Bbased the image.
i have image1 with + icon and image2 have with - icon
between the image have a label named lzoom
i need to show in label the value when i click on the 2 imsges
note:
the max range of zoom is from 15 to 21
ZOOM WITH + -
-
- PlatinumLounger
- Posts: 4355
- Joined: 26 Apr 2010, 17:36
ZOOM WITH + -
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78478
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: ZOOM WITH + -
You could declare a variable of type Long at the top of the form's module.
Set its value to 15 (or 18 or 21, whichever you prefer) when the form is loaded, and set the Caption of the label to the value of the variable.
When the + button is clicked, check whether the variable is < 21. If so, increase it by 1, and set the Caption of the label to the new value.
When the - button is clicked, check whether the variable is > 15. If so, decrease it by 1, and set the Caption of the label to the new value.
Set its value to 15 (or 18 or 21, whichever you prefer) when the form is loaded, and set the Caption of the label to the value of the variable.
When the + button is clicked, check whether the variable is < 21. If so, increase it by 1, and set the Caption of the label to the new value.
When the - button is clicked, check whether the variable is > 15. If so, decrease it by 1, and set the Caption of the label to the new value.
Best wishes,
Hans
Hans
-
- Microsoft MVP
- Posts: 1318
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: ZOOM WITH + -
If you're working in a userform in Excel or Word, use a Textbox control instead of a label, and use a SpinButton control instead of the two images.
When the user clicks the upward pointing arrow, the SpinButton1_SpinUp code runs. When they click the downward pointing arrow, the SpinButton1_SpinDown code runs. The If statements in those codes serve to limit the range of numbers that can appear in the textbox.
In a userform like this, with the default names for the controls, the code should be something like this:Code: Select all
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub SpinButton1_SpinDown()
If TextBox1.Value > 15 Then
TextBox1.Value = TextBox1.Value - 1
End If
End Sub
Private Sub SpinButton1_SpinUp()
If TextBox1.Value < 21 Then
TextBox1.Value = TextBox1.Value + 1
End If
End Sub
Private Sub UserForm_Initialize()
TextBox1.Value = 18
End Sub
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78478
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4355
- Joined: 26 Apr 2010, 17:36
Re: ZOOM WITH + -
TKS.HansV wrote: ↑10 Jan 2023, 21:25You could declare a variable of type Long at the top of the form's module.
Set its value to 15 (or 18 or 21, whichever you prefer) when the form is loaded, and set the Caption of the label to the value of the variable.
When the + button is clicked, check whether the variable is < 21. If so, increase it by 1, and set the Caption of the label to the new value.
When the - button is clicked, check whether the variable is > 15. If so, decrease it by 1, and set the Caption of the label to the new value.
Can you post a code for solution.instead to use image, use a labels name L_PIU and L_MENO
-
- Administrator
- Posts: 78478
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: ZOOM WITH + -
Set the caption of LZOOM to (for example) 15.
Code: Select all
Private Sub L_MENO_Click()
Dim V As Long
V = Val(Me.LZOOM.Caption)
If V > 15 Then
Me.LZOOM.Caption = V - 1
End If
End Sub
Private Sub L_PIU_Click()
Dim V As Long
V = Val(Me.LZOOM.Caption)
If V < 21 Then
Me.LZOOM.Caption = V + 1
End If
End Sub
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4355
- Joined: 26 Apr 2010, 17:36
Re: ZOOM WITH + -
Great!!!!HansV wrote: ↑11 Jan 2023, 10:01Set the caption of LZOOM to (for example) 15.
Code: Select all
Private Sub L_MENO_Click() Dim V As Long V = Val(Me.LZOOM.Caption) If V > 15 Then Me.LZOOM.Caption = V - 1 End If End Sub Private Sub L_PIU_Click() Dim V As Long V = Val(Me.LZOOM.Caption) If V < 21 Then Me.LZOOM.Caption = V + 1 End If End Sub
Tks Bro
-
- PlatinumLounger
- Posts: 4355
- Joined: 26 Apr 2010, 17:36
Re: ZOOM WITH + -
DUBT...HansV wrote: ↑11 Jan 2023, 10:01Set the caption of LZOOM to (for example) 15.
Code: Select all
Private Sub L_MENO_Click() Dim V As Long V = Val(Me.LZOOM.Caption) If V > 15 Then Me.LZOOM.Caption = V - 1 End If End Sub Private Sub L_PIU_Click() Dim V As Long V = Val(Me.LZOOM.Caption) If V < 21 Then Me.LZOOM.Caption = V + 1 End If End Sub
i can declare as public in a module the var V?
In effect i need to use for other code.
-
- Administrator
- Posts: 78478
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: ZOOM WITH + -
Then use
Code: Select all
Public V As Long
Private Sub Form_Load()
V = Value(Me.LZOOM.Caption)
End Sub
Private Sub L_MENO_Click()
V = Val(Me.LZOOM.Caption)
If V > 15 Then
V = V - 1
Me.LZOOM.Caption = V
End If
End Sub
Private Sub L_PIU_Click()
V = Val(Me.LZOOM.Caption)
If V < 21 Then
V = V + 1
Me.LZOOM.Caption = V
End If
End Sub
Best wishes,
Hans
Hans