ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Click to Add Image (https://www.excelbanter.com/excel-programming/389298-click-add-image.html)

mtm4300 via OfficeKB.com

Click to Add Image
 
I have a userform with 10 images that are all not visible when the userform
is loaded. I have a command button that will make each image visible each
time the button is clicked. For instance, if the button is clicked one time,
Image1 becomes Visible. If the button is clicked again, then Image2 becomes
visible, and so on. I cannot figure out how to do this. Can anyone help me?
Thank you.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1


Dave Peterson

Click to Add Image
 
I added 10 images to a userform.

I named them Image1, Image2, ..., Image10.

Then I used this code behind the userform:

Option Explicit
Dim pCtr As Long
Private Sub CommandButton1_Click()
Dim iCtr As Long

If pCtr = 10 Then
pCtr = 1
Else
pCtr = pCtr + 1
End If

For iCtr = 1 To 10
Me.Controls("Image" & iCtr).Visible = CBool(iCtr = pCtr)
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("image" & iCtr).Visible = False
Next iCtr
pCtr = 10 'next will be 1
End Sub



"mtm4300 via OfficeKB.com" wrote:

I have a userform with 10 images that are all not visible when the userform
is loaded. I have a command button that will make each image visible each
time the button is clicked. For instance, if the button is clicked one time,
Image1 becomes Visible. If the button is clicked again, then Image2 becomes
visible, and so on. I cannot figure out how to do this. Can anyone help me?
Thank you.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1


--

Dave Peterson

mtm4300 via OfficeKB.com

Click to Add Image
 
This works great.
Is there any way when another Image is added, that the previous Image is kept
visible. For instance, If the button is clicked 2 Times, Image1 (which became
visible after 1 click) and Image2 are both visible.

Dave Peterson wrote:
I added 10 images to a userform.

I named them Image1, Image2, ..., Image10.

Then I used this code behind the userform:

Option Explicit
Dim pCtr As Long
Private Sub CommandButton1_Click()
Dim iCtr As Long

If pCtr = 10 Then
pCtr = 1
Else
pCtr = pCtr + 1
End If

For iCtr = 1 To 10
Me.Controls("Image" & iCtr).Visible = CBool(iCtr = pCtr)
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("image" & iCtr).Visible = False
Next iCtr
pCtr = 10 'next will be 1
End Sub

I have a userform with 10 images that are all not visible when the userform
is loaded. I have a command button that will make each image visible each

[quoted text clipped - 6 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1


Dave Peterson

Click to Add Image
 
And after 10 clicks nothing changes??????

Option Explicit
Dim pCtr As Long
Private Sub CommandButton1_Click()
Dim iCtr As Long

If pCtr = 10 Then
'do nothing
Else
pCtr = pCtr + 1
End If

For iCtr = 1 To 10
Me.Controls("Image" & iCtr).Visible = CBool(iCtr <= pCtr)
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("image" & iCtr).Visible = False
Next iCtr
pCtr = 0 'next will be 1
End Sub


"mtm4300 via OfficeKB.com" wrote:

This works great.
Is there any way when another Image is added, that the previous Image is kept
visible. For instance, If the button is clicked 2 Times, Image1 (which became
visible after 1 click) and Image2 are both visible.

Dave Peterson wrote:
I added 10 images to a userform.

I named them Image1, Image2, ..., Image10.

Then I used this code behind the userform:

Option Explicit
Dim pCtr As Long
Private Sub CommandButton1_Click()
Dim iCtr As Long

If pCtr = 10 Then
pCtr = 1
Else
pCtr = pCtr + 1
End If

For iCtr = 1 To 10
Me.Controls("Image" & iCtr).Visible = CBool(iCtr = pCtr)
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("image" & iCtr).Visible = False
Next iCtr
pCtr = 10 'next will be 1
End Sub

I have a userform with 10 images that are all not visible when the userform
is loaded. I have a command button that will make each image visible each

[quoted text clipped - 6 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1


--

Dave Peterson


All times are GMT +1. The time now is 12:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com