Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strange error

Status
Not open for further replies.

Oostwijk

Technical User
Oct 19, 2003
82
NL
What is wrong with this ?
I'm not always getting an subscript out of range, but when Filelistbox File1
contains these files:

uwvGAK sollicitatie.doc
cv
BLABLAR.DOC
cv.doc
brief16-07-2002.DOC
uitkeringsdeskundige.DOC
gembel.doc
h&m.doc
vvbs.doc
uszoterug.doc
CV2.doc
belast2001.doc
openweb.DOC
uszoterug2.doc
upc+deurwaarder.doc
verzoekdiemen.doc
upc+deurwaarder2.doc
groeneland.doc
belast2001c.doc
Daisycon.doc
belast2001b.doc
belkwijt_bijl.doc
openadministratief.DOC
belastinfo.doc
uszooverzicht.doc
speciaal
lol.txt
dreizen.doc
Google.doc
Google.txt
locuscentre.doc
roclelystad.doc


it goes wrong at nFile = nFile & Text3.Text & Asperge & Text4.Text & "." & arrFil(1).
While other directories aren't giving problems.
What am I doing wrong and what can I do to solve it ?

Private Sub Command1_Click()
Dim i As Integer, arrFil() As String, Lastokfile As String
Dim sFile As String, nFile As String, antw As Integer
Dim Asperge As Integer, Dezedir As String, myfile As String
Dim bestandsnummer As Integer, FDS As String, FS As String

If Text2.Text = "" Then Text2.Text = "1"
Asperge = Text2.Text
For i = 0 To File1.ListCount - 1

arrFil = Split(File1.List(i), ".")

If Right$(File1.Path, 1) <> &quot;\&quot; Then
sFile = File1.Path & &quot;\&quot; & File1.List(i)
Else
sFile = File1.Path & File1.List(i)
End If

nFile = Dir2.Path
If Right$(Dir2.Path, 1) <> &quot;\&quot; Then
nFile = nFile & &quot;\&quot;
End If
nFile = nFile & Text3.Text & Asperge & Text4.Text & &quot;.&quot; & arrFil(1)

<<<<<<<<<< rest of my lines >>>>>>>>>
 
Its the file without an extension, so arrFil() UBound is 0, when your trying to retrieve arrFil(1)
 
Select Case UBound(arrFil())
Case 0
nFile = nFile & Text3.Text & Asperge & Text4.Text
Case Else
nFile = nFile & Text3.Text & Asperge & Text4.Text & &quot;.&quot; & arrFil(1)
End Select
 
hi Lplates, good to see you again

I've placed Select Case UBound(arrFil())
Case 0
nFile = nFile & Text3.Text & Asperge & Text4.Text
Case Else
nFile = nFile & Text3.Text & Asperge & Text4.Text & &quot;.&quot; & arrFil(1)
End Select

after the line:
arrFil = Split(File1.List(i), &quot;.&quot;)

But i'm still getting a subscript out of range.

 
Oops sorry, I looked better and placed the code at the right spot. It works great now. Thanks
 
Ok, Great! Just browsing at your code, its the file extension from the filename you wish to add to the nFile variable. In case the file has more than one Period or '.' in it, use UBound(arrFil()) to get the UBound of arrFil which contains the file extension like below, else if the filename is Test.Example.Txt you will end up with 'Example' as the file extension and so on.

Select Case UBound(arrFil())
Case 0
nFile = nFile & Text3.Text & Asperge & Text4.Text
Case Else
nFile = nFile & Text3.Text & Asperge & Text4.Text & &quot;.&quot; & arrFil(UBound(arrFil()))
End Select

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top