|
-
Jul 20th, 2005, 12:02 PM
#1
Thread Starter
Hyperactive Member
[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:
If frmMain.List1.ListIndex = frmMain.List1.NewIndex Then
iResponse% = MsgBox("Reached End of List." & vbCrLf & "" & vbCrLf & "Start from top of list?", vbQuestion + vbYesNo, "ClipBoard Monitor")
If iResponse% = vbYes Then
frmMain.List1.ListIndex = frmMain.List1.TabIndex
Dim strImagePath As String
strImagePath = ("C:\Documents and Settings\All Users\Application Data\Clipboard Data\Pictures\" & frmMain.List1.List(frmMain.List1.ListIndex))
Form1.picShowImage.Picture = LoadPicture((strImagePath), , , 0, 0)
Form1.picShowImage.Picture = LoadPicture(strImagePath)
Form1.picShowImage.Move 0, 0
Form1.picShowImage.Visible = True
OnImageLoad
Else
Exit Sub
'This portion does not work because it doesn't allow 2 [B]if[/B]'s
Else
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
 Originally Posted by stilekid007
-
Jul 20th, 2005, 12:06 PM
#2
Re: Problem with multiple if statements.
VB Code:
If frmMain.List1.ListIndex = frmMain.List1.NewIndex Then
iResponse% = MsgBox("Reached End of List." & vbCrLf & "" & vbCrLf & "Start from top of list?", vbQuestion + vbYesNo, "ClipBoard Monitor")
If iResponse% = vbYes Then
frmMain.List1.ListIndex = frmMain.List1.TabIndex
Dim strImagePath As String
strImagePath = ("C:\Documents and Settings\All Users\Application Data\Clipboard Data\Pictures\" & frmMain.List1.List(frmMain.List1.ListIndex))
Form1.picShowImage.Picture = LoadPicture((strImagePath), , , 0, 0)
Form1.picShowImage.Picture = LoadPicture(strImagePath)
Form1.picShowImage.Move 0, 0
Form1.picShowImage.Visible = True
OnImageLoad
Else
Exit Sub
'This portion does not work because it doesn't allow 2 if's
Else
frmMain.List1.ListIndex = frmMain.List1.ListIndex +1
End if
End if
Wouldnt that just work?
-
Jul 20th, 2005, 12:06 PM
#3
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:
If frmMain.List1.ListIndex = frmMain.List1.NewIndex Then
iResponse% = MsgBox("Reached End of List." & vbCrLf & "" & vbCrLf & "Start from top of list?", vbQuestion + vbYesNo, "ClipBoard Monitor")
If iResponse% = vbYes Then
frmMain.List1.ListIndex = frmMain.List1.TabIndex
Dim strImagePath As String
strImagePath = ("C:\Documents and Settings\All Users\Application Data\Clipboard Data\Pictures\" & frmMain.List1.List(frmMain.List1.ListIndex))
Form1.picShowImage.Picture = LoadPicture((strImagePath), , , 0, 0)
Form1.picShowImage.Picture = LoadPicture(strImagePath)
Form1.picShowImage.Move 0, 0
Form1.picShowImage.Visible = True
OnImageLoad
ElseIf iResponse% = vbNo Then
Exit Sub
Else
frmMain.List1.ListIndex = frmMain.List1.ListIndex +1
End If
-
Jul 20th, 2005, 12:08 PM
#4
Re: Problem with multiple if statements.
Try vbYesNoCancel since the last Else will never be true
-
Jul 20th, 2005, 12:20 PM
#5
Re: Problem with multiple if statements.
This should work.
VB Code:
Dim strImagePath As String
If frmMain.List1.ListIndex = frmMain.List1.NewIndex Then
iResponse% = MsgBox("Reached End of List." & vbCrLf & "" & vbCrLf & "Start from top of list?", vbQuestion + vbYesNo, "ClipBoard Monitor")
If iResponse% = vbYes Then
frmMain.List1.ListIndex = frmMain.List1.TabIndex
strImagePath = ("C:\Documents and Settings\All Users\Application Data\Clipboard Data\Pictures\" & frmMain.List1.List(frmMain.List1.ListIndex))
Form1.picShowImage.Picture = LoadPicture((strImagePath), , , 0, 0)
Form1.picShowImage.Picture = LoadPicture(strImagePath)
Form1.picShowImage.Move 0, 0
Form1.picShowImage.Visible = True
OnImageLoad
Else ' if anything but Yes then boogie
Exit Sub
End If
Else 'we have not reached the end yet, so keep going
frmMain.List1.ListIndex = frmMain.List1.ListIndex + 1
End If
Note: I moved your Dim statement to the top of the routine.
-
Jul 20th, 2005, 12:24 PM
#6
Thread Starter
Hyperactive Member
Re: Problem with multiple if statements.
HACK THATS GREAT!
So all I had to do was add an END IF?
Fabulous!
Thanks man!
Stilekid007
 Originally Posted by stilekid007
-
Jul 20th, 2005, 12:28 PM
#7
Re: Problem with multiple if statements.
 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
-
Jul 20th, 2005, 12:31 PM
#8
Thread Starter
Hyperactive Member
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
 Originally Posted by stilekid007
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|