BrianExcel
Well-known Member
- Joined
- Apr 21, 2010
- Messages
- 975
I am using the following code which when run displays an image from a set of three.
I am trying to better understand how to pass variables to simplify code, and so I am trying to re-write the above code using different scenarios. For example: I have three buttons, and one label. Each button is named uniquely such as btn1, btn2, btn3 with different captions. What I want to do is display the caption of the button selected in the label, but I can't figure out what I am doing wrong.
Could someone please help with the requested code above? Or at the very least try to explain (for Dummies) how to pass variables? I know this should be simple but I am struggling with it...
Code:
Sub optInkColor_Click()
ShowImageInk "imgInkColor"
End Sub
Sub optInkBW_Click()
ShowImageInk "imgInkBW"
End Sub
Sub optInkMix_Click()
ShowImageInk "imgInkMix"
End Sub
Sub ShowImageInk(whichOneink As String)
Dim objImage As Image
Dim cntl As Control
For Each cntl In Me.frmInk.Controls
If Left(cntl.Name, 3) = "img" Then
cntl.Visible = False
End If
Next cntl
Set objImage = Me.Controls(whichOneink)
objImage.Visible = True
Set objImage = Nothing
End Sub
I am trying to better understand how to pass variables to simplify code, and so I am trying to re-write the above code using different scenarios. For example: I have three buttons, and one label. Each button is named uniquely such as btn1, btn2, btn3 with different captions. What I want to do is display the caption of the button selected in the label, but I can't figure out what I am doing wrong.
Could someone please help with the requested code above? Or at the very least try to explain (for Dummies) how to pass variables? I know this should be simple but I am struggling with it...