Solved

help with loop

Posted on 2004-03-22
1
176 Views
Last Modified: 2010-05-01
I wrote this code to pull the first borr_nrb which (is 1). And the first instance of  brr-nbr (one). Once it is found I want it to fine borr_nbr (2) and give me the first instance of borr_nbr 2. I need help is setting up the loop or counter.
Thanks

Dim Result
Dim intIndex As integer
Dim strAddr As string

For intIndex = 1 To Val(CDE.LT-ADDRESS.BORR-ADDR("Count"))
      If Val(CDE.LT-ADDRESS.BORR-NBR(intIndex)) = vElementIndex Then
            strAddr = Trim(CDE.LT-ADDRESS.BORR-ADDR(intIndex))
            If Trim(CDE.LT-ADDRESS.BORR-ADDR2(intIndex)) <> "" Then
                  strAddr = strAddr & ", " & Trim(CDE.LT-ADDRESS.BORR-ADDR2(intIndex))
            End If
            If CDE.LT-ADDRESS.MILIT-FLAG(intIndex) = True Then
                  If Trim(CDE.LT-ADDRESS.MILIT-ADDR(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT-ADDRESS.MILIT-ADDR(intIndex))
                  End If
            Else
                  If Trim(CDE.LT-ADDRESS.BORR-CITY(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT-ADDRESS.BORR-CITY(intIndex))
                  End If
                  If Trim(CDE.LT-ADDRESS.BORR-ST(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT-ADDRESS.BORR-ST(intIndex))
                  End If
                  If Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex)) <> "" Then
                        strAddr = strAddr & "  "
                        If Len(Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex))) = 9 Then
                              strAddr = strAddr & LEFT(Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex)), 5) & "-"
                              strAddr = strAddr & RIGHT(Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex)), 4)
                        Else
                              strAddr = strAddr & Trim(CDE.LT-ADDRESS.BORR-ZIP(intIndex))
                        End If
                  End If
            End If
            Exit For
      End If
Next
0
Comment
Question by:cdb424ttm
1 Comment
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 10651928
I'm guessing that this is what you want.


Dim Result
Dim intIndex As Integer
Dim strAddr As String
Dim vElementIndex As Integer

For vElementIndex = 1 To 2
    For intIndex = 1 To Val(CDE.LT - ADDRESS.BORR - ADDR("Count"))
         If Val(CDE.LT - ADDRESS.BORR - NBR(intIndex)) = vElementIndex Then
              strAddr = Trim(CDE.LT - ADDRESS.BORR - ADDR(intIndex))
              If Trim(CDE.LT - ADDRESS.BORR - ADDR2(intIndex)) <> "" Then
                   strAddr = strAddr & ", " & Trim(CDE.LT - ADDRESS.BORR - ADDR2(intIndex))
              End If
              If CDE.LT - ADDRESS.MILIT - FLAG(intIndex) = True Then
                   If Trim(CDE.LT - ADDRESS.MILIT - ADDR(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT - ADDRESS.MILIT - ADDR(intIndex))
                   End If
              Else
                   If Trim(CDE.LT - ADDRESS.BORR - CITY(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT - ADDRESS.BORR - CITY(intIndex))
                   End If
                   If Trim(CDE.LT - ADDRESS.BORR - ST(intIndex)) <> "" Then
                        strAddr = strAddr & ", " & Trim(CDE.LT - ADDRESS.BORR - ST(intIndex))
                   End If
                   If Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex)) <> "" Then
                        strAddr = strAddr & "  "
                        If Len(Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex))) = 9 Then
                             strAddr = strAddr & Left(Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex)), 5) & "-"
                             strAddr = strAddr & Right(Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex)), 4)
                        Else
                             strAddr = strAddr & Trim(CDE.LT - ADDRESS.BORR - ZIP(intIndex))
                        End If
                   End If
              End If
              Exit For
         End If
    Next
Next vElementIndex
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now