none
VBA.COMPILE.ERROR...Variable not defined, wrong marked RRS feed

  • Question

  • Hi,

    very old code with many-many colons....

    ' COMPILE:  Variable not defined......>vbCrLf<.................FALSE /Compile Error !!!
    ' COMPILE:  Variable not defined......>gkxPAC_NAME_SHRT<.......TRUE

    Option Compare Database
    Option Explicit
    '--------------------------------
    'Private Const gkxPAC_NAME_SHRT = ""
    'Private Const gkxPACAppMainVersion = ""
    'Private Function APP_QUIT(Optional cMsg$ = "")
    'On Error GoTo xPAC_CHYBA
    'Dim lc__proc_meno$, lc__proc_ErrUSR$, ln__proc_err&
    'lc__proc_meno$ = "APP_QUIT"
    'If Len(cMsg) > 0 Then MsgBox cMsg & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbExclamation + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno
    'LBL_EXIT:
    'Application.Quit
    'xPAC_KONIEC:
    'Exit Function
    'xPAC_CHYBA:
    'MsgBox "Err: " & Err.Number & "," & Err.Description & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbCritical + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno & ", E" & "rr" & "or !"
    'Resume LBL_EXIT
    'End Function
    '--------------------------------
    ' COMPILE:  Variable not defined......>vbCrLf<.................FALSE /Compile Error !!!
    ' COMPILE:  Variable not defined......>gkxPAC_NAME_SHRT<.......TRUE
    Private Function APP_QUIT(Optional cMsg$ = ""): On Error GoTo xPAC_CHYBA: Dim lc__proc_meno$, lc__proc_ErrUSR$, ln__proc_err&: lc__proc_meno$ = "APP_QUIT": If Len(cMsg) > 0 Then MsgBox cMsg & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbExclamation + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno
    LBL_EXIT: Application.Quit
    xPAC_KONIEC: Exit Function
    xPAC_CHYBA: MsgBox "Err: " & Err.Number & "," & Err.Description & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbCritical + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno & ", E" & "rr" & "or !": Resume LBL_EXIT
    End Function


    dBase,FoxPro,MS Access 2003,(2010=Not rec.),Office 2010+ACC.2013 ,Symbian C++, AC.2013.SystemResource.GetCurrentFreeSize=?

    Tuesday, August 18, 2015 9:29 AM

Answers

  • Hi PACALA_BA,

    >> the main  point is NOT „Variable not defined“

    Did you mean that you could make your code work, and you are wondering why the Selected undefined variable is wrong if you did not define the gkxPAC_NAME_SHRT?

    I have made a test with your code, and I could reproduce your issue. If I test with the code below, the error message with the selected is correct.

    Option Compare Database
    Option Explicit
    '--------------------------------
    'Private Const gkxPAC_NAME_SHRT = ""
    'Private Const gkxPACAppMainVersion = ""
    'Private Function APP_QUIT(Optional cMsg$ = "")
    'On Error GoTo xPAC_CHYBA
    'Dim lc__proc_meno$, lc__proc_ErrUSR$, ln__proc_err&
    'lc__proc_meno$ = "APP_QUIT"
    'If Len(cMsg) > 0 Then MsgBox cMsg & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbExclamation + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno
    'LBL_EXIT:
    'Application.Quit
    'xPAC_KONIEC:
    'Exit Function
    'xPAC_CHYBA:
    'MsgBox "Err: " & Err.Number & "," & Err.Description & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbCritical + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno & ", E" & "rr" & "or !"
    'Resume LBL_EXIT
    'End Function
    '--------------------------------
    ' COMPILE:  Variable not defined......>vbCrLf<.................FALSE /Compile Error !!!
    ' COMPILE:  Variable not defined......>gkxPAC_NAME_SHRT<.......TRUE
    'Private Function APP_QUIT(Optional cMsg$ = ""): On Error GoTo xPAC_CHYBA: Dim lc__proc_meno$, lc__proc_ErrUSR$, ln__proc_err&: lc__proc_meno$ = "APP_QUIT": If Len(cMsg) > 0 Then MsgBox cMsg & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbExclamation + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno
    'LBL_EXIT: Application.Quit
    'xPAC_KONIEC: Exit Function
    'xPAC_CHYBA: MsgBox "Err: " & Err.Number & "," & Err.Description & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbCritical + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno & ", E" & "rr" & "or !": Resume LBL_EXIT
    'End Function
    Private Function test()
        MsgBox "Hello" & vbCrLf & undefinedVariable
    End Function

    To be honesty, I do not know why this happened, I used the Editor for developer, but I did not know the details achievement of it.

    I suggest you define all the variable you will use in the code, write the correct code.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by PACALA_BA Tuesday, August 25, 2015 1:10 PM
    Monday, August 24, 2015 3:34 AM

All replies

  • I suggest you check your references.

    This error can show when a required reference is missing...


    Brian, ProcessIT- Hawke`s Bay, New Zealand



    • Edited by ProcessIT Wednesday, August 19, 2015 4:27 AM spelling
    Wednesday, August 19, 2015 4:26 AM
  • Hi PACALA_BA,

    Based on your code, you commend out many line codes, and you did not define the “gkxPAC_NAME_SHRT”, you will get the Variable not defined when you compile. I suggest you try the code in a new module:

    Option Compare Database
    Private Const gkxPAC_NAME_SHRT = ""
    Private Const gkxPACAppMainVersion = ""
    Private Function APP_QUIT(Optional cMsg$ = ""): On Error GoTo xPAC_CHYBA: Dim lc__proc_meno$, lc__proc_ErrUSR$, ln__proc_err&: lc__proc_meno$ = "APP_QUIT": If Len(cMsg) > 0 Then MsgBox cMsg & vbCrLf & String(50, "-") & vbCrLf & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbExclamation + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno
    LBL_EXIT: Application.Quit
    xPAC_KONIEC: Exit Function
    xPAC_CHYBA: MsgBox "Err: " & Err.Number & "," & Err.Description & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbCritical + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno & ", E" & "rr" & "or !": Resume LBL_EXIT
    'End If
    End Function

    In addition, with your issue, it would be helpful if you could tell us how and what issues you have instead of just posting code and error, and just post the related code. And community members could know what your issue, and could focus on this issue.

    Thanks for your understanding.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, August 19, 2015 5:27 AM
  • Hi

    “gkxPAC_NAME_SHRT”, you will get the Variable not defined when you compile....NOT 100% TRUE

    COMPILE:  Variable not defined......>vbCrLf<.................FALSE /Compile Error !!!
    ' COMPILE:  Variable not defined......>gkxPAC_NAME_SHRT<.......TRUE

    After Compile, l get the Variable not defined, but in in Selection is >vbCrLf<......................+++WHY+++ ?

    after removing all the colons

    After Compile, l get the Variable not defined, but in in Selection is >gkxPAC_NAME_SHRT<..........OK


    dBase,FoxPro,MS Access 2003,(2010=Not rec.),Office 2010+ACC.2013 ,Symbian C++, AC.2013.SystemResource.GetCurrentFreeSize=?

    Wednesday, August 19, 2015 7:44 AM
  • Hi PACALA_BA,

    You use the Option Explicit statement to protect your modules from having undeclared variables and to eliminate the possibility of inadvertently creating new variables when typographical errors occur. For more information about Variable not defined, you could refer the link below:
    #Variable not defined
    https://msdn.microsoft.com/en-us/library/office/gg264325.aspx

    Have you tested my code?

    >> after removing all the colons

    What is the code now you have? Will your project work correctly?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, August 20, 2015 2:06 AM
  • Hi

    I am sorry, the main point is NOTVariable not defined“

    After Compiler says Variable not defined,

    ·        Current:
    the Selected  undefined Variable is >vbCrLf<...wrong marked/selected
    • Required:
    the Selected  undefined Variable SHOULD BE > gkxPAC_NAME_SHRT<
    try the code...

    I does NOT have Access to ONEDRIVE, at this place, i can not upload pictures

    (Outlook Editor used for this message,  NOT Forum Editor.... )


    dBase,FoxPro,MS Access 2003,(2010=Not rec.),Office 2010+ACC.2013 ,Symbian C++, AC.2013.SystemResource.GetCurrentFreeSize=?

    Friday, August 21, 2015 7:45 AM
  • Hi PACALA_BA,

    >> the main  point is NOT „Variable not defined“

    Did you mean that you could make your code work, and you are wondering why the Selected undefined variable is wrong if you did not define the gkxPAC_NAME_SHRT?

    I have made a test with your code, and I could reproduce your issue. If I test with the code below, the error message with the selected is correct.

    Option Compare Database
    Option Explicit
    '--------------------------------
    'Private Const gkxPAC_NAME_SHRT = ""
    'Private Const gkxPACAppMainVersion = ""
    'Private Function APP_QUIT(Optional cMsg$ = "")
    'On Error GoTo xPAC_CHYBA
    'Dim lc__proc_meno$, lc__proc_ErrUSR$, ln__proc_err&
    'lc__proc_meno$ = "APP_QUIT"
    'If Len(cMsg) > 0 Then MsgBox cMsg & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbExclamation + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno
    'LBL_EXIT:
    'Application.Quit
    'xPAC_KONIEC:
    'Exit Function
    'xPAC_CHYBA:
    'MsgBox "Err: " & Err.Number & "," & Err.Description & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbCritical + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno & ", E" & "rr" & "or !"
    'Resume LBL_EXIT
    'End Function
    '--------------------------------
    ' COMPILE:  Variable not defined......>vbCrLf<.................FALSE /Compile Error !!!
    ' COMPILE:  Variable not defined......>gkxPAC_NAME_SHRT<.......TRUE
    'Private Function APP_QUIT(Optional cMsg$ = ""): On Error GoTo xPAC_CHYBA: Dim lc__proc_meno$, lc__proc_ErrUSR$, ln__proc_err&: lc__proc_meno$ = "APP_QUIT": If Len(cMsg) > 0 Then MsgBox cMsg & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbExclamation + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno
    'LBL_EXIT: Application.Quit
    'xPAC_KONIEC: Exit Function
    'xPAC_CHYBA: MsgBox "Err: " & Err.Number & "," & Err.Description & vbCrLf & String(50, "-") & vbCrLf & gkxPAC_NAME_SHRT & " " & gkxPACAppMainVersion, vbCritical + vbSystemModal, gkxPAC_NAME_SHRT & ", " & lc__proc_meno & ", E" & "rr" & "or !": Resume LBL_EXIT
    'End Function
    Private Function test()
        MsgBox "Hello" & vbCrLf & undefinedVariable
    End Function

    To be honesty, I do not know why this happened, I used the Editor for developer, but I did not know the details achievement of it.

    I suggest you define all the variable you will use in the code, write the correct code.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by PACALA_BA Tuesday, August 25, 2015 1:10 PM
    Monday, August 24, 2015 3:34 AM