Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1. Guest ji, please consider donating today!
      Become a Supporter    ::   Make a Contribution   
    Monthly Recurring Target: $300 :: Achieved: $95

For and If loops

Discussion in 'Information Technology' started by thusnani@gmail.com, Jul 28, 2006.

Tags:
  1. thusnani@gmail.com

    thusnani@gmail.com
    Expand Collapse
    Guest

    Im trying to put if loops in one for loop and im getting this error:
    "Complie Error: Next without for"
    Here is my code. What am i forgetting

    Dim i As Integer
    i = 1

    For Each varItem In Me!ProjectList.ItemsSelected
    project = Me!ProjectList.ItemData(varItem)
    If i = 1 Then
    Label1.Visible = True
    Label1.Caption = project
    Else
    If i = 2 Then
    Label2.Visible = True
    Label2.Caption = project
    Else
    If i = 3 Then
    Label3.Visible = True
    Label3.Caption = project
    Else
    If i = 4 Then
    Label4.Visible = True
    Label4.Caption = project
    Else
    If i = 5 Then
    Label5.Visible = True
    Label5.Caption = project
    Else
    If i = 6 Then
    Label6.Visible = True
    Label6.Caption = project
    Else
    If i = 7 Then
    Label7.Visible = True
    Label7.Caption = project
    Else
    If i = 8 Then
    Label8.Visible = True
    Label8.Caption = project
    Else
    If i = 9 Then
    Label9.Visible = True
    Label9.Caption = project
    Else
    If i = 10 Then
    Label10.Visible = True
    Label10.Caption = project
    End If
    i = i + 1
    Next varItem
     
  2. thusnani@gmail.com

    thusnani@gmail.com
    Expand Collapse
    Guest

    Sorry i answered my own question. I forgot to put each if statement as
    elseif instead of else if
     
  3. Jeff Boyce

    Jeff Boyce
    Expand Collapse
    Guest

    A couple observations...

    You appear to be using:

    Else
    If ...

    when I think you need

    ElseIf ...

    Otherwise, you have a bunch of If ... Else... statements without their
    respective EndIfs.

    You might consider using a Select Case statement in place of multiple
    If/Then statements.

    Regards

    Jeff Boyce
    Microsoft Office/Access MVP

    <thusnani@gmail.com> wrote in message
    news:1147972510.912821.134970@j55g2000cwa.googlegroups.com...
    > Im trying to put if loops in one for loop and im getting this error:
    > "Complie Error: Next without for"
    > Here is my code. What am i forgetting
    >
    > Dim i As Integer
    > i = 1
    >
    > For Each varItem In Me!ProjectList.ItemsSelected
    > project = Me!ProjectList.ItemData(varItem)
    > If i = 1 Then
    > Label1.Visible = True
    > Label1.Caption = project
    > Else
    > If i = 2 Then
    > Label2.Visible = True
    > Label2.Caption = project
    > Else
    > If i = 3 Then
    > Label3.Visible = True
    > Label3.Caption = project
    > Else
    > If i = 4 Then
    > Label4.Visible = True
    > Label4.Caption = project
    > Else
    > If i = 5 Then
    > Label5.Visible = True
    > Label5.Caption = project
    > Else
    > If i = 6 Then
    > Label6.Visible = True
    > Label6.Caption = project
    > Else
    > If i = 7 Then
    > Label7.Visible = True
    > Label7.Caption = project
    > Else
    > If i = 8 Then
    > Label8.Visible = True
    > Label8.Caption = project
    > Else
    > If i = 9 Then
    > Label9.Visible = True
    > Label9.Caption = project
    > Else
    > If i = 10 Then
    > Label10.Visible = True
    > Label10.Caption = project
    > End If
    > i = i + 1
    > Next varItem
    >
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page