Solved

Loops

Posted on 2004-10-29
223 Views
Last Modified: 2010-04-23
I have a form that pops up and shows all jobs associated with one person.  Next to each job, is a checkbox.  If the checkbox is checked I want the data printed into excel.  One job per row.  I have the first job being printed into one column--now I need a loop to do the other checkboxes.

                                            Dim i as integer = 0
                                            While (CBool(dt.Rows(iIndex).Item("To_Print")) = True)
                                                oSheet.Cells(i + 1, 1) = FileNum
                                                oSheet.Cells(i + 1, 2) = Recipient
                                                oSheet.Cells(i + 1, 3) = SSN
                                                oSheet.Cells(i + 1, 4) = RecipientAddress
                                                oSheet.Cells(i + 1, 5) = RecipientAddress2
                                                oSheet.Cells(i + 1, 6) = RecipientCity
                                                oSheet.Cells(i + 1, 7) = RecipientState
                                                oSheet.Cells(i + 1, 8) = RecipientZip
                                                oSheet.Cells(i + 1, 9) = RecipientPhone
                                                oSheet.Cells(i + 1, 10) = SpecialInstructions
                                                oSheet.Cells(i + 1, 11) = AKAofPersonServed
                                                oSheet.Cells(i + 1, 12) = ServiceManner
                                                oSheet.Cells(i + 1, 13) = StatusDate
                                                oSheet.Cells(i + 1, 14) = EmployerName
                                                oSheet.Cells(i + 1, 15) = EmployerAddress1
                                                oSheet.Cells(i + 1, 16) = EmployerAddress2
                                                oSheet.Cells(i + 1, 17) = EmployerAddress3
                                                oSheet.Cells(i + 1, 18) = EmployerAddress4
                                                oSheet.Cells(i + 1, 19) = EmployerAddress5
                                                oSheet.Cells(i + 1, 20) = PersonCompanyPhone
                                                oSheet.Cells(i + 1, 21) = Comments
                                                oSheet.Cells(i + 1, 22) = JobNum
                                                oSheet.Cells(i + 1, 23) = ClientFee
                                            End While
0
Question by:computerg33k
    2 Comments
     
    LVL 44

    Accepted Solution

    by:
    change your code like this:

                                        Dim i as integer = 0
                                       
                                         do while iRow as Integer < dt.Rows.Count
                                                If  (CBool(dt.Rows(iRow).Item("To_Print")) = True)
                                                    oSheet.Cells(i + 1, 1) = FileNum
                                                    oSheet.Cells(i + 1, 2) = Recipient
                                                    oSheet.Cells(i + 1, 3) = SSN
                                                    oSheet.Cells(i + 1, 4) = RecipientAddress
                                                    oSheet.Cells(i + 1, 5) = RecipientAddress2
                                                    oSheet.Cells(i + 1, 6) = RecipientCity
                                                    oSheet.Cells(i + 1, 7) = RecipientState
                                                    oSheet.Cells(i + 1, 8) = RecipientZip
                                                    oSheet.Cells(i + 1, 9) = RecipientPhone
                                                    oSheet.Cells(i + 1, 10) = SpecialInstructions
                                                    oSheet.Cells(i + 1, 11) = AKAofPersonServed
                                                    oSheet.Cells(i + 1, 12) = ServiceManner
                                                    oSheet.Cells(i + 1, 13) = StatusDate
                                                    oSheet.Cells(i + 1, 14) = EmployerName
                                                    oSheet.Cells(i + 1, 15) = EmployerAddress1
                                                    oSheet.Cells(i + 1, 16) = EmployerAddress2
                                                    oSheet.Cells(i + 1, 17) = EmployerAddress3
                                                    oSheet.Cells(i + 1, 18) = EmployerAddress4
                                                    oSheet.Cells(i + 1, 19) = EmployerAddress5
                                                    oSheet.Cells(i + 1, 20) = PersonCompanyPhone
                                                    oSheet.Cells(i + 1, 21) = Comments
                                                    oSheet.Cells(i + 1, 22) = JobNum
                                                    oSheet.Cells(i + 1, 23) = ClientFee
                                               End If
                                               i += 1
                                               iRow += 1
                                           End While

    AW
    0
     
    LVL 4

    Author Comment

    by:computerg33k
    sounds like it'll work--but what is irow?  and it says do must end with a matching loop?
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    Suggested Solutions

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    934 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

    21 Experts available now in Live!

    Get 1:1 Help Now