Results 1 to 9 of 9

Thread: error:variable not defined?????

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    error:variable not defined?????

    Code:
    Private Sub mnuFileMRU_Click(index As Integer)
    
        strFileNewName1 = (Left(mnuFileMRU(index).Caption, InStr(1, mnuFileMRU(index).Caption, "\DAF")) & "Map\")
        strFileNewName2 = (Mid(mnuFileMRU(index).Caption, InStr(1, mnuFileMRU(index).Caption, "MY"), 8) & ".bmp")
        strFileNewName3 = strFileNewName1 & strFileNewName2
        'MsgBox " " & strFileNewName3
        
        Picture1.Picture = LoadPicture(strFileNewName3)
        
       Call ConvertMRU
       End Sub
    
    Private Sub ConvertMRU()
    
        Dim intFF As Integer
        Dim strReaded() As String
        Dim index as integer    
           intFF = FreeFile
           
                Open mnuFileMRU(index).Caption For Input As #intFF
                    strReaded = Split(Input(LOF(intFF), #intFF), vbLf)
               Close #intFF
             
             strFileNewName4 = (Left(mnuFileMRU(index).Caption, InStr(1, mnuFileMRU(index).Caption, "\DAF")) & "Setting\Daf.txt")
             'MsgBox "" & strFileNewName4
             
            intFF = FreeFile
                Open strFileNewName4 For Output As #intFF
                    Print #intFF, Join(strReaded, vbCrLf);
                Close #intFF
    
    End Sub
    above is part of my code. it came out an error "variable not defined" and point to index(the red color). how to improve the code above?
    Last edited by junlo; Mar 13th, 2007 at 12:27 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: error:variable not defined?????

    If your menu items are not in an array, then there will be no index property, and the result will be an error.

    If you are using my example to create an MRU, have you created your menu array that will be populated with the most recently used items?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: error:variable not defined?????

    Quote Originally Posted by Hack
    If your menu items are not in an array, then there will be no index property, and the result will be an error.

    If you are using my example to create an MRU, have you created your menu array that will be populated with the most recently used items?
    yes, i used your example to edit. when i add the code ( the blue color in #1).the error became as "control array element '0" doesn't exist"

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: error:variable not defined?????

    You need to make a menu array in design time.

    Open the project in my attachment and look at the menu I created on the form. Under CleanMRU you will see a bunch of menu items with no caption, and a sequential index number.

    That index number is what the code is looking for, and what you do not have.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: error:variable not defined?????

    Quote Originally Posted by Hack
    You need to make a menu array in design time.

    Open the project in my attachment and look at the menu I created on the form. Under CleanMRU you will see a bunch of menu items with no caption, and a sequential index number.

    That index number is what the code is looking for, and what you do not have.
    i had a sequential index number from 1 to 4.

  6. #6
    Junior Member
    Join Date
    Mar 2007
    Posts
    21

    Re: error:variable not defined?????

    hmm
    then try out a loop

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: error:variable not defined?????

    Quote Originally Posted by VaRz
    hmm
    then try out a loop
    Code:
    Private Sub ConvertMRU()
        Dim intFF As Integer
        Dim strReaded() As String
        Dim i As Integer
        
             intFF = FreeFile
        For i = 1 To 4
                Open mnuFileMRU(i).Caption For Input As #intFF
                    strReaded = Split(Input(LOF(intFF), #intFF), vbLf)
               Close #intFF
             MsgBox "" & mnuFileMRU(i)         strFileNewName4 = (Left(mnuFileMRU(i).Caption, InStr(1, mnuFileMRU(i).Caption, "\DAF")) & "Setting\Daf.txt")
             
            intFF = FreeFile
                Open strFileNewName4 For Output As #intFF
                    Print #intFF, Join(strReaded, vbCrLf);
                Close #intFF
       Next
    
    End Sub
    i try the loop. but by using the message box ( the red line). it came out the message "true" not the directory of file. why?????

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: error:variable not defined?????

    Attach your form so I can take a look at it.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: error:variable not defined?????

    i have attact the code. please open the file MY3C0540.daf in forder DAF first. then close it and try again with MRU.
    Attached Files Attached Files

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