|
-
Mar 19th, 2007, 01:59 AM
#1
Thread Starter
New Member
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:
Private Sub Command1_Click()
Dim sngWrangler As Single, sngGrand As Single
Dim sngTotal As Single, sngRover, sngDays As Single
'assighn the variables
sngDays = cboDays.Text
'make calculations
sngTotal = (sngWrangler * sngDays) + (sngGrand * sngDays) + (sngRover * sngDays)
'display the results on the screen
lblTotal.Caption = sngTotal
End Sub
Private Sub Form_Load()
cboDays.AddItem 1
cboDays.AddItem 2
cboDays.AddItem 3
cboDays.AddItem 4
cboDays.AddItem 5
cboDays.AddItem 6
cboDays.AddItem 7
End Sub
Private Sub optRover_Click()
If optRover.Value = True Then
sngRover = 125
Else
sngRover = 0
End If
End Sub
Private Sub optWrangler_Click()
If optWrangler.Value = True Then
sngWrangler = 55
Else
sngWrangler = 0
End If
End Sub
Private Sub optGrand_Click()
If optGrand.Value = True Then
sngGrand = 85
Else
sngGrand = 0
End If
End Sub
Private Sub chkGas_Click()
If chkGas.Value = 1 Then
sngGas = 52
Else
sngGas = 0
End If
lblTotal.Caption = ""
End Sub
Last edited by Hack; Mar 19th, 2007 at 08:30 AM.
Reason: Added VB Highlight Tags
-
Mar 19th, 2007, 02:05 AM
#2
Re: need help with a program
Are you getting any particular error?
-
Mar 19th, 2007, 02:15 AM
#3
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!
-
Mar 19th, 2007, 03:11 AM
#4
Thread Starter
New Member
Re: need help with a program
i fixed the problems you mentioned but the total still displays 0.
-
Mar 19th, 2007, 08:32 AM
#5
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.
-
Mar 19th, 2007, 09:14 AM
#6
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
-
Mar 19th, 2007, 09:57 AM
#7
Thread Starter
New Member
Re: need help with a program
thanks guys its workin now
-
Mar 19th, 2007, 10:40 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|