PDA

View Full Version : VBA Help with Word



rlcaudill
06-29-2009, 07:13 PM
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&"

joms
06-29-2009, 10:24 PM
try this: it might give you an idea on what you want to achieve


'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

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..

Dave
06-29-2009, 10:34 PM
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

MsgBox "The Price is: " & NumOne & vbCrLf _
& "The Delivery fee is: " & NumTwo & vbCrLf _
& "The Total Price is: " & TotalPrice

rlcaudill
06-29-2009, 10:43 PM
Thanks.

fumei
06-30-2009, 10:43 AM
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:
NumOne = InputBox ("Please enter the price of the car")
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