Results 1 to 8 of 8

Thread: [RESOLVED] Problem with multiple if statements.

  1. #1

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Resolved [RESOLVED] Problem with multiple if statements.

    Hello,

    Bellow is some code from my program. It scrolls through images listed in a listbox.

    My problem is this:

    Here is a portion of my code:

    VB Code:
    1. If frmMain.List1.ListIndex = frmMain.List1.NewIndex Then
    2.  
    3.  
    4. iResponse% = MsgBox("Reached End of List." & vbCrLf & "" & vbCrLf & "Start from top of list?", vbQuestion + vbYesNo, "ClipBoard Monitor")
    5.  If iResponse% = vbYes Then
    6. frmMain.List1.ListIndex = frmMain.List1.TabIndex
    7.  
    8.  
    9.      Dim strImagePath As String
    10.  
    11.      strImagePath = ("C:\Documents and Settings\All Users\Application Data\Clipboard Data\Pictures\" & frmMain.List1.List(frmMain.List1.ListIndex))
    12.  
    13.     Form1.picShowImage.Picture = LoadPicture((strImagePath), , , 0, 0)
    14.     Form1.picShowImage.Picture = LoadPicture(strImagePath)
    15.    
    16.     Form1.picShowImage.Move 0, 0
    17.     Form1.picShowImage.Visible = True
    18.     OnImageLoad
    19.    
    20.  
    21. Else
    22.  
    23. Exit Sub
    24.  
    25. 'This portion does not work because it doesn't allow 2 [B]if[/B]'s
    26. Else
    27. frmMain.List1.ListIndex = frmMain.List1.ListIndex +1

    Now as you see there are 2 "IF" statements in this code. My question is how do I put 2 "Else" functions in this code?

    If I put 2 Else I get the error Else without IF.

    Thank you for any help!
    P.S. If you need more info just let me know!
    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Problem with multiple if statements.

    VB Code:
    1. If frmMain.List1.ListIndex = frmMain.List1.NewIndex Then
    2.  
    3.  
    4. iResponse% = MsgBox("Reached End of List." & vbCrLf & "" & vbCrLf & "Start from top of list?", vbQuestion + vbYesNo, "ClipBoard Monitor")
    5.  If iResponse% = vbYes Then
    6. frmMain.List1.ListIndex = frmMain.List1.TabIndex
    7.  
    8.  
    9.      Dim strImagePath As String
    10.  
    11.      strImagePath = ("C:\Documents and Settings\All Users\Application Data\Clipboard Data\Pictures\" & frmMain.List1.List(frmMain.List1.ListIndex))
    12.  
    13.     Form1.picShowImage.Picture = LoadPicture((strImagePath), , , 0, 0)
    14.     Form1.picShowImage.Picture = LoadPicture(strImagePath)
    15.    
    16.     Form1.picShowImage.Move 0, 0
    17.     Form1.picShowImage.Visible = True
    18.     OnImageLoad
    19.    
    20.  
    21. Else
    22.  
    23. Exit Sub
    24.  
    25. 'This portion does not work because it doesn't allow 2 if's
    26. Else
    27. frmMain.List1.ListIndex = frmMain.List1.ListIndex +1
    28. End if
    29. End if

    Wouldnt that just work?

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Problem with multiple if statements.

    You can only put in another Else when another If statement is gonna be in there. The last Else doesn't need one, while the others do. Try this:

    VB Code:
    1. If frmMain.List1.ListIndex = frmMain.List1.NewIndex Then
    2.  
    3.  
    4. iResponse% = MsgBox("Reached End of List." & vbCrLf & "" & vbCrLf & "Start from top of list?", vbQuestion + vbYesNo, "ClipBoard Monitor")
    5.  If iResponse% = vbYes Then
    6. frmMain.List1.ListIndex = frmMain.List1.TabIndex
    7.  
    8.  
    9.      Dim strImagePath As String
    10.  
    11.      strImagePath = ("C:\Documents and Settings\All Users\Application Data\Clipboard Data\Pictures\" & frmMain.List1.List(frmMain.List1.ListIndex))
    12.  
    13.     Form1.picShowImage.Picture = LoadPicture((strImagePath), , , 0, 0)
    14.     Form1.picShowImage.Picture = LoadPicture(strImagePath)
    15.    
    16.     Form1.picShowImage.Move 0, 0
    17.     Form1.picShowImage.Visible = True
    18.     OnImageLoad
    19.    
    20.  
    21. ElseIf  iResponse% = vbNo Then
    22.  
    23.      Exit Sub
    24.  
    25. Else
    26.  
    27.      frmMain.List1.ListIndex = frmMain.List1.ListIndex +1
    28.  
    29. End If

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Problem with multiple if statements.

    Try vbYesNoCancel since the last Else will never be true

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problem with multiple if statements.

    This should work.
    VB Code:
    1. Dim strImagePath As String
    2. If frmMain.List1.ListIndex = frmMain.List1.NewIndex Then
    3.     iResponse% = MsgBox("Reached End of List." & vbCrLf & "" & vbCrLf & "Start from top of list?", vbQuestion + vbYesNo, "ClipBoard Monitor")
    4.         If iResponse% = vbYes Then
    5.             frmMain.List1.ListIndex = frmMain.List1.TabIndex
    6.             strImagePath = ("C:\Documents and Settings\All Users\Application Data\Clipboard Data\Pictures\" & frmMain.List1.List(frmMain.List1.ListIndex))
    7.             Form1.picShowImage.Picture = LoadPicture((strImagePath), , , 0, 0)
    8.             Form1.picShowImage.Picture = LoadPicture(strImagePath)
    9.             Form1.picShowImage.Move 0, 0
    10.             Form1.picShowImage.Visible = True
    11.             OnImageLoad
    12.         Else ' if anything but Yes then boogie
    13.           Exit Sub
    14.         End If
    15. Else 'we have not reached the end yet, so keep going
    16.     frmMain.List1.ListIndex = frmMain.List1.ListIndex + 1
    17. End If
    Note: I moved your Dim statement to the top of the routine.

  6. #6

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Re: Problem with multiple if statements.

    HACK THATS GREAT!

    So all I had to do was add an END IF?

    Fabulous!

    Thanks man!
    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problem with multiple if statements.

    Quote Originally Posted by stilekid007
    HACK THATS GREAT!

    So all I had to do was add an END IF?

    Fabulous!

    Thanks man!
    Stilekid007
    Yep. For every If there must be a cooresponding End If, for every For a cooresponding Next and so forth. You can nest those suckers all day long. There are three important things to remember when nesting:

    1. INDENT
    2. INDENT
    3. INDENT


  8. #8

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Re: Problem with multiple if statements.

    Oh wow! Now that is very cool! THATS JUST JAZZY AWSOME!

    Alright well - you got rated BIG! haha! You rock buddy!

    Thank you all you others for your help as well!
    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

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