|
-
Apr 11th, 2005, 10:26 AM
#1
Thread Starter
Frenzied Member
Simple Data Calculation
I am trying to create a simple credit calculator that calculates the tax percentage, then it takes that percentage and multiplies it by the different shipping tiers we have, but for some reason, i cant get the values, to turn into actual money values, I did the Ccur but it dosent work
VB Code:
Option Explicit
Dim num1 As Double
Dim num2 As Double
Dim num3 As Double
Dim num4 As Double
Dim num5 As Double
Dim answer1 As Double
Private Sub Command1_Click()
num1 = Text1.Text
num2 = Text2.Text
num3 = Text3.Text
num4 = Text4.Text
answer1 = (num2 / num1)
Text3.Text = answer1
Text4.Text = (answer1 * num1) + (num1)
Text5.Text = CCur(Text5.Text * answer1)
Text6.Text = CCur(Text6.Text * answer1)
Text7.Text = CCur(Text7.Text * answer1)
Text8.Text = CCur(Text8.Text * answer1)
Text9.Text = CCur(Text9.Text * answer1)
Text10.Text = CCur(Text10.Text * answer1)
Text11.Text = CCur(Text11.Text * answer1)
Text12.Text = CCur(Text12.Text * answer1)
Text13.Text = CCur(Text13.Text * answer1)
Text14.Text = CCur(Text14.Text * answer1)
Text15.Text = CCur(Text15.Text * answer1)
Text16.Text = CCur(Text16.Text * answer1)
Text17.Text = CCur(Text17.Text * answer1)
Text18.Text = CCur(Text18.Text * answer1)
Text19.Text = CCur(Text19.Text * answer1)
End Sub
'Clear the Values
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = "0"
Text4.Text = "0"
Form_Load
End Sub
Public Sub Form_Load()
' Loading the values into the sections
Text5.Text = CCur(4.95)
Text6.Text = CCur(5.95)
Text7.Text = CCur(8.95)
Text8.Text = CCur(10.95)
Text9.Text = CCur(12.95)
Text10.Text = CCur(9.95)
Text11.Text = CCur(11.95)
Text12.Text = CCur(13.95)
Text13.Text = CCur(15.95)
Text14.Text = CCur(17.95)
Text15.Text = CCur(24.95)
Text16.Text = CCur(26.95)
Text17.Text = CCur(28.95)
Text18.Text = CCur(30.95)
Text19.Text = CCur(32.95)
End Sub
-
Apr 11th, 2005, 03:19 PM
#2
Lively Member
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
-
Apr 11th, 2005, 03:53 PM
#3
Thread Starter
Frenzied Member
Re: Simple Data Calculation
I know they are not set, i dont set them until i hit the button.
Anyone else please review!
-
Apr 11th, 2005, 04:12 PM
#4
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.
-
Apr 12th, 2005, 02:01 PM
#5
Thread Starter
Frenzied Member
-
Apr 12th, 2005, 04:37 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|