2014-05-01 77 views
-3

我對這個新的等,我已經擺脫了,如果你可以使一個按鈕等於一次點擊一個值。下面有什麼Iv'e得到了
的一個實例:具有價值的Visual Basic按鈕

公共類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 

答: 私人小組Btn10p_Click(BYVAL發件人爲System.Object的,BYVALË作爲System.EventArgs)把手Btn10p .Click AmountTextBox.Text = AmountTextBox.Text + 0.1 End Sub

+1

一些技巧。把你的代碼放在一個代碼塊中(突出顯示它並按下cntl + k)。此外,這是vb.net或vba?他們是不同的語言。請編輯您的問題,以便您可以從正確的人員處獲得關注。 – RubberDuck

+2

或抵制旨在幫助您回滾的編輯。 :} – J0e3gan

+0

謝謝,編輯。 – user3498334

回答

1

您是指按鈕上的文字?或者你是否只想讓多個點擊事件執行相同的增量例程?如果是後者則

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 

如果不是你以後,那麼你需要正是你在更好的細節想要什麼解釋。