-
VBA Help with Word
I am working with word and vba for a class project and have ran into a wall. Any help would be appreciated. (Btw I am totally new to all of this!)
has a part here that tells me to place my code below and here's what I have based on examples within my text. It's not working. Help!
NumOne = InputBox ("Please enter the price of the car")
NumTwo = InputBox ("Please enter the delivery fee")
NumThree = InputBox ("Please enter the trade in amount")
TotalPrice = NumOne + NumTwo - NumThree
LabelOut.Caption = LabelOut.Caption & vbNewLine & "The final cost of the car selected, including delivery fee and trade in credit: & "is" & "" & TotalPrice&"
-
try this: it might give you an idea on what you want to achieve
[vba]
'Cdbl convert the string for computation
Sub try()
Dim totalprice As Double
Numone = InputBox("Please enter the price of the car")
Numtwo = InputBox("Please enter the delivery fee")
NumThree = InputBox("Please enter the trade in amount")
totalprice = CDbl(Numone) + CDbl(Numtwo) - CDbl(NumThree)
MsgBox totalprice
End Sub[/vba]
ohhh..this one is for your class project..you must try to learn and understand what you are doing. so that one day.. you will learn to stand and not to lean on.. cheers study hard..
-
The VBA MsgBox can be a good friend when you're learning. I believe the policy is we's don't do homework here. Having said that, perhaps the following will help you learns. Dave
[VBA]
MsgBox "The Price is: " & NumOne & vbCrLf _
& "The Delivery fee is: " & NumTwo & vbCrLf _
& "The Total Price is: " & TotalPrice
[/VBA]
-
-
Some suggestions.
1. I hope you are using Option Explicit. If you are not, then start...now.
2. That will force you to properly declare variables. As it stands:[vba]
NumOne = InputBox ("Please enter the price of the car")
[/vba]will return a string. Yes, using Cdbl() will work, but what if NumOne is "123e4"? The user slipped and hit a text key?
In other words....
- declare proper variables
- get into the habit of at least basic error trapping
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