TheSwamp
Code Red => VB(A) => Topic started by: vladimirzm on December 20, 2005, 01:09:15 AM
-
how do i store the the random number (generated through RND) in USERR1
ThisDrawing.SetVariable "USERI1", ((10 * Rnd) + 1) returns error
-
'rnd' returns a single (real in Lisp), therefore you've to use the USERRx variables as you mentioned in the text.
Your sample works with a USERIx variable and that is not possible...
-
In VBA, variables are defined based on the type of data you plan to store such as:
Dim Num as Integer
would be a variable that would only hold integers. So if I tried to store a string value such as "123" I would get an error.
However once I have defined my variable I can now assign a value to it:
Set Num = ((10 * RND)+1)
You can then use that variable that contains a value.
Note: I did not address whether your math function works or not.
What is the purpose of setting this value to UserI1? (is this really a variable? I'm on 2000i...) or are you simply trying to store a value somewhere?
-
This does what you want, but it cold be laid out better
Public Sub TESTRND()
Dim num As Double, e As Double
e = 0.25 ' MUST BE INITIALIZED TO SOMETHING, OR IT REPEATS THE SAME NUMBER
num = (10 * (Rnd(e)) + 1)
ThisDrawing.SetVariable "Userr1", num
End Sub
-
thanks
'rnd' returns a single (real in Lisp), therefore you've to use the USERRx variables as you mentioned in the text.
Your sample works with a USERIx variable and that is not possible...
USERRx or USERIx returns the same thing... error
In VBA, variables are defined based on the type of data you plan to store such as:
Dim Num as Integer
would be a variable that would only hold integers. So if I tried to store a string value such as "123" I would get an error.
However once I have defined my variable I can now assign a value to it:
Set Num = ((10 * RND)+1)
You can then use that variable that contains a value.
Note: I did not address whether your math function works or not.
What is the purpose of setting this value to UserI1? (is this really a variable? I'm on 2000i...) or are you simply trying to store a value somewhere?
Well, actually I'm trying to store from Vlisp. For example:
(defun msgbox (title button msg / useri1 r)
(setq useri1 (getvar "useri1"))
(vla-eval
(vlax-get-acad-object)
(strcat
"ThisDrawing.SetVariable \"USERI1\","
"MsgBox (\""
msg
"\","
(itoa button)
",\""
title
"\")"
)
)
(setq r (getvar "useri1"))
(setvar "useri1" useri1)
r
)
This works very well and allow me to show basic interface without DCL... Msgbox returns a value that is stored in USERI1, then i can use this without trouble.
In the same way I supposed
ThisDrawing.SetVariable "USERI1", ((10 * Rnd) + 1)
will work
-
only problem I see, useri1 stores an integer, and rnd (in vba at least) generates a real (double)
-
If you place the value of your RND call in a variant you should be able to place it in useri1 without incident, or at very least move the data from a variant to an integer variable then into useri1
-
ThisDrawing.SetVariable "USERR1", (CDbl ((10 * Rnd) + 1))
should work...
-
Nice!
Another line to the tricks book!
Thank you!
-
I dont believe you have to cast the calc result, just make sure one of the numeric constants is a real
ThisDrawing.SetVariable "USERR1", ((10.0 * Rnd) + 1)
or
ThisDrawing.SetVariable "USERR1", ((10 * Rnd) + 1.0)