CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2014
    Posts
    1

    Help with code compile error message.

    Hi all,

    I am very new to programming and VBA so absolutely any help is greatly appreciated. I am trying to fix this code and I cannot find where the error is. Whenever I try to run it, I get a message saying "Compile error: Variable not defined"

    Option Explicit
    Sub ChipmunkToss()

    Dim Dale As Single, Theo as Single
    Dale = 11.1
    Theo = 31.3
    MsgBox Dale1 + Theo1
    End Sub


    Thank you in advance for any help!

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Help with code compile error message.

    Single means WHOLE # ONLY. No decimal points. Try 11 + 31 instead
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Help with code compile error message.

    Quote Originally Posted by dglienna View Post
    Single means WHOLE # ONLY. No decimal points. Try 11 + 31 instead
    What?

    Single means Single Precision and has decimals

    The problem here is that @AndrewDz is declaring Dale and Theo but he is using Dale1 and Theo1 in the MsgBox
    Last edited by jggtz; January 29th, 2014 at 01:43 PM.
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Help with code compile error message.

    oops. was thinking INT for Integer
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Help with code compile error message.

    Your problem is highlighted in Red
    Code:
    Option Explicit
    Sub ChipmunkToss()
    
    Dim Dale As Single, Theo as Single
    Dale = 11.1
    Theo = 31.3
    MsgBox Dale1 + Theo1
    End Sub
    Dale1 and Theo1 do not exist

    Edit: I see that jggtz pointed this out above also
    Always use [code][/code] tags when posting code.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured