Consulting

Results 1 to 5 of 5

Thread: VBA Help with Word

  1. #1

    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&"

  2. #2
    VBAX Contributor
    Joined
    Feb 2009
    Posts
    103
    Location
    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..

  3. #3
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    836
    Location
    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]

  4. #4
    Thanks.

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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
  •