-
Apr 4th, 2008, 03:19 AM
#1
Thread Starter
Lively Member
[RESOLVED] IF-Then Problem.
I have a button that changes a picture in a picture box, and I tried using If Then Statements to change it like so..
Code:
If imgtour.Tag = "pic01" Then
Set imgtour.Picture = LoadPicture(App.Path & "smallpics\pic02.jpg")
imgtour.Tag = "pic02"
End If
The problem is that I have 20+ If Then statements in this button, when I press the button, it cycles through every picture to the end. How can I make it "pause" at each picture until I click it again?
My knowledge of VB is pretty limited, so the most basic answers would be most appreciated 
Thanks in advance,
Shawn
-
Apr 4th, 2008, 03:23 AM
#2
Re: IF-Then Problem.
try using select case imgtour.tag
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 4th, 2008, 03:28 AM
#3
Re: IF-Then Problem.
?? What are you trying to do?
-a- Show a different picture on each click of the command button OR
-b- Show a "Slide Show" of ALL pictures when clicking on the button??
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Apr 4th, 2008, 03:28 AM
#4
Thread Starter
Lively Member
Re: IF-Then Problem.
Could you elaborate on Select Case please?
What is it?
How should it be used?
Opus: I am having it show a different picture each time I click the button.
-
Apr 4th, 2008, 03:34 AM
#5
Re: IF-Then Problem.
I am not sure if slelect case would be different then an IF-Then.
It totally depends on your code in the button click event.
Can I have a look at your button click code?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
MyGear:
OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011
-
Apr 4th, 2008, 03:38 AM
#6
Frenzied Member
Re: IF-Then Problem.
You can put the pictureboxes and tags in arrays and then use one Long to cycle the index.
vb Code:
'make a control array of pictureboxes called imgtor Dim tag() As String 'make as much tags as there are image boxes 'put an appropriate string in each tag If imgtour(index).Tag = Tag(index) Then '... End If index = index + 1 If index > UBound(imgtour) Then index = 0
-
Apr 4th, 2008, 03:40 AM
#7
Re: IF-Then Problem.
I assume you have named all your pictures like: "smallpics\pic01.jpg", the number starts at 01 and ends at max at 99.
in the commandbutton_click event routine
Code:
Dim ActualPicture as Integer
ActualPicture=CInt(Right(imgtour.Tag;2))
ActualPicture=ActualPicture+1
'You have to set the correct maximum-number of pictures in here!
If ActualPicture>99 then
ActualPicture=1
End If
Set imgtour.Picture = LoadPicture(App.Path & "smallpics\pic" &CStr(ActualPicture) & ".jpg")
imgtour.Tag = "pic" & CStr(ActualPicture)
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Apr 4th, 2008, 03:48 AM
#8
Thread Starter
Lively Member
Re: IF-Then Problem.
I don't quite understand what arrays are.
I understand your code opus but I get a "compile error: Expected: list separator or )" for line
Code:
ActualPicture=CInt(Right(imgtour.Tag;2))
-
Apr 4th, 2008, 03:52 AM
#9
Re: IF-Then Problem.
Sorry that should have been
Code:
ActualPicture=CInt(Right(imgtour.Tag,2))
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Apr 4th, 2008, 04:06 AM
#10
Thread Starter
Lively Member
Re: IF-Then Problem.
When I compile it and press the button the first time, it works. when I press it the second time I get an error "Run-time error '13': Type mismatch"
I also changed the code a little and used it as a prev button. That button works about 20 times or so, then I get the same error.
Code:
Dim ActualPicture As Integer
ActualPicture = CInt(Right(imgtour.Tag, 2))
ActualPicture = ActualPicture - 1
'You have to set the correct maximum-number of pictures in here!
If ActualPicture < 1 Then
ActualPicture = 27
End If
Set imgtour.Picture = LoadPicture(App.Path & "smallpics\pic" & CStr(ActualPicture) & ".jpg")
imgtour.Tag = "pic" & CStr(ActualPicture)
-
Apr 4th, 2008, 04:17 AM
#11
Re: IF-Then Problem.
I think that you need to make sure that the leading zero is added when you get to single digits
Code:
Set imgtour.Picture = LoadPicture(App.Path & "smallpics\pic" & _
Left$("0", 2 - Len(CStr(ActualPicture))) & CStr(ActualPicture) & ".jpg")
-
Apr 4th, 2008, 04:18 AM
#12
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
MyGear:
OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011
-
Apr 4th, 2008, 04:20 AM
#13
Thread Starter
Lively Member
Re: IF-Then Problem.
To make the opus' code work, I actually removed the 0 in the image names and tag names so its just pic1, pic2, etc... now.
My 2 buttons are
Code:
Private Sub Next_Click()
Dim ActualPicture As Integer
ActualPicture = CInt(Right(imgtour.Tag, 2))
ActualPicture = ActualPicture + 1
'You have to set the correct maximum-number of pictures in here!
If ActualPicture > 27 Then
ActualPicture = 1
End If
Set imgtour.Picture = LoadPicture(App.Path & "smallpics\pic" & CStr(ActualPicture) & ".jpg")
imgtour.Tag = "pic" & CStr(ActualPicture)
End Sub
Private Sub Prev_Click()
Dim ActualPicture As Integer
ActualPicture = CInt(Right(imgtour.Tag, 2))
ActualPicture = ActualPicture - 1
'You have to set the correct maximum-number of pictures in here!
If ActualPicture < 1 Then
ActualPicture = 27
End If
Set imgtour.Picture = LoadPicture(App.Path & "smallpics\pic" & CStr(ActualPicture) & ".jpg")
imgtour.Tag = "pic" & CStr(ActualPicture)
End Sub
Last edited by russow kid; Apr 4th, 2008 at 04:23 AM.
-
Apr 4th, 2008, 04:26 AM
#14
Re: IF-Then Problem.
I suggest you put the leading zeros back otherwise you'll have to perform another test before
Code:
ActualPicture = CInt(Right$(imgtour.Tag, 2))
beacuse where you have a single digit the rightmost 2 characters wont be numeric (eg Right$ ("Pic1",2) will return "c1" and will give you a type mismatch
whereas Right$("Pic01",2) will return "01" which is numeric)
-
Apr 4th, 2008, 04:36 AM
#15
Thread Starter
Lively Member
Re: IF-Then Problem.
Thanks everyone for your help, it is now working after adding the leading 0 back in.
-
Apr 4th, 2008, 04:37 AM
#16
Re: IF-Then Problem.
just a suggestion. if your pictures are named as 01 to 27 then you will have to use this way to achieve what you want
Code:
Sub numberformat()
Dim ActualPicture As Integer
ActualPicture = 1
MsgBox CStr(Format(ActualPicture, "00"))
'Comment the above and uncomment the below
'Set imgtour.Picture = LoadPicture(App.Path & "smallpics\pic" & CStr(Format(ActualPicture, "00")) & ".jpg")
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
MyGear:
OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011
-
Apr 4th, 2008, 05:20 AM
#17
Fanatic Member
Re: [RESOLVED] IF-Then Problem.
 Originally Posted by russow kid
I have a button that changes a picture in a picture box, and I tried using If Then Statements to change it like so..
Code:
If imgtour.Tag = "pic01" Then
Set imgtour.Picture = LoadPicture(App.Path & "smallpics\pic02.jpg")
imgtour.Tag = "pic02"
End If
The problem is that I have 20+ If Then statements in this button, when I press the button, it cycles through every picture to the end. How can I make it "pause" at each picture until I click it again?
My knowledge of VB is pretty limited, so the most basic answers would be most appreciated
Thanks in advance,
Shawn
Code:
If imgtour.Tag = "pic01" Then
Set imgtour.Picture = LoadPicture(App.Path & "smallpics\pic02.jpg")
imgtour.Tag = "pic02"
Exit Sub
End If
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
|