Re: Simple Data Calculation
Hi,
Just alter your code to this
num1 = CCur(Text1.Text)
num2 = CCur(Text2.Text)
'num3 = CCur(Text3.Text) ' These are not used yet and have no value
'num4 = CCur(Text4.Text)
Fishy
Re: Simple Data Calculation
I know they are not set, i dont set them until i hit the button. :thumb:
Anyone else please review!
Re: Simple Data Calculation
Ok, a few things.
I created a Sub to Load the default values, as you were attempting to call the Form_Load event.
Possibly use the FormatCurrency() function as opposed to CCur().
I removed some unwanted Variables (if you arn't using them elsewhere) as you can
directly use the TextBox value - no need to take an intermediate step and place them into a Variable.
VB Code:
Option Explicit
Dim num3 As Double
Dim num4 As Double
Dim num5 As Double
Dim answer1 As Double
Private Sub Form_Load()
Call Load_Default_Values
End Sub
Private Sub Command1_Click()
num3 = Text3.Text
num4 = Text4.Text
answer1 = (Text2.Text / Text1.Text)
Text3.Text = answer1
Text4.Text = (answer1 * Text1.Text) + (Text1.Text)
Text5.Text = FormatCurrency(Text5.Text * answer1)
Text6.Text = FormatCurrency(Text6.Text * answer1)
Text7.Text = FormatCurrency(Text7.Text * answer1)
Text8.Text = FormatCurrency(Text8.Text * answer1)
Text9.Text = FormatCurrency(Text9.Text * answer1)
Text10.Text = FormatCurrency(Text10.Text * answer1)
Text11.Text = FormatCurrency(Text11.Text * answer1)
Text12.Text = FormatCurrency(Text12.Text * answer1)
Text13.Text = FormatCurrency(Text13.Text * answer1)
Text14.Text = FormatCurrency(Text14.Text * answer1)
Text15.Text = FormatCurrency(Text15.Text * answer1)
Text16.Text = FormatCurrency(Text16.Text * answer1)
Text17.Text = FormatCurrency(Text17.Text * answer1)
Text18.Text = FormatCurrency(Text18.Text * answer1)
Text19.Text = FormatCurrency(Text19.Text * answer1)
End Sub
'Clear the Values
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = "0"
Text4.Text = "0"
Call Load_Default_Values
End Sub
Private Sub Load_Default_Values()
' Loading the values into the sections
Text5.Text = FormatCurrency(4.95)
Text6.Text = FormatCurrency(5.95)
Text7.Text = FormatCurrency(8.95)
Text8.Text = FormatCurrency(10.95)
Text9.Text = FormatCurrency(12.95)
Text10.Text = FormatCurrency(9.95)
Text11.Text = FormatCurrency(11.95)
Text12.Text = FormatCurrency(13.95)
Text13.Text = FormatCurrency(15.95)
Text14.Text = FormatCurrency(17.95)
Text15.Text = FormatCurrency(24.95)
Text16.Text = FormatCurrency(26.95)
Text17.Text = FormatCurrency(28.95)
Text18.Text = FormatCurrency(30.95)
Text19.Text = FormatCurrency(32.95)
End Sub
There are other areas to fix, but wanted to ensure it was on track first :)
Bruce.
Re: Simple Data Calculation
Hey I have an uncle named Bruce Fox....
lol
Hey worked like a charm :)
THANKS!!!!!!!!!! :wave: :afrog: :wave: :cool: :) :rolleyes: :eek2: :p :bigyello: ;) :afrog:
Re: Simple Data Calculation
No probs Cous' :)
Suggestion: To avoid errors when empty string ("") or an alpha character is entered
in either Text1 or Text2, validate them at the start of Command1_Click using:
VB Code:
Option Explicit
Private Sub Command1_Click()
If Not (IsNumeric(Text1.Text) And IsNumeric(Text2.Text)) Then
MsgBox "Numbers only please.", vbOKOnly + vbInformation, "Data Entry"
Exit Sub
End If
'Your Code Here........
'
'
'
End Sub
Also, could you please edit your first post and select the green 'tick' to indicate that this tread is resolved.
Cheers,
Bruce.