2016-06-07 102 views
0

如何讓一個標籤接受來自多個按鈕的數字,例如,如果我點擊一個帶有「1」的按鈕,該標籤顯示我1,但如果我點擊另一個按鈕,如「2」取代了1對2 ...它應該告訴我「12」不能代替數字...在vba中構建一個簡單的計算器

這是我,將顯示結果的標籤代碼,我按下按鈕

Dim intNum1 As Integer 
Dim intNum2 As Integer 
Dim intNum3 As Integer 
Dim intNum4 As Integer 
Dim intNum5 As Integer 
Dim IntNum6 As Integer 
Dim IntNum7 As Integer 
Dim IntNum8 As Integer 
Dim IntNum9 As Integer 





Me.txtEntry_Result.Text = intNum1 & intNum2 
+0

你需要所有這些整數?單擊按鈕時,您可以直接更新標籤的標題。 –

+0

我正在嘗試每個整數對應於標籤中的空格的方法 –

回答

0

如果txtEntry_Result是標籤

那麼您應該使用.Caption屬性該對象。

像這樣Me.txtEntry_Result.Caption = intNum1 & Me.txtEntry_Result.Caption它會將Me.txtEntry_Result.Caption與新號碼連接並將其重新分配給它。

How can I make a label accepts multiple numbers from buttons, example if I hit a button that has "1" the label shows me 1, but if I hit another button like "2" the label replaces the 1 for the 2...it should show me "12" not replace the numbers..

可以爲所有其他按鈕,你可以不喜歡它那像這樣做,例如爲Button1

Private Sub CommandButton1_Click() 
    Me.txtEntry_Result.Caption = Me.txtEntry_Result.Caption & Me.CommandButton1.Caption 
End Sub 

同樣。

+0

在2013年訪問vba中的編程不應該是一個問題......但是它返回我編譯錯誤:找不到方法或數據成員:/在buttons_Click –

+0

Ohh對不起,我不知道這是訪問你應該添加'access'標籤。無論如何,該錯誤意味着按鈕名稱是錯誤的,所以改變代碼,但邏輯是正確的。 – newguy

+0

是的,它工作!但是我使用txtEntry_Result.DefaultValue而不是txtEntry_Result.Caption –