Visual Basic Button with a Value [closed]

2019-09-21 18:47发布

Im new to this etc, and I was woundering if you can make a button equal a value once clicked. Heres what Iv'e got for an exmple:

Public Class Form1

    Private Sub BuyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BuyButton.Click

        Dim MoneyBtn1 As String
        Btn10p.PerformClick = MoneyBtn1
        MoneyBtn1 = 0.1 + AmountTextBox.Text

        Dim Cost, Amount, Change As Decimal
        Dim Pennies, Pounds As Integer
        Dim msg As String

        Cost = Decimal.Parse(CostTextBox.Text)
        Amount = Decimal.Parse(AmountTextBox.Text)
        Change = (Amount - Cost)

        If Change < 0 Then

            msg = "You don't have enough Money"

        Else

            Pounds = Math.Floor(Change)
            Pennies = (Change - Pounds) * 100

            msg = "Your change is: " & Change.ToString("##.00") & Environment.NewLine
            msg += "Pounds: " & Pounds & vbNewLine
            msg += "Pennies: " & Pennies & vbNewLine

        End If
        ChangeLabel.Text = msg
    End Sub
End Class

Answer I have used: Private Sub Btn10p_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn10p.Click AmountTextBox.Text = AmountTextBox.Text + 0.1 End Sub

1条回答
女痞
2楼-- · 2019-09-21 18:49

Do you mean the text on a button? Or do you simply want more than one click event to perform the same increment routine? If the latter then

Private Sub BuyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BuyButton.Click

    IncrementValue()

    --Other stuff.

End Sub

Private Sub SomeOtherButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SomeOtherButton.Click
    IncrementValue()
End Sub

Private Sub IncrementValue()
    TextBox.Text = (Decimal.Parse(TextBox.Text) + 0.1).ToString
End Sub

If that's not what you're after then you need to explain exactly what you want in better detail.

查看更多
登录 后发表回答