creating a browse button with VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NasirMunir
    New Member
    • Jun 2007
    • 27

    creating a browse button with VB6

    I need some help for creating a button that can allow the users to browse to a location and upload a file. I am new to VB, and any help would be greatly appreciated.
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by NasirMunir
    I need some help for creating a button that can allow the users to browse to a location and upload a file. I am new to VB, and any help would be greatly appreciated.
    Glad to help you, NasirMunir...

    Do you have anything working thus far?

    Dököll

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      Try use Microsoft CommonDialog control for the purpose . Use the search box on the top right side of your page for further details.

      Comment

      • jacobevans
        New Member
        • Aug 2007
        • 26

        #4
        This is what I would use.

        Code:
        Private Sub cmdLoad_Click()
        If lstLoad.ListCount > 1 Then lstLoad.Clear
        On Error GoTo Cancelled
          
            cdlcommon.DialogTitle = "Load List"
            cdlcommon.CancelError = True
            cdlcommon.InitDir = App.Path
            cdlcommon.Flags = &H4
            cdlcommon.Filter = "Text File (*.txt)|*.txt|All files (*.*)|*.*"
            cdlcommon.ShowOpen
        Cancelled:
                
        End Sub
        Don't forget to add the Microsoft Common Dialog Control.

        Then to take the file you loaded you would use cdlcommon.filen ame

        Example: I would use a function to add it to a list.

        Call LoadFile(cdlcom mon.FileName)

        Code:
        Private Function LoadFile(strFile As String)
        On Error Resume Next
        Dim opt As Integer, tmpStr As String
        opt = FreeFile
        Open strFile For Input As #opt
        While Not EOF(opt)
            Input #opt, tmpStr
            lstLoad.AddItem tmpStr
        Wend
        Close #opt
        End Function

        Comment

        • Ali Rizwan
          Banned
          Contributor
          • Aug 2007
          • 931

          #5
          Originally posted by NasirMunir
          I need some help for creating a button that can allow the users to browse to a location and upload a file. I am new to VB, and any help would be greatly appreciated.
          Here is a simple way for browse button...
          Add Microsoft common control to your form.
          and add this code to your browse buttons code.

          Code:
          commondialog1.showopen
          commondialog1.filter="*.txt|Text Files|*.*|All Files" ' You can add or change this filter.
          msgbox "You have choose"&commondialog1.filename

          Now your browse button is ready to work.

          GOOD LUCK
          ALI

          Comment

          • NasirMunir
            New Member
            • Jun 2007
            • 27

            #6
            Thanks to all.
            After banging my head for few days, I figured it out how to do that :). I was not aware of command dialog box. At any rate, thanks again for all the help.

            Originally posted by Ali Rizwan
            Here is a simple way for browse button...
            Add Microsoft common control to your form.
            and add this code to your browse buttons code.

            Code:
            commondialog1.showopen
            commondialog1.filter="*.txt|Text Files|*.*|All Files" ' You can add or change this filter.
            msgbox "You have choose"&commondialog1.filename

            Now your browse button is ready to work.

            GOOD LUCK
            ALI

            Comment

            Working...