locked
Error in Loop Result, Help ???? RRS feed

  • Question

  • User-982972619 posted

    Hi guys it's me again. I have a problem in my VB.NET program

    I have this code for looping:

    1    For i As Integer = 0 To slsList.Count - 1
    2                m_lp.Print(m_lp.PadL(slsList.Item(0), 20), True)
    3                m_lp.Print(m_lp.PadL(slsList.Item(1), 30), True)
    4                m_lp.Print(m_lp.PadL(slsList.Item(2), 25), True)
    5                m_lp.Print(m_lp.PadL(slsList.Item(3), 30), True)
    6                m_lp.Print(m_lp.PadL(slsList.Item(4), 20), True)
    7                m_lp.Print(m_lp.PadL(slsList.Item(5), 30))
    8    Next
    
    It loop the database column data and stored in an ArrayList variable called slsList.
    When click the show data button, instead of looping like this:
    Province     Supervisor Name     Employee Name      Employee Code 
    -----------------------------------------------------------------
    NTB	     Jack		Richard		   TN0001
    NTB	     Jack		Angela		   TN0002
    NTB	     Jim		Brett		   TN0004
     
    The result is showing this:
    Province     Supervisor Name     Employee Name      Employee Code 
    -----------------------------------------------------------------
    NTB	     			Jack		    TN0005
    NTB				Jack		    TN0005
    NTB				Jack		    TN0005
     
    So The problem is, the result only show the province and just the supervisor name and supervisor code again and again, instead
    of showing the correct ones(the first correct looping results). So can you guys help me please, can you tell me what's wrong, my program is
    all goin' haywire. I appreciate all kinds of help.
     
    FYI: I use Visual Studio .NET 2003 and SQL Server 2000 
     
    Best Regards. 
     
     
     
    Friday, April 18, 2008 12:35 AM

Answers

  • User-1125720926 posted

    you're not making use of the i var in your looping..

    you're only extracting the first item in your arraylist..

    try using a "for each" instead this will loop over each item in the arraylist:

    for each (object AnItem in slsList.Items)

    {

    m_lp.Print(m_lp.PadL(AnItem[0], 20), True)
    item[1] ... etc...

    }

    ...

    sorry I can't remember vb syntax but it's similar!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 18, 2008 5:55 AM