Consulting

Results 1 to 7 of 7

Thread: Help with VBA code for a scale calculator

  1. #1
    VBAX Regular
    Joined
    Jul 2007
    Posts
    34
    Location

    Help with VBA code for a scale calculator

    Hello Everyone!

    Need help with some code, this is what I have but first off its just a very basic calculator to come up with a scale factor. I have this dialog box seen in pic, and this code:
    [VBA]Private Sub CommandButton1_Click()

    Dim crfeet As Double
    Dim crinch As Double
    Dim nrfeet As Double
    Dim nrinch As Double
    Dim cfeet As Double
    Dim nfeet As Double
    Dim fscale As Double

    cfeet = (crfeet * 12) + crinch ' For Text Box input
    nfeet = (nrfeet * 12) + nrinch ' For Text Box input

    fscale = (cfeet / nfeet)


    Dim Msg, Style, Title, Response, MyString
    Msg = "fscale" ' Define message.
    Style = CommandButton1 ' Define buttons.
    Title = "Scale Factor" ' Define title.
    ' context.
    ' Display message.
    Response = MsgBox(Msg, Style, Title)

    End Sub
    [/VBA]

    But Its hanging up on this part:
    [VBA]fscale = (cfeet / nfeet)
    [/VBA]

    Any help is appreciated!



  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I'm going way out on a limb here by assuming sooooooo much
    [vba]
    Private Sub CommandButton1_Click()

    'Dim crfeet As Double <- should be the userform textbox name
    'Dim crinch As Double <- should be the userform textbox name
    'Dim nrfeet As Double <- should be the userform textbox name
    'Dim nrinch As Double <- should be the userform textbox name
    Dim cfeet As Double
    Dim nfeet As Double
    Dim fscale As Double
    ' For Text Box input
    cfeet = (Val(UserForm1.crfeet.text) * 12) + Val(UserForm1.crinch.text)
    ' For Text Box input
    nfeet = (Val(UserForm1.nrfeet.text) * 12) + Val(UserForm1.nrinch.text)

    fscale = (cfeet / nfeet)

    'the below will display the message box with the answer
    Dim Msg, Style, Title, Response, MyString
    Msg = cstr(fscale ) ' Define message.
    Style = vbOK ' Define buttons.
    Title = "Scale Factor" ' Define title.
    ' context.
    ' Display message.
    Response = MsgBox(Msg, Style, Title)

    End Sub

    [/vba]

    It's a start anyway

  3. #3
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I attached a sample with a form. It doesn't have the formatting of yours.

  4. #4
    Quote Originally Posted by Tommy
    I attached a sample with a form. It doesn't have the formatting of yours.
    Thanks for the help, forgot my password at work for RMS.

    But one problem, how would we cut and paste the scale factor to use in a command? I thought I would be able to cut out of a message box what was Bill Gates thinking???

    Actually if we could use this code within the scale command that would be my goal. I will try and come up with somthing else

    But hey its is working good job Tommy!

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Instead of a message box, use a texbox to output to. You should be able to copy that then.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Quote Originally Posted by Zrob
    Actually if we could use this code within the scale command that would be my goal.
    You could write a macro to scale. Select the entities with a selection set with filters, or let the user select the entities one at a time or multiple. Display the userform, get your answer and invoke the scale command passing the entities and the scale with base point one at a time or all at once (basically rescale the whole drawing so far as the entities selected go).

    As xld has said the output could also be placed in a text box, but the scale command and the selection would have to be made after the form has been closed or hidden.

  7. #7
    VBAX Regular
    Joined
    Jul 2007
    Posts
    34
    Location
    Quote Originally Posted by xld
    Instead of a message box, use a texbox to output to. You should be able to copy that then.
    I will give that a try, then do somthing more advanced.

    Thanks guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •