Results 1 to 5 of 5

Thread: For loop question...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93

    Question

    Please tell me there's a way to do this other than using a
    bunch of If statements. What I'm looking for is a way to do
    what "continue" does in C.

    I have a text file I've read into an array of strings, each
    element of teh array is a line in the file. for some lines,
    I only need to do minimal things, some are even discarded.
    Here's what I wanted to do

    Function Parse_Lines(FileArray() As String, OptionArray() As tOption) As Boolean

    Dim x As Integer, y As Integer, EndTagPos As Integer
    Dim OneChar As String, KeyWord As String, FileComments As String

    FileComments = ""
    KeyWord = ""

    For x = 1 To UBound(FileArray)
    If (Mid$(FileArray(x), 1, 1) = "") Or _
    Just_Spaces(FileArray(x), 1) Then
    <do a "Next x" or something like that to
    skip the rest>
    End If

    If Mid$(FileArray(x), 1, 1) = "#" Then
    FileComments = FileComments & Mid$(FileArray(x), _
    2, Len(FileArray(x)) & vbNewLine)
    <something like a Next X>
    End If

    ... a whole lot more string parsing...

    I know you can use a whole bunch of nested If's but
    that's just so damn ugly. Is there any way to start
    the next iteration of the for loop without traversing the
    whole loop?

    -Rich



  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    the only thing I can think of is if you do something like this

    Code:
    Dim i As Long
    Dim j As Long
    Dim boolNextIteration As Boolean
    For i = 1 to 10
    
        For j = 1 To 1
    
            'Put Code Here
    
            If boolNextIteration Then Exit For
    
            'More Code Here
    
        Next j
    
    Next i
    Hope this helps

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93

    Thumbs up

    Thanks.. that will do the trick. I threw in a goto but I definately wasn't happy using that either. This should do. A continue statement would be much cooler though.

  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    May be you can use Select Case

    Code:
    For x = 1 To UBound(FileArray)
            Select Case Mid$(FileArray(x), 1, 1)
                Case ""
                    '....
                Case "#"
                    '...
            End Select
    Next

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93
    Switch isn't going to work out for me but it was a good idea. There are some instances where I need the first two characters and switch wont (I don't think) support that. Thanks for the suggestion though.

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