Results 1 to 2 of 2

Thread: Confused about loops

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    13

    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:
    1. for each file in folder1.files
    2.  
    3.     if (Left(file.Name,Len(file.Name) - InStr(file.Name,".ci"))) = "DQ" then
    4.    
    5.         cidFileName = file.Name
    6.         dqNumber = replace(file.name,".ci","")
    7.    
    8.         ForReading1 = 1
    9.    
    10.         'Create the file system object
    11.         Set fso = CreateObject("Scripting.FileSystemObject")
    12.    
    13.         'Initialize a few items
    14.         strSource = "F:\Am\EXCEL.CSV"
    15.        
    16.         'Open the source file to read it
    17.         Set ts = fso.OpenTextFile(strSource,ForReading1)
    18.    
    19.         'Read the file line by line
    20.         Do while not ts.AtEndOfStream
    21.             strLine = ts.ReadLine
    22.             'Remove the quotes from the string
    23.             strLine = Replace(strLine, Chr(34), "")
    24.             'Split the line on the comma into an array
    25.             strValues = Split(strLine, ",")
    26.    
    27.             'Check if the dq number matches
    28.             For i = 15 to 27
    29.                 If strValues(i) = dqNumber Then
    30.                     'Get the other values you need
    31.                     soNumber = strValues(0)
    32.                     setNumber = strValues(2)
    33.                     sideNumber = strValues(4)
    34.                    
    35.                     'Set flag that say the value was found
    36.                     blnFound = True
    37.                    
    38.                     'Exit the loop
    39.                     Exit Do
    40.  
    41.                 End If
    42.             Next
    43.  
    44.         Loop
    45.    
    46.  
    47.        
    48.        
    49.  
    50.         'Close the file
    51.         ts.Close
    52.    
    53.         msgbox(soNumber&" "&setNumber&" "&sideNumber)
    54.  
    55.              End If
    56.  
    57. Next

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132

    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
  •  



Click Here to Expand Forum to Full Width