Results 1 to 11 of 11

Thread: Little Problem?

  1. #1

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362

    Question Little Problem?

    I'm using this code to try to kame 2 different controls but when I try to run my app I get a compile error: agrument not optional.

    Why?

    VB Code:
    1. ListFiles (CheckPath(App.Path) & "Favorites\")
    2. ListhFiles = (CheckPath(App.Path) & "history\")
    3.  
    4.  
    5. Public Sub ListFiles(sFolder As String)
    6. Dim i As Integer
    7. Dim sFilename As String
    8. Dim iCount As Integer
    9. Dim FSO As New FileSystemObject
    10.  
    11. iCount = 1
    12.  
    13. ' Remove flags for files you don't want to include
    14.  
    15. sFilename = Dir(FSO.BuildPath(sFolder, "*.wwu"), vbNormal Or vbHidden Or vbSystem Or vbReadOnly)
    16. sFilename = Left(sFilename, InStrRev(sFilename, ".") - 1)
    17. On Error Resume Next
    18. mnuViewFiles(0).Caption = sFilename
    19. mnuViewFiles(0).Visible = True
    20.  
    21. Do
    22.   sFilename = Dir()  ' Get next filename
    23.   If Trim$(sFilename) = vbNullString Then Exit Sub
    24.   Load mnuViewFiles(iCount)
    25.   sFilename = Left(sFilename, InStrRev(sFilename, ".") - 1)
    26.   mnuViewFiles(iCount).Caption = sFilename
    27.   mnuViewFiles(iCount).Visible = True
    28.   iCount = iCount + 1
    29. Loop
    30.  
    31. End Sub
    32. Private Function NormalizePath(sFolder As String, hfolder As String) As String
    33.  
    34. sFolder = Trim$(sFolder)
    35. hfolder = Trim$(hfolder)
    36.  
    37. If Right$(sFolder, 1) <> "\" Then sFolder = sFolder & "\"
    38. NormalizePath = sFolder
    39. If Right$(hfolder, 1) <> "\" Then sFolder = hfolder & "\"
    40. NormalizePath = hfolder
    41.  
    42. End Function
    43.  
    44. Public Sub ListhFiles(hfolder As String)
    45. Dim i As Integer
    46. Dim hFilename As String
    47. Dim iCount As Integer
    48. Dim FSO As New FileSystemObject
    49.  
    50. iCount = 1
    51.  
    52. ' Remove flags for files you don't want to include
    53.  
    54. hFilename = Dir(FSO.BuildPath(hfolder, "*.wwu"), vbNormal Or vbHidden Or vbSystem Or vbReadOnly)
    55. hFilename = Left(hFilename, InStrRev(hFilename, ".") - 1)
    56. On Error Resume Next
    57. Toolbar1.Buttons(1).ButtonMenus(0).Text = hFilename
    58. Toolbar1.Buttons(1).ButtonMenus(0).Visible = True
    59.  
    60. Do
    61.   hFilename = Dir()  ' Get next filename
    62.   If Trim$(hFilename) = vbNullString Then Exit Sub
    63.   Load Toolbar1.Buttons(1).ButtonMenus(iCount)
    64.   hFilename = Left(hFilename, InStrRev(hFilename, ".") - 1)
    65.   Toolbar1.Buttons(1).ButtonMenus(iCount).Text = hFilename
    66.   Toolbar1.Buttons(1).ButtonMenus(iCount).Visible = True
    67.   iCount = iCount + 1
    68. Loop
    69.  
    70. End Sub

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    I didnt read your code, but it means you're calling a function and you are not passing one or more arguments. Like a function might need you to call it like FUNCTION (ARG) and you are not passsing ARG, like you're just calling FUNCTION()

    Umm, maybe you're not getting the returned variable

    change the first line to this, see if this helps
    call ListFiles (CheckPath(App.Path) & "Favorites\")
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I'd be willing to bet your problem is here
    VB Code:
    1. If Right$(sFolder, 1) <> "\" Then sFolder = sFolder & "\"
    2. NormalizePath = sFolder
    3. If Right$(hfolder, 1) <> "\" Then sFolder = hfolder & "\"
    4. NormalizePath = hfolder
    You can't just say NormalizePath. This function is expecting to be passed two paraemeters (sFolder As String, hfolder As String) and you aren't passing it any parameters.

  4. #4

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    the error is on ListhFiles = (CheckPath(App.Path) & "history\")

    would it still have something to do with th normalizepath?

  5. #5

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    Could you please suggest a way to fix my code?

  6. #6

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    I will keep this post on top until I get an answer!

  7. #7
    Addicted Member mepaco's Avatar
    Join Date
    Mar 2002
    Location
    Jackson, MS
    Posts
    185
    What or where is the CheckPath() function?

  8. #8

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    the checkpath() function is to locate the app's path nomatter where the app's dir is located.

    and the checkpath() function is located at the near top of the code page just after the declarations and just before the form load Sub.

    Why?

  9. #9
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    ListFiles (CheckPath(App.Path) & "Favorites\")
    ListhFiles = (CheckPath(App.Path) & "history\")
    Are these calls inside a sub?

  10. #10
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Why are you passing two folders to NormalizePath? I think it should be like this:
    VB Code:
    1. Function NormalizePath(ByRef sFolder As String)
    2.  
    3. sFolder = Trim$(sFolder)
    4.  
    5. If Right$(sFolder, 1) <> "\" Then sFolder = sFolder & "\"
    6.  
    7. End Function

  11. #11

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    yup, the form_load sub, but never mind I fixed the problem I just removed the "=" and every thing worked

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