Results 1 to 11 of 11

Thread: [RESOLVED] how to put code in module?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Resolved [RESOLVED] how to put code in module?

    Code:
    Private Sub mnuOpen_Click()
    
        On Error GoTo errTrap
    
            mnuCoordinateList(1).Checked = True
            mnuCoordinateList(2).Checked = False
    
            With CommonDialog1
                .CancelError = True
                .Filter = "dKart ACSII files (*.daf)|*.daf|"
                .ShowOpen
            End With
           
        
        strFileNewName1 = (Left(CommonDialog1.FileName, InStr(1, CommonDialog1.FileName, "\DAF")) & "Map\")
        strFileNewName2 = (Mid(CommonDialog1.FileName, InStr(1, CommonDialog1.FileName, "MY"), 8) & ".bmp")
        strFileNewName3 = strFileNewName1 & strFileNewName2
        strFileNewName4 = (Left(CommonDialog1.FileName, InStr(1, CommonDialog1.FileName, "\DAF")) & "Setting\Daf.txt")
        strFileNewName5 = (Left(CommonDialog1.FileName, InStr(1, CommonDialog1.FileName, "\DAF")) & "Setting\Output.txt")
        Picture1.Picture = LoadPicture(strFileNewName3)
       
       Call Convert
       Call ENCExtract
       
       If mnuCoordinateList(1).Checked = True Then
            Call DecimalDegrees
        ElseIf mnuCoordinateList(2).Checked = True Then
            Call DDtoDMS
        End If
      
        blnOkToMove = True
        
        'add the file just opened to our MRU list
        Call WriteMRUList(CommonDialog1.FileName)
        
     Exit Sub
     
    errTrap:
    'cancel was hit, so dont do anything
    End Sub
    Code:
    Private Sub DDtoDMS()
    Dim sLines() As String
    Dim Degrees1 As Variant, Degrees2 As Variant, Degrees3 As Variant, Degrees4 As Variant
    Dim Minutes1 As Variant, Minutes2 As Variant, Minutes3 As Variant, Minutes4 As Variant
    Dim seconds1 As Variant, seconds2 As Variant, Seconds3 As Variant, Seconds4 As Variant
    Dim A As Variant
    Dim B As Variant
    On Error GoTo errTrap:
    strFileNewName4 = (Left(CommonDialog1.FileName, InStr(1, CommonDialog1.FileName, "\DAF")) & "Setting\Daf.txt")
        Open strFileNewName4 For Input As #1
            sLines = Split(Input(LOF(1), #1), vbCrLf)
        Close #1
     
        Degrees1 = Int(sLines(1))
        Minutes1 = (sLines(1) - Degrees1) * 60
        seconds1 = Format(((Minutes1 - Int(Minutes1)) * 60), "0")
        Label1.Caption = " " & Degrees1 & "° " & Int(Minutes1) & "' " _
                & seconds1 + Chr(34)
    
        Degrees2 = Int(sLines(2))
        Minutes2 = (sLines(2) - Degrees2) * 60
        seconds2 = Format(((Minutes2 - Int(Minutes2)) * 60), "0")
        Label2.Caption = " " & Degrees2 & "° " & Int(Minutes2) & "' " _
                & seconds2 + Chr(34)
                
        Degrees3 = Int(sLines(3))
        Minutes3 = (sLines(3) - Degrees3) * 60
        Seconds3 = Format(((Minutes3 - Int(Minutes3)) * 60), "0")
        Label3.Caption = " " & Degrees3 & "° " & Int(Minutes3) & "' " _
                & Seconds3 + Chr(34)
    
        Degrees4 = Int(sLines(4))
        Minutes4 = (sLines(4) - Degrees4) * 60
        Seconds4 = Format(((Minutes4 - Int(Minutes4)) * 60), "0")
        Label4.Caption = " " & Degrees4 & "° " & Int(Minutes4) & "' " _
                & Seconds4 + Chr(34)
    errTrap:
                   
    End Sub
    when i put mnuOpen and DDtoDMS at the same form, it can work. But , when i moved the DDtoDMs to a module.it came out an error "sub or function not defined"and highlight the code call DDtoDMS.how to improve my code if i want DDtoDMS in module.

  2. #2
    New Member simonle's Avatar
    Join Date
    Apr 2007
    Posts
    3

    Re: how to put code in module?

    in your module replace this:

    Code:
    Private Sub DDtoDMS()
    with this:

    Code:
    Public Sub DDtoDMS()

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: how to put code in module?

    Quote Originally Posted by simonle
    in your module replace this:

    Code:
    Private Sub DDtoDMS()
    with this:

    Code:
    Public Sub DDtoDMS()
    i have change it, althrough this time it don't have error message but i think it doesn't run on this module, because if this module is run,my value in label1,2,3 and 4 will change to Degree.but,it still same without changing.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: how to put code in module?

    If you have moved DDtoDMS to a code module then everything in it that refers to controls on the form needs to be changed to refer to the form. For example

    Label1.Caption

    needs to be changed to

    YourFormName.Label1.caption

    If you compile you'll find all the things that need to change.

  5. #5
    Fanatic Member
    Join Date
    Jun 2001
    Location
    Oregon
    Posts
    643

    Re: how to put code in module?

    put a Break on the first line in your DDtoDMS sub and run your program, do what your supposed to do to have it run that sub. If your program never breaks then you know its not running the code, and you can step through earlier portions of your code to find out why.

    Also once your in, use F8 to keep going through, maybe its running through DDtoDMS but not getting the values properly to change your labels.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: how to put code in module?

    i have change the all label.caption to form.label.caption.afterthat, i add a message box in module,the message box is came out. so, this module is run but my value in label1,2,3,4 still not changing.
    Last edited by junlo; Apr 4th, 2007 at 02:53 PM.

  7. #7
    Fanatic Member
    Join Date
    Jun 2001
    Location
    Oregon
    Posts
    643

    Re: how to put code in module?

    Quote Originally Posted by junlo
    i have change the all label.caption to form.label.caption.afterthat, i add a message box in module.but, the message box not pop up.
    Dont use a message box, use a Break point.. Just click the first executable line in your sub and push F9. The line will turn red and you will have a red dot on the left side of the screen.

    Its important to do the very first possible line only becuase if the code sends you into the sub, an error or something else could pull it out of the code pretty quick.

    If your code doesnt stop on that first line, usually you put the break on your "Private Sub Blah Blah" line... So if it doesnt stop on that line, it never went into it.. So go a few steps back before its supposed to run that code, and stick in another break point.. Keep going backwards until you find where its skipping over what you need.

    Not sure how big your project is, but it might be easier to start your program by hitting F8 and step through the entire thing. But if you have alot of lines of code, it may take awhile to get to where you need, thats why you use breakpoints if you have alot of code

  8. #8
    Fanatic Member
    Join Date
    Jun 2001
    Location
    Oregon
    Posts
    643

    Re: how to put code in module?

    Quote Originally Posted by junlo
    i have change the all label.caption to form.label.caption.afterthat, i add a message box in module,the message box is came out. so, this module is run but my value in label1,2,3,4 still not changing.
    Ok, break on your first label and hover your mouse over what the label is supposed to be, for example:

    Code:
    Label1.Caption = strLine
    Hover your mouse above 'strLine', dont click it.. A tooltip should pop up and tell you what strLine is, if it pops up an empty box, or shows 0 or something, then you know its the wrong value, and you can trace that back to make sure.

    What Martin said is correct about the labels, but it goes for every control your accessing in your module. If you have code in a module that refer's to a control on a form, you have to do FormName.ControlName or else its not going to find it..

  9. #9
    Fanatic Member
    Join Date
    Jun 2001
    Location
    Oregon
    Posts
    643

    Re: how to put code in module?

    I think this might be your current problem:

    Code:
    strFileNewName4 = (Left(CommonDialog1.FileName, InStr(1, CommonDialog1.FileName, "\DAF")) & "Setting\Daf.txt")
    You need to change both of the 'CommonDialog1.FileName' to add your form name at the front (i never looked at your code until now hehe)

  10. #10

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: how to put code in module?

    i have found the error in line

    Code:
    strFileNewName4 = (Left(CommonDialog1.FileName, InStr(1, CommonDialog1.FileName, "\DAF")) & "Setting\Daf.txt")
    it came out an error "object require", but i don't know how to correct it.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: how to put code in module?

    Quote Originally Posted by PMad
    I think this might be your current problem:

    Code:
    strFileNewName4 = (Left(CommonDialog1.FileName, InStr(1, CommonDialog1.FileName, "\DAF")) & "Setting\Daf.txt")
    You need to change both of the 'CommonDialog1.FileName' to add your form name at the front (i never looked at your code until now hehe)
    thank you very much,my problem is solve.

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