Error Parsing Data 
Author Message
 Error Parsing Data

Hi all
    There is a problem I am having that hopefully someone could help me out
with.  I have a script that basically reads through a text file that
contains a listing of user directories on a file server.  The text file is
comprised of lines that look like the following:

[juser]
[jsmith]
[cloughli]

As you can see each username is surrounded by brackets.  The problem is that
the last line of the file is not a username surrounded by brackets but
instead some information on the folder (all this info is from a batch file
that does an "ls -1" command).  This last line looks like this:

    4096 (595) bytes in 1 files

My question is: How do I make the code (which follows) ignore a line in the
file if it has no brackets?  As of now it errors out and quits out of the
loop altogether.

Here is the code to remove the brackets and take the remaining username and
store it in a variable:

'///////////////////////
'Drives is an array that contains each line of the text file created by
doing: Drives = Split(newDrivesTextStream.ReadAll, vbNewLine)
'sWithoutLeft is a variable to hold the username without the left bracket
'nCharOfBracket determines where the next bracket is in the line of the text
file that we are looking at
'lUsername is a temporary variable to hold the left most portion of the file
line that doesn't have the remaining bracket
'\\\\\\\\\\\\\\\\\\\\\\\\\\\

Do While x < UBound(Drives)
      sWithoutLeft = Mid(Drives(x), 2)
      nCharOfBracket = InStr (sWithoutLeft,"]")
      nCharOfBracketLessOne = nCharOfBracket - 1
      lUsername = Left(sWithoutLeft, nCharOfBracketLessOne)
      If size >= asize Then
'You can ignore the rest of this loop, it simply reads lUsername into
another array
           asize = asize + 100
           ReDim Preserve sDrive(asize)
      End If
      sDrive(size) = lUsername
      size = size+1
     x = x+1
Loop



Sun, 15 Sep 2002 03:00:00 GMT  
 Error Parsing Data
Do While x < UBound(Drives)
      '
      ' assumes *only* the last line does not start with [
      '
      if left(Drives(x),1) <> "[" then exit do
      sWithoutLeft = Mid(Drives(x), 2)
      nCharOfBracket = InStr (sWithoutLeft,"]")
      nCharOfBracketLessOne = nCharOfBracket - 1
      lUsername = Left(sWithoutLeft, nCharOfBracketLessOne)
      If size >= asize Then
'You can ignore the rest of this loop, it simply reads lUsername into
another array
           asize = asize + 100
           ReDim Preserve sDrive(asize)
      End If
      sDrive(size) = lUsername
      size = size+1
     x = x+1
Loop

--
Michael Harris
MVP Scripting


Hi all
    There is a problem I am having that hopefully someone could help me out
with.  I have a script that basically reads through a text file that
contains a listing of user directories on a file server.  The text file is
comprised of lines that look like the following:

[juser]
[jsmith]
[cloughli]

As you can see each username is surrounded by brackets.  The problem is that
the last line of the file is not a username surrounded by brackets but
instead some information on the folder (all this info is from a batch file
that does an "ls -1" command).  This last line looks like this:

    4096 (595) bytes in 1 files

My question is: How do I make the code (which follows) ignore a line in the
file if it has no brackets?  As of now it errors out and quits out of the
loop altogether.

Here is the code to remove the brackets and take the remaining username and
store it in a variable:

'///////////////////////
'Drives is an array that contains each line of the text file created by
doing: Drives = Split(newDrivesTextStream.ReadAll, vbNewLine)
'sWithoutLeft is a variable to hold the username without the left bracket
'nCharOfBracket determines where the next bracket is in the line of the text
file that we are looking at
'lUsername is a temporary variable to hold the left most portion of the file
line that doesn't have the remaining bracket
'\\\\\\\\\\\\\\\\\\\\\\\\\\\

Do While x < UBound(Drives)
      sWithoutLeft = Mid(Drives(x), 2)
      nCharOfBracket = InStr (sWithoutLeft,"]")
      nCharOfBracketLessOne = nCharOfBracket - 1
      lUsername = Left(sWithoutLeft, nCharOfBracketLessOne)
      If size >= asize Then
'You can ignore the rest of this loop, it simply reads lUsername into
another array
           asize = asize + 100
           ReDim Preserve sDrive(asize)
      End If
      sDrive(size) = lUsername
      size = size+1
     x = x+1
Loop



Sun, 15 Sep 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. problem of parsing Gif raster data

2. Parsing data from text and html files

3. Parsing Data from NT Res kit utilities

4. Parsing a string with data separated by variable numbers of blanks (NEWBIE ALERT)

5. Beginner- Parsing Data

6. Parsing data out of an email

7. Get error: Disallowed implicit conversion from data type varchar to data type money

8. Tiff2PDF conversion Insufficient Data for an image error

9. not an object error with data binding

10. Data missing Errors

11. Truncated Data Error

12. An error occured while reading response data from the server

 

 
Powered by phpBB® Forum Software