PDA

View Full Version : Help with VBA code for a scale calculator



RMS
08-14-2007, 10:52 AM
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:
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


But :banghead: Its hanging up on this part:
fscale = (cfeet / nfeet)


Any help is appreciated!
:friends:

Tommy
08-14-2007, 04:39 PM
I'm going way out on a limb here by assuming sooooooo much :rofl:

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



It's a start anyway :)

Tommy
08-14-2007, 04:51 PM
I attached a sample with a form. It doesn't have the formatting of yours.:thumb

Zrob
08-14-2007, 06:12 PM
I attached a sample with a form. It doesn't have the formatting of yours.:thumb

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 :bug: 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 :mkay

But hey its is working good job Tommy! :friends:

Bob Phillips
08-15-2007, 12:21 AM
Instead of a message box, use a texbox to output to. You should be able to copy that then.

Tommy
08-15-2007, 06:16 AM
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.:yes

RMS
08-15-2007, 11:51 AM
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