|
-
Oct 19th, 2000, 04:32 PM
#1
Thread Starter
Junior Member
I can currently pick up Multiplefiles but if I try to only select one file it throws up the MsgBox "Please Select File(s) to be Uploaded."--which it should send if they did not select a file. How can I allow someone to pick up a single file as well? Here is the code
Private Sub Command1_Click()
Dim iCounter As Integer
Dim sFolder As String
With CommonDialog1
List1.Clear
.FileName = ""
.InitDir = Trim(UploadFile)
.Flags = cdlOFNExplorer Or cdlOFNAllowMultiselect Or cdlOFNHideReadOnly
.Filter = "All files (*.*)|*.*|Text files (*.txt)|*.txt|"
.ShowOpen
On Error GoTo ErrorHandler
iCounter = 1
sFolder = Mid(.FileName, 1, InStr(iCounter, .FileName, vbNullChar) - 1)
Do Until InStr(iCounter + 1, .FileName, vbNullChar) = 0
iCounter = InStr(iCounter + 1, .FileName, vbNullChar) + 1
If InStr(iCounter, .FileName, vbNullChar) = 0 Then
List1.AddItem Mid(.FileName, iCounter)
Else
List1.AddItem Mid(.FileName, iCounter, InStr(iCounter + 1, .FileName, vbNullChar) - iCounter)
End If
Loop
If iCounter > 1 Then
Label1.Caption = "Here are the file(s) you have selected to upload, if this is not correct please choose the correct file(s)"
Label1.Visible = True
List1.Visible = True
Else
End If
End With
iCounter = 0
Exit Sub
ErrorHandler: ''Error Handeling Routine if the file is not found.
Select Case Err.Number
Case 5
Label1.Visible = False
List1.Visible = False
MsgBox "Please Select File(s) to be Uploaded."
Err.Clear
Case Else
'MsgBox Err.Number, Err.HelpFile, Err.HelpContext
MsgBox Err.Description
Resume Next
End
End Select
End Sub
-
Oct 19th, 2000, 04:36 PM
#2
Didn't have a real close look but I did see this:
Code:
If iCounter > 1 Then ...
Shouldn't that be:
Code:
If iCounter > 0 Then ...
<?>
-
Oct 19th, 2000, 04:52 PM
#3
Thread Starter
Junior Member
If you only select one file it errors out here. And apparently doesn't find a Null character to it thinks there has not been a file selected.
sFolder = Mid(.FileName, 1, InStr(iCounter, .FileName, vbNullChar) - 1)
-
Oct 31st, 2000, 03:43 PM
#4
Thread Starter
Junior Member
I figured out what my problem was
Private Sub Command1_Click()
Dim Mypos, Myfile
Myfile = "" '''Clear File Name
With CommonDialog1
List1.Clear
.FileName = ""
.InitDir = Trim(UploadFile)
.Flags = cdlOFNExplorer Or cdlOFNAllowMultiselect Or cdlOFNHideReadOnly
.Filter = "All files (*.*)|*.*|Text files (*.txt)|*.txt|"
.ShowOpen '''Open Dialog box to pick files
On Error GoTo ErrorHandler
Myfile = Mid(.FileName, InStrRev(.FileName, "\") + 1) '''Get File Name
iCounter = 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''Routine if a single file was selected''''''''''''''''''''''''''''''''''''
If InStr(1, Myfile, vbNullChar) = 0 Then '''Check to see if NullChar exists
Myfile = vbNullChar & Myfile '''Put NullChar before file name
.FileName = Dir1 & Myfile '''Plug new filename
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''Routine to Seperate Files''''''''''''''''''''''''''''''''''''''''''''''''
sFolder = Mid(.FileName, 1, InStr(iCounter, .FileName, vbNullChar) - 1) 'Pull Original Path Name
Do Until InStr(iCounter + 1, .FileName, vbNullChar) = 0 'Pull filenames until there are no more
iCounter = InStr(iCounter + 1, .FileName, vbNullChar) + 1
If InStr(iCounter, .FileName, vbNullChar) = 0 Then
List1.AddItem Mid(.FileName, iCounter)
Else
List1.AddItem Mid(.FileName, iCounter, InStr(iCounter + 1, .FileName, vbNullChar) - iCounter)
End If
Loop
If iCounter > 0 Then '''Find out if they picked any files
Label1.Caption = "Here are the file(s) you have selected to upload, if this is not correct please choose the correct file(s). If the file(s) are correct Press OK."
Label1.Visible = True
List1.Visible = True
OK1.Visible = True
Cancel1.Visible = True
Line1.Visible = True
Else
End If
End With
iCounter = 0
Exit Sub
ErrorHandler: ''Error Handeling Routine if the file is not found.
Select Case Err.Number
Case 5 ''No file was selected to upload
OK1.Visible = False
Cancel1.Visible = False
Line1.Visible = False
Label1.Visible = False
List1.Visible = False
MsgBox "Please Select File(s) to be Uploaded."
Err.Clear
Case Else
'MsgBox Err.Number, Err.HelpFile, Err.HelpContext
MsgBox Err.Description
Err.Clear
Resume Next
End
End Select
End Sub
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
|