|
-
Sep 30th, 2009, 05:39 PM
#1
Thread Starter
New Member
Confused about loops
I am totally lost on this looping stuff. I am new to this, and am still learning so please bear with me. How Do I tell the code that if the dqNumber is not found, move on to the next file in the folder?
1 Code:
for each file in folder1.files
if (Left(file.Name,Len(file.Name) - InStr(file.Name,".ci"))) = "DQ" then
cidFileName = file.Name
dqNumber = replace(file.name,".ci","")
ForReading1 = 1
'Create the file system object
Set fso = CreateObject("Scripting.FileSystemObject")
'Initialize a few items
strSource = "F:\Am\EXCEL.CSV"
'Open the source file to read it
Set ts = fso.OpenTextFile(strSource,ForReading1)
'Read the file line by line
Do while not ts.AtEndOfStream
strLine = ts.ReadLine
'Remove the quotes from the string
strLine = Replace(strLine, Chr(34), "")
'Split the line on the comma into an array
strValues = Split(strLine, ",")
'Check if the dq number matches
For i = 15 to 27
If strValues(i) = dqNumber Then
'Get the other values you need
soNumber = strValues(0)
setNumber = strValues(2)
sideNumber = strValues(4)
'Set flag that say the value was found
blnFound = True
'Exit the loop
Exit Do
End If
Next
Loop
'Close the file
ts.Close
msgbox(soNumber&" "&setNumber&" "&sideNumber)
End If
Next
-
Oct 1st, 2009, 01:52 AM
#2
Addicted Member
Re: Confused about loops
Hi,
you move already to the next file in folder with the for each loop and you check already with "If strValues(i) = dqNumber Then" if the number exist in den EXCEL.csv file.
The only thing whats maybe a Problem is the first check
(Left(file.Name,Len(file.Name) - InStr(file.Name,".ci"))) = "DQ"
this implies that the filename have the following format
DQ<number>.ci
exactly where it's written there.
This means "dq<nnn>.ci" or "DQ<nnn>.CI" will not your check.
To achive this you should store file.name in a symbol and convert the value of the symbol to upper or lower case and change the checking e.g for uppercase.
szName = ucase(file.name)
(Left(szName,Len(szName) - InStr(szName,".CI"))) = "DQ"
best regards
TheOnly
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
|