Results 1 to 2 of 2

Thread: How to use loop to add receipts one by one?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    478

    How to use loop to add receipts one by one?

    I used code below to send an email to multiple users. It works fine.

    mail.[To].Add("aaa@mycompany.com")
    mail.CC.Add("bbb@mycompany.com")
    mail.CC.Add("ccc@mycompany.com")
    mail.CC.Add("ddd@mycompany.com")

    Now, I want to store email receipts in a table so that I do not re-compile app if email receipts were changed.

    How to use loop to add receipts one by one?

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: How to use loop to add receipts one by one?

    First you must have some sort of collection. You mentioned a table, so I'm assuming you want a data table. So let's first declare that:

    Code:
    Dim receiptTable As DataTable = New DataTable
    Next we must add at least one(1) column, our receipt column:

    Code:
    Dim receiptColumn As DataColumn = New DataColumn("Receipt")
    Now we start looping. Really any loop will do, but the easiest loop to use in this case would be the For/Next loop. So let's start up the loop. You didn't mention how many records there will be, so I will just loop to 10:

    Code:
    For i As Integer = 1 To 10
    
    Next
    Inside the loop we declare a new row from our data table and set it to some value:

    Code:
    For i As Integer = 1 To 10
        Dim dr As DataRow = receiptTable.NewRow
        dr(0) = i.ToString
        receiptTable.Rows.Add(dr)
    Next
    In the example above, I just set the value of the new row(in column 0, our receiptColumn) to what iteration we are currently on. Now you'll do something similar, the difference will be:
    1. Where you start in the loop(most likely 0)
    2. Where you end in the loop
    3. The values being added in the loop


    But you didn't provide enough information for me to address those three(3) differences.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

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