Results 1 to 8 of 8

Thread: need help with a program

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    need help with a program

    This program gives you the option of picking 3 different rental cars. Jeep Wrangler which cost $55 per day, Grand Cherokee which cost $85 per day, and a Land Rover which cost $125 dollars per day. You also have an option to refill the gas for $52. The program needs to calculate the total cost.

    here my code, but its didnt work:
    vb Code:
    1. Private Sub Command1_Click()
    2. Dim sngWrangler As Single, sngGrand As Single
    3. Dim sngTotal As Single, sngRover, sngDays As Single
    4.  
    5. 'assighn the variables
    6. sngDays = cboDays.Text
    7. 'make calculations
    8. sngTotal = (sngWrangler * sngDays) + (sngGrand * sngDays) + (sngRover * sngDays)
    9. 'display the results on the screen
    10. lblTotal.Caption = sngTotal
    11.  
    12. End Sub
    13.  
    14. Private Sub Form_Load()
    15. cboDays.AddItem 1
    16. cboDays.AddItem 2
    17. cboDays.AddItem 3
    18. cboDays.AddItem 4
    19. cboDays.AddItem 5
    20. cboDays.AddItem 6
    21. cboDays.AddItem 7
    22.  
    23. End Sub
    24.  
    25. Private Sub optRover_Click()
    26. If optRover.Value = True Then
    27.     sngRover = 125
    28. Else
    29.     sngRover = 0
    30. End If
    31. End Sub
    32.  
    33. Private Sub optWrangler_Click()
    34. If optWrangler.Value = True Then
    35.     sngWrangler = 55
    36. Else
    37.     sngWrangler = 0
    38. End If
    39. End Sub
    40.  
    41. Private Sub optGrand_Click()
    42. If optGrand.Value = True Then
    43.     sngGrand = 85
    44. Else
    45.     sngGrand = 0
    46. End If
    47. End Sub
    48.  
    49. Private Sub chkGas_Click()
    50.  
    51. If chkGas.Value = 1 Then
    52.     sngGas = 52
    53. Else
    54.     sngGas = 0
    55. End If
    56.  
    57. lblTotal.Caption = ""
    58. End Sub
    Last edited by Hack; Mar 19th, 2007 at 08:30 AM. Reason: Added VB Highlight Tags

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: need help with a program

    Are you getting any particular error?

  3. #3
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: need help with a program

    You did declare the Single Variables in the Sub Command1_Click although you need them in the whole programm, put the declaration in the General Section (just below "Option Explicit") . also you are missing the declaration of sngGas and sngRover isn't declared correctly!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    Re: need help with a program

    i fixed the problems you mentioned but the total still displays 0.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: need help with a program

    Number one problem is that you are declaring your variables at the event level. sngRover, sngWrangler etc are only available to the Command1_Click event.

    They mean nothing whatsoever to any of the option button click events.

    Remove those variable declarations from the button's click event and place them as Private in the Form's declaration section. This will make these variables available to EVERYTHING on the form.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: need help with a program

    And the first line of EVERY code window in VB should be Option Explicit. Then you won't have those problerms.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    Re: need help with a program

    thanks guys its workin now

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: need help with a program

    One last thing....sngRover is not a Single, it is a Variant. You should change your declares to include sngRover As Single.

    Also, if you consider this resolved, would you please pull down the Thread Tools menu and click the Mark Thread Resolved menu item? That will let everyone know that you have your answer.

    Thank you.

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