?
Solved

Loop Structures in VB6.0

Posted on 2006-04-21
6
Medium Priority
?
4,112 Views
Last Modified: 2008-01-09
suppose there are 5 values in a table..i am fetching the values using while loop..
while fetching the 3rd value some of the values doesnt match with the validation criterion..
so i need to move on to the next value in the loop without fetchin this one...
how can i do this without using GOTO statement....
give suggestion....

Eg:

 Do While bRet = True
   
             gsInvNo = UCase(Trim$(eSheet.Cells(iRwCnt, 1)))
             
             If gsInvNo = "Null" Then
               gsInvNo = ""
             End If
               
             gsInvDate = UCase(Trim$(eSheet.Cells(iRwCnt, 2)))
             gsInvType = UCase(Trim$(eSheet.Cells(iRwCnt, 3)))
              If gsInvType = "NULL" Then
               gsInvType = ""
             End If
             gsSupCode = UCase(Trim$(eSheet.Cells(iRwCnt, 4)))
              If gsSupCode = "NULL" Then
               gsSupCode = ""
             End If
             gsInvAmt = UCase(Trim$(eSheet.Cells(iRwCnt, 5)))
              If gsInvAmt = "NULL" Then
               gsInvAmt = ""
             End If
             gsPoRefNo = UCase(Trim$(eSheet.Cells(iRwCnt, 6)))
              If gsPoRefNo = "NULL" Then
               gsPoRefNo = ""
             End If
loop
0
Comment
Question by:lazziebob
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 172 total points
ID: 16506123
something like this:

dim blnTakeRecord as boolean

Do While bRet = True
      blnTakeRecord = true

             gsInvNo = UCase(Trim$(eSheet.Cells(iRwCnt, 1)))
             
             If gsInvNo = "Null" Then
               gsInvNo = ""
               blnTakeRecord = false
             End If
             
             if blnTakeRecord then  
               gsInvDate = UCase(Trim$(eSheet.Cells(iRwCnt, 2)))
               gsInvType = UCase(Trim$(eSheet.Cells(iRwCnt, 3)))
                If gsInvType = "NULL" Then
                 gsInvType = ""
                 blnTakeRecord = false
               End If
             end if

             if blnTakeRecord then
               gsSupCode = UCase(Trim$(eSheet.Cells(iRwCnt, 4)))
                If gsSupCode = "NULL" Then
                 gsSupCode = ""
                 blnTakeRecord = false
               End If
             end if

            if blnTakeRecord then
             gsInvAmt = UCase(Trim$(eSheet.Cells(iRwCnt, 5)))
              If gsInvAmt = "NULL" Then
               gsInvAmt = ""
                 blnTakeRecord = false
             End If
            end if

            if blnTakeRecord then
             gsPoRefNo = UCase(Trim$(eSheet.Cells(iRwCnt, 6)))
              If gsPoRefNo = "NULL" Then
               gsPoRefNo = ""
                 blnTakeRecord = false
             End If
           end if

      if blnTakeRecord then
          'do what you want with the record
      end if
loop

0
 
LVL 1

Assisted Solution

by:rbvoigt
rbvoigt earned 164 total points
ID: 16534627
Better is a nested once-through loop, by exiting the inner loop you reach the bottom of the outer loop.

 Do While bRet = True
    Do
             gsInvNo = UCase(Trim$(eSheet.Cells(iRwCnt, 1)))
             
             If gsInvNo = "Null" Then
               gsInvNo = ""
               Exit Do
             End If
               
             gsInvDate = UCase(Trim$(eSheet.Cells(iRwCnt, 2)))
             gsInvType = UCase(Trim$(eSheet.Cells(iRwCnt, 3)))
              If gsInvType = "NULL" Then
               gsInvType = ""
               Exit Do
             End If
             gsSupCode = UCase(Trim$(eSheet.Cells(iRwCnt, 4)))
              If gsSupCode = "NULL" Then
               gsSupCode = ""
               Exit Do
             End If
             gsInvAmt = UCase(Trim$(eSheet.Cells(iRwCnt, 5)))
              If gsInvAmt = "NULL" Then
               gsInvAmt = ""
               Exit Do
             End If
             gsPoRefNo = UCase(Trim$(eSheet.Cells(iRwCnt, 6)))
              If gsPoRefNo = "NULL" Then
               gsPoRefNo = ""
               Exit Do
             End If
    Loop Until True
loop
0
 
LVL 1

Expert Comment

by:rbvoigt
ID: 16534641
Of course you can also put the loop action in a function, and use exit function to skip to the next iteration
0
 
LVL 3

Assisted Solution

by:prafful_nagwani
prafful_nagwani earned 164 total points
ID: 16594192
'General Declaration
Dim blnTest As Boolean

Private Function CheckSub(testString As String)
    blnTest = True
    If testString = "NULL" Or testString = Empty Then blnTest = False
End Function

Private Sub Test()
    bRet = True
    Do While bRet = True
        gsInvNo = UCase(Trim$(eSheet.Cells(iRwCnt, 1))): CheckSub (gsInvNo)
        If blnTest = True Then gsInvDate = UCase(Trim$(eSheet.Cells(iRwCnt, 2))): CheckSub (gsInvDate)
        If blnTest = True Then gsInvType = UCase(Trim$(eSheet.Cells(iRwCnt, 3))): CheckSub (gsInvType)
        If blnTest = True Then gsSupCode = UCase(Trim$(eSheet.Cells(iRwCnt, 4))): CheckSub (gsSupCode)
        If blnTest = True Then gsInvAmt = UCase(Trim$(eSheet.Cells(iRwCnt, 5))): CheckSub (gsInvAmt)
        If blnTest = True Then gsPoRefNo = UCase(Trim$(eSheet.Cells(iRwCnt, 6))): CheckSub (gsPoRefNo)
    Loop
End Sub

Private Sub Form_Load()
    Test
End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Introduction to Processes
Screencast - Getting to Know the Pipeline

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question