6 Replies - 2654 Views - Last Post: 20 March 2011 - 11:41 PM Rate Topic: -----

#1 xkaijinx  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 09-March 11

Unused Local Variable - Error

Posted 20 March 2011 - 06:17 PM

Hi. I wrote a small program, and I am getting the warning 'Unused local variable' It is saying that 'NumberGuess' is that variable that is not being used.

My problem is that I used this variable. I checked the spelling of the variable as well, however I am still getting this error. Is there an option I need to set to correct this? I must be doing something wrong.

 Module GuessingGame

    Sub Main()
        Dim RandomNumber As Integer
        Dim NumberGuess As Integer
        Dim GuessCounter As Integer
        GuessCounter = 1
        Randomize()
        RandomNumber = Int(Rnd() * 20) + 1
        Do
        Loop
        NumberGuess = CInt(InputBox("Please type in a guess between 1 and 20"))
        If NumberGuess <> RandomNumber Then

        End If
        GuessCounter = GuessCounter + 1
        If NumberGuess > RandomNumber Then
            MsgBox("Your guess is too high.")
        Else
            MsgBox("Your guess is too low.")
        End If
        Do
        Loop Until NumberGuess = RandomNumber
        MsgBox("Great job!  The number " & NumberGuess & "was correct!")
    End Sub

End Module


Is This A Good Question/Topic? 0
  • +

Replies To: Unused Local Variable - Error

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Unused Local Variable - Error

Posted 20 March 2011 - 06:53 PM

The compiler is just saying you have not used it, so you can get rid of it if you don't need it.

This post has been edited by hawkvalley1: 20 March 2011 - 07:29 PM

Was This Post Helpful? 0
  • +
  • -

#3 xkaijinx  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 09-March 11

Re: Unused Local Variable - Error

Posted 20 March 2011 - 07:40 PM

View Posthawkvalley1, on 20 March 2011 - 06:53 PM, said:

The compiler is just saying you have not used it, so you can get rid of it if you don't need it.



I went ahead and deleted that portion at the beginning of the program and I received a bunch of new error messages stating..

'NumberGuess' is not declared. It may be inaccessible due to its protection level.'

This is very odd, because I am using it throughout the script.
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Unused Local Variable - Error

Posted 20 March 2011 - 08:04 PM

What I meant was, that what it should mean when you see that. I'll have too check that out, but I don't remember it doing that. I typically declare mine with value even if setting it too nothing.
Was This Post Helpful? 0
  • +
  • -

#5 LoveIsNull  Icon User is offline

  • Recovering D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 646
  • Joined: 10-March 09

Re: Unused Local Variable - Error

Posted 20 March 2011 - 10:30 PM

Do
Loop


Code below those lines (10-11) will never run anyways; empty infinite loop you have....two of them actually.

This post has been edited by LoveIsNull: 20 March 2011 - 10:33 PM

Was This Post Helpful? 1
  • +
  • -

#6 Elda  Icon User is offline

  • D.I.C Regular

Reputation: 31
  • View blog
  • Posts: 314
  • Joined: 30-December 10

Re: Unused Local Variable - Error

Posted 20 March 2011 - 11:36 PM

Why don't try to have this
 Dim NumberGuess As Integer = txtguess.text
and remove
NumberGuess = CInt(InputBox("Please type in a guess between 1 and 20"))
and validate txtguess.text to put integer only.

Hope that helps..
Was This Post Helpful? 0
  • +
  • -

#7 Elda  Icon User is offline

  • D.I.C Regular

Reputation: 31
  • View blog
  • Posts: 314
  • Joined: 30-December 10

Re: Unused Local Variable - Error

Posted 20 March 2011 - 11:41 PM

or

Dim NumberGuess As Integer = val(txtguess.text)

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1