Results 1 to 6 of 6

Thread: Simple Data Calculation

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    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:
    1. Option Explicit
    2. Dim num1 As Double
    3. Dim num2 As Double
    4. Dim num3 As Double
    5. Dim num4 As Double
    6. Dim num5 As Double
    7. Dim answer1 As Double
    8.  
    9. Private Sub Command1_Click()
    10. num1 = Text1.Text
    11. num2 = Text2.Text
    12. num3 = Text3.Text
    13. num4 = Text4.Text
    14.  
    15. answer1 = (num2 / num1)
    16. Text3.Text = answer1
    17. Text4.Text = (answer1 * num1) + (num1)
    18. Text5.Text = CCur(Text5.Text * answer1)
    19. Text6.Text = CCur(Text6.Text * answer1)
    20. Text7.Text = CCur(Text7.Text * answer1)
    21. Text8.Text = CCur(Text8.Text * answer1)
    22. Text9.Text = CCur(Text9.Text * answer1)
    23. Text10.Text = CCur(Text10.Text * answer1)
    24. Text11.Text = CCur(Text11.Text * answer1)
    25. Text12.Text = CCur(Text12.Text * answer1)
    26. Text13.Text = CCur(Text13.Text * answer1)
    27. Text14.Text = CCur(Text14.Text * answer1)
    28. Text15.Text = CCur(Text15.Text * answer1)
    29. Text16.Text = CCur(Text16.Text * answer1)
    30. Text17.Text = CCur(Text17.Text * answer1)
    31. Text18.Text = CCur(Text18.Text * answer1)
    32. Text19.Text = CCur(Text19.Text * answer1)
    33.  
    34. End Sub
    35.  
    36. 'Clear the Values
    37. Private Sub Command3_Click()
    38. Text1.Text = ""
    39. Text2.Text = ""
    40. Text3.Text = "0"
    41. Text4.Text = "0"
    42. Form_Load
    43. End Sub
    44.  
    45. Public Sub Form_Load()
    46. ' Loading the values into the sections
    47.     Text5.Text = CCur(4.95)
    48.     Text6.Text = CCur(5.95)
    49.     Text7.Text = CCur(8.95)
    50.     Text8.Text = CCur(10.95)
    51.     Text9.Text = CCur(12.95)
    52.     Text10.Text = CCur(9.95)
    53.     Text11.Text = CCur(11.95)
    54.     Text12.Text = CCur(13.95)
    55.     Text13.Text = CCur(15.95)
    56.     Text14.Text = CCur(17.95)
    57.     Text15.Text = CCur(24.95)
    58.     Text16.Text = CCur(26.95)
    59.     Text17.Text = CCur(28.95)
    60.     Text18.Text = CCur(30.95)
    61.     Text19.Text = CCur(32.95)
    62.  
    63. End Sub

  2. #2
    Lively Member
    Join Date
    Apr 2005
    Posts
    91

    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

  3. #3

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Data Calculation

    I know they are not set, i dont set them until i hit the button.

    Anyone else please review!

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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:
    1. Option Explicit
    2.  
    3. Dim num3 As Double
    4. Dim num4 As Double
    5. Dim num5 As Double
    6. Dim answer1 As Double
    7.  
    8. Private Sub Form_Load()
    9.  
    10.     Call Load_Default_Values
    11.    
    12. End Sub
    13.  
    14. Private Sub Command1_Click()
    15.  
    16.     num3 = Text3.Text
    17.     num4 = Text4.Text
    18.    
    19.     answer1 = (Text2.Text / Text1.Text)
    20.     Text3.Text = answer1
    21.     Text4.Text = (answer1 * Text1.Text) + (Text1.Text)
    22.     Text5.Text = FormatCurrency(Text5.Text * answer1)
    23.     Text6.Text = FormatCurrency(Text6.Text * answer1)
    24.     Text7.Text = FormatCurrency(Text7.Text * answer1)
    25.     Text8.Text = FormatCurrency(Text8.Text * answer1)
    26.     Text9.Text = FormatCurrency(Text9.Text * answer1)
    27.     Text10.Text = FormatCurrency(Text10.Text * answer1)
    28.     Text11.Text = FormatCurrency(Text11.Text * answer1)
    29.     Text12.Text = FormatCurrency(Text12.Text * answer1)
    30.     Text13.Text = FormatCurrency(Text13.Text * answer1)
    31.     Text14.Text = FormatCurrency(Text14.Text * answer1)
    32.     Text15.Text = FormatCurrency(Text15.Text * answer1)
    33.     Text16.Text = FormatCurrency(Text16.Text * answer1)
    34.     Text17.Text = FormatCurrency(Text17.Text * answer1)
    35.     Text18.Text = FormatCurrency(Text18.Text * answer1)
    36.     Text19.Text = FormatCurrency(Text19.Text * answer1)
    37.  
    38. End Sub
    39.  
    40. 'Clear the Values
    41. Private Sub Command3_Click()
    42.  
    43.     Text1.Text = ""
    44.     Text2.Text = ""
    45.     Text3.Text = "0"
    46.     Text4.Text = "0"
    47.    
    48.     Call Load_Default_Values
    49.    
    50. End Sub
    51.  
    52. Private Sub Load_Default_Values()
    53.  
    54. ' Loading the values into the sections
    55.     Text5.Text = FormatCurrency(4.95)
    56.     Text6.Text = FormatCurrency(5.95)
    57.     Text7.Text = FormatCurrency(8.95)
    58.     Text8.Text = FormatCurrency(10.95)
    59.     Text9.Text = FormatCurrency(12.95)
    60.     Text10.Text = FormatCurrency(9.95)
    61.     Text11.Text = FormatCurrency(11.95)
    62.     Text12.Text = FormatCurrency(13.95)
    63.     Text13.Text = FormatCurrency(15.95)
    64.     Text14.Text = FormatCurrency(17.95)
    65.     Text15.Text = FormatCurrency(24.95)
    66.     Text16.Text = FormatCurrency(26.95)
    67.     Text17.Text = FormatCurrency(28.95)
    68.     Text18.Text = FormatCurrency(30.95)
    69.     Text19.Text = FormatCurrency(32.95)
    70.    
    71. End Sub


    There are other areas to fix, but wanted to ensure it was on track first




    Bruce.

  5. #5

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Data Calculation

    Hey I have an uncle named Bruce Fox....
    lol

    Hey worked like a charm
    THANKS!!!!!!!!!!

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.     If Not (IsNumeric(Text1.Text) And IsNumeric(Text2.Text)) Then
    6.         MsgBox "Numbers only please.", vbOKOnly + vbInformation, "Data Entry"
    7.         Exit Sub
    8.     End If
    9.  
    10.  
    11.     'Your Code Here........
    12.     '
    13.     '
    14.     '
    15.  
    16.  
    17. 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
  •  



Click Here to Expand Forum to Full Width