ZOOM WITH + -

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

ZOOM WITH + -

Post by sal21 »

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
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78478
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ZOOM WITH + -

Post by HansV »

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.
Best wishes,
Hans

User avatar
Jay Freedman
Microsoft MVP
Posts: 1318
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: ZOOM WITH + -

Post by Jay Freedman »

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.
1.jpg
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
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.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78478
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ZOOM WITH + -

Post by HansV »

@Jay: Sal21 is working with VB6.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: ZOOM WITH + -

Post by sal21 »

HansV wrote:
10 Jan 2023, 21:25
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.
TKS.
Can you post a code for solution.instead to use image, use a labels name L_PIU and L_MENO

User avatar
HansV
Administrator
Posts: 78478
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ZOOM WITH + -

Post by HansV »

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

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: ZOOM WITH + -

Post by sal21 »

HansV wrote:
11 Jan 2023, 10:01
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
Great!!!!
Tks Bro

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: ZOOM WITH + -

Post by sal21 »

HansV wrote:
11 Jan 2023, 10:01
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
DUBT...
i can declare as public in a module the var V?

In effect i need to use for other code.

User avatar
HansV
Administrator
Posts: 78478
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ZOOM WITH + -

Post by HansV »

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