Results 1 to 8 of 8

Thread: File1, Dir1,Drive1

  1. #1

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    This is going to be hard to explain but i will do my best.
    Ok, i have 5 textboxes and beside those 5 text boxes i have 5 command buttons . When a button is pressed another form pops up with File1 Dir1 and Drive1 boxes in place. When a user selects a file, the file name and path go to the text box that the button was beside. But my problem is that...i don't want to have 5 forms that look and act exactly alike. So i was wondering how should i go about using one form and be able to select files for each of those text boxes.
    Maybe the screen shot will explain it better.
    http://dim.clan2rw.com/program.gif

    Thank you,
    D!m
    ps. I think i would have to store the selected file as a var, but i just have too much code in my head to figure out how.
    Dim

  2. #2
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    How about a global/module level variable. Use it to store the filename/path as a string from your File1,Dir1 form. In the form with the textboxes just use the global variable.

  3. #3

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    =/
    So something in the lines of...
    Code:
    Dim varup1 As String
        varup1 = Form2.File1.Path & "\" & Form2.File1.FileName
    Dim varup2 As String
        varup2 = Form2.File1.Path & "\" & Form2.File1.FileName
    .
    .
    .
    'And for the textboxes
    Text1.Text = varup1
    Text2.Text = varup2
    =/ That don look too good.
    Dim

  4. #4
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Not quite.

    Place something like:

    Public PathString as String

    in a module.


    Now when someone clicks on the button and selects the file :

    PathString = Form2.File1.Path & "\" & Form2.File1.FileName


    Now set it to the textbox

    Text1.Text = PathString



    Now say they click on the second button/textbox

    PathString = ""
    PathString = Form2.File1.Path & "\" & Form2.File1.FileName

    Set it to the second textbox

    Text2.Text = PathString



    Just use the one variable and use that to assign the textboxes text with. Then whenever you need the string in the textbox just use the Text1.Text for the string.





  5. #5
    Guest
    Why don't you use CommonDialog?
    Place a CommonDialog control on the form.

    Code:
    Private Sub Command1_Click()
        Dim iFile As Integer
        On Error GoTo User_Cancelled
        With CommonDialog1
        .CancelError = True
        .DialogTitle = "Select a File.."
        .Filter = "File (*.*)|*.*"
        .ShowOpen
        Text1.text = CommonDialog1.FileName
        End With
    User_Cancelled:
    End Sub
    Do the same for all the command buttons.

    [Edited by Matthew Gates on 07-11-2000 at 10:13 PM]

  6. #6

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    I'm supposed to have a min size for this aplication. and adding controls isn't one of my first choices. I know it will be much easier. But...well...about how many k's will it add?
    Dim

  7. #7
    Guest
    You just do:

    For text1:
    Code:
    Private Sub Command1_Click()
        Dim iFile As Integer
        On Error GoTo User_Cancelled
        With CommonDialog1
        .CancelError = True
        .DialogTitle = "Select a File.."
        .Filter = "File (*.*)|*.*"
        .ShowOpen
        Text1.text = CommonDialog1.FileName
        End With
    User_Cancelled:
    End Sub
    For text2:
    Code:
    Private Sub Command2_Click()
        Dim iFile As Integer
        On Error GoTo User_Cancelled
        With CommonDialog1
        .CancelError = True
        .DialogTitle = "Select a File.."
        .Filter = "File (*.*)|*.*"
        .ShowOpen
        Text2.text = CommonDialog1.FileName
        End With
    User_Cancelled:
    End Sub
    For text3:
    Code:
    Private Sub Command3_Click()
        Dim iFile As Integer
        On Error GoTo User_Cancelled
        With CommonDialog1
        .CancelError = True
        .DialogTitle = "Select a File.."
        .Filter = "File (*.*)|*.*"
        .ShowOpen
        Text3.text = CommonDialog1.FileName
        End With
    User_Cancelled:
    End Sub
    For text4:
    Code:
    Private Sub Command4_Click()
        Dim iFile As Integer
        On Error GoTo User_Cancelled
        With CommonDialog1
        .CancelError = True
        .DialogTitle = "Select a File.."
        .Filter = "File (*.*)|*.*"
        .ShowOpen
        Text4.text = CommonDialog1.FileName
        End With
    User_Cancelled:
    End Sub
    For text5:
    Code:
    Private Sub Command5_Click()
        Dim iFile As Integer
        On Error GoTo User_Cancelled
        With CommonDialog1
        .CancelError = True
        .DialogTitle = "Select a File.."
        .Filter = "File (*.*)|*.*"
        .ShowOpen
        Text5.text = CommonDialog1.FileName
        End With
    User_Cancelled:
    End Sub
    The CommonDialog control can be used for all. Simple as that. And for the Filter, it says "File (*.*)|*.*", you might want to change that to plural instead of just one..or change it to what you'd like. Hope that helps.


  8. #8

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Hehe thanx Matt, you didn't have to go into that much detail but thanx.
    Dim

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