dcsimg
Results 1 to 4 of 4

Thread: Can't Declare Variables

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Angry Can't Declare Variables

    It's been awhile since I was using VB.Net, but I'm having a problem with the most basic of Basic programming... I can't declare variables! Even using extremely simple code:
    Code:
    Dim MyInt As Integer = 17
    MyInt = MyInt + 3
    the variable MyInt has a squiggle under it with the error: Declaration Expected. That's what I thought the first line did. Not sure why I'm having so much trouble with this...

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,569

    Re: Can't Declare Variables

    Your syntax is correct, although the 2nd line could be shorter to:
    Code:
    MyInt += 3
    My question would be where are you placing the code?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: Can't Declare Variables

    Thanks for your question.... I figured out my problem. I had just put it right under the Class signature instead of creating a Method for it. Told ya I was out of VB for awhile!

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,902

    Re: Can't Declare Variables

    Yeah, there's nothing wrong with that code as written. Of course, if it is outside of a method, then it would be an issue. Since that seems unlikely, I would guess that this is a misdirection and that the actual problem lies somewhere before the posted code.

    EDIT: HA! I didn't write much, but I DID write late!
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width