how to change a label caption?

ALMUDENA PÉREZ DE LA VEGA 21 Reputation points
2020-12-28T16:52:56.09+00:00

I've been trying to make the caption of a label change from 0-10 when clicking in a button so each time that I click one of the buttons it adds 1 all the way to 10 and another that does the oposite (minus 1 until you reach 0)
I've tried this so far but it doesn't seem to work.

Private Sub FRosaU_Click()
For CuboRosa.Caption = Val(CuboRosa.Caption) + 1 To CuboRosa.Caption = 10
Next
End Sub
Private Sub FRosaD_Click()
For CuboRosa.Caption = Val(CuboRosa.Caption) - 1 To CuboRosa.Caption = 0
Next
End Sub

I've also tried this

Private Sub FVU_Click()
Dim nvu As Integer
For CuboVerde.Caption = Val(nvu) + 1 To Val(nvu) = 10
Next
End Sub

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,741 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,728 questions
0 comments No comments
{count} votes

Accepted answer
  1. HansV 966 Reputation points MVP
    2020-12-28T17:09:51.217+00:00

    Like this:

    Private Sub FRosaU_Click()
        If Val(VuboRosa.Caption) < 10 Then
            CuboRosa.Caption = Val(CuboRosa.Caption) + 1
        End If
    End Sub
    
    Private Sub FRosaD_Click()
        If Val(VuboRosa.Caption) > 0 Then
            CuboRosa.Caption = Val(CuboRosa.Caption) - 1
        End If
    End Sub
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Emi Zhang-MSFT 25,631 Reputation points Microsoft Vendor
    2020-12-29T08:05:51.153+00:00

    Hi @ALMUDENA PÉREZ DE LA VEGA ,
    Thanks for "Accept Answer" answer of HansV, I also suggest you upvote it. Other partners who read the forums with the same issue can get more information from the correct result.

    Thank you.
    :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.