[Resolved] compile error: variable not defined-VBForums
Results 1 to 13 of 13

Thread: [Resolved] compile error: variable not defined

  1. #1

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Resolved [Resolved] compile error: variable not defined

    I have a problem with the code. When I call the msgbox to quit the program and on the msgbox appeared to come on my screen, when I clicked cmdcancel I have received error: Compile error: variable not defined


    Code:
    Private Sub cmdCancel_Click()
        Unload Quit
    End Sub


    I don't know what's wrong, I bet that Unload Quit are incorrect. What other way that I can tell the form to cancel one dialog because I am running two dialogs??



    I'm sorry to make another thread but have received an error which it didn't means that I am spamming the forum. So I am here asking for advice which I would like to get resolve it asap!!!!!



    Thanks,
    Mark
    Last edited by Mark103; Nov 2nd, 2007 at 07:15 AM.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,097

    Re: compile error: variable not defined

    Quote Originally Posted by Mark103
    Code:
    Private Sub cmdCancel_Click()
        Unload Quit
    End Sub
    What is Quit? You use Unload to unload an object, i.e., Unload Me

  3. #3

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: compile error: variable not defined

    Quote Originally Posted by LaVolpe
    What is Quit? You use Unload to unload an object, i.e., Unload Me


    Thanks, but received the same error


    Code:
    Public Property Get QuitMe() As VbMsgBoxResult
        QuitMe = miQuitMe
    End Property


    what's wrong??



    Mark

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,097

    Re: compile error: variable not defined

    No, you won't receive an error on Unload Me. You are recieving an error in a different routine. Again. what is miQuiteMe? Are you using Option Explicit at the top of your form? You should be. And then run your project by pressing Ctrl+F5 to find all your errors, one at a time.

    Edited: typo, should have typed Ctrl+F5 - fixed.
    Last edited by LaVolpe; Nov 1st, 2007 at 02:55 PM.

  5. #5

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: compile error: variable not defined

    Quote Originally Posted by LaVolpe
    No, you won't receive an error on Unload Me. You are recieving an error in a different routine. Again. what is miQuiteMe? Are you using Option Explicit at the top of your form? You should be. And then run your project by pressing Ctrl+5 to find all your errors, one at a time.

    Yes I am using Option Explicit at the top of my form. I don't know what's wrong with the code (QuitMe = miQuitMe)that i have received the same error when I have refixed Unload Me??


    Thanks,
    Mark

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,097

    Re: compile error: variable not defined

    What is miQuitMe? It must not be a numeric variable or it isn't declared anywhere? This is your code, you should know what that variable is or is suppose to be.

  7. #7

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: compile error: variable not defined

    Quote Originally Posted by LaVolpe
    What is miQuitMe? It must not be a numeric variable or it isn't declared anywhere? This is your code, you should know what that variable is or is suppose to be.

    It tell the form to quit the program. Why do the error come with the same reasons that I have received?? How can we refix it??




    Thanks,
    Mark

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,097

    Re: compile error: variable not defined

    Declare it. That's why you are getting the error, nowhere in your code do you have a statement like Dim miQuitMe As ....

    Declaring it will fix that one error, but unless you actually assign it a value somewhere in your code, its value will always be zero, null.

    Again, this is your code, you should know what you want that variable to be declared as and what its value should be. We won't know that.

  9. #9

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: compile error: variable not defined

    Quote Originally Posted by LaVolpe
    Declare it. That's why you are getting the error, nowhere in your code do you have a statement like Dim miQuitMe As ....

    Declaring it will fix that one error, but unless you actually assign it a value somewhere in your code, its value will always be zero, null.

    Again, this is your code, you should know what you want that variable to be declared as and what its value should be. We won't know that.

    How we can fix the error then?? I have no idea what's the error is and I have no virtually idea how I could fix it. Maybe just use QuitMe which will fix my problem??



    Thanks,
    Mark

  10. #10
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: compile error: variable not defined

    I read this thread at least 15 times and I still don't understand the problem... something with a messagebox and unloading a form.

    Do you want to show a messagebox to ask the user if a form should be unloaded?

    Code:
    Private Sub Command1_Click()
        If MsgBox("Do you want to unload this form?", vbQuestion + vbYesNo, "Confirmation") = vbYes Then
            Unload Me
        End If
    End Sub

  11. #11
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: compile error: variable not defined

    Use Option Explicit to force you to declare all your variable so that you wont have this problem.

  12. #12
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: compile error: variable not defined

    Quote Originally Posted by LaVolpe
    You use Unload to unload an object, i.e., Unload Me
    This is all you need.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  13. #13

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: compile error: variable not defined

    Quote Originally Posted by randem
    Use Option Explicit to force you to declare all your variable so that you wont have this problem.


    I have done this. Problem resolved!



    Thanks,
    Mark

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