Help in making a simple calculator

cc.caroline15

Registered User.
Local time
Today, 05:06
Joined
Oct 23, 2014
Messages
23
Hi everyone I'm new to this forum and to VBA
I'm trying to make a simple calculator but I cant find the error on my code, any help is well appreciated!! I have been working on this for a couple of days and I'm getting frustrated. Please help me. I have attach my work so far !
Thank you
 

Attachments

There's quite a few things wrong with your code. See below:

Code:
Private Sub cmdAdd_Click()
ArithmeticProcess = "+"    [COLOR="Red"]This is not declared anywhere and it appears you're not using it[/COLOR]
'declare variable and assign data type
Dim txtNumber1 As Double    [COLOR="red"]'You declared this wrong, this needs to be the name of your variable[/COLOR]
Dim txtNumber2 As Double    [COLOR="red"]'You declared this wrong, this needs to be the name of your variable[/COLOR]
'assigned values to variables
dblNumber1 = Val(txtNumber1.Value)    [COLOR="red"]'You need this to be Me.MyTextBox[/COLOR]
dblNumber2 = Val(txtNumber2.Value)    [COLOR="red"]'You need this to be Me.MyTextBox[/COLOR]

Me.lblAnswer.Caption = dblNumber1 + dblNumber2
'Me.lblAnswer.Caption = dblNumber1 + dblNumber2
End Sub

So to clean it up you could use this:
Code:
Private Sub cmdAdd_Click()
'declare variable and assign data type
Dim dblNumber1 As Double
Dim dblNumber2 As Double

'assigned values to variables
dblNumber1 = Val(Me.txtNumber1.Value)
dblNumber2 = Val(Me.txtNumber2.Value)

Me.lblAnswer.Caption = dblNumber1 + dblNumber2
End Sub

You could also check out this thread that has already done what you're doing:
http://www.access-programmers.co.uk/forums/showthread.php?t=103573&highlight=calculator
 
Thank you very much! I though I was never going to get it to work!! Now. I can finish my calculator :) u were a big help my teacher is not the best at explaining and doesn't like to answer questions so I watched YouTube videos but I think they confused me more instead of helping lol
 

Users who are viewing this thread

Back
Top Bottom