|
-
Jul 11th, 2000, 08:43 PM
#1
Thread Starter
Fanatic Member
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.
-
Jul 11th, 2000, 08:50 PM
#2
Fanatic Member
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.
-
Jul 11th, 2000, 08:59 PM
#3
Thread Starter
Fanatic Member
=/
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.
-
Jul 11th, 2000, 09:07 PM
#4
Fanatic Member
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.
-
Jul 11th, 2000, 09:10 PM
#5
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]
-
Jul 11th, 2000, 09:15 PM
#6
Thread Starter
Fanatic Member
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?
-
Jul 11th, 2000, 09:33 PM
#7
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.
-
Jul 11th, 2000, 09:40 PM
#8
Thread Starter
Fanatic Member
Hehe thanx Matt, you didn't have to go into that much detail but thanx.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|