### Author Topic: RND  (Read 5156 times)

0 Members and 2 Guests are viewing this topic.

• Guest
##### RND
« 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

#### Jürg Menzi

• Swamp Rat
• Posts: 599
• Oberegg, Switzerland
##### Re: RND
« Reply #1 on: December 20, 2005, 02:14:07 AM »
'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...
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

#### Arizona

• Guest
##### Re: RND
« Reply #2 on: December 20, 2005, 06:34:20 AM »
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?

#### David Hall

• Automatic Duh Generator
• King Gator
• Posts: 4076
##### Re: RND
« Reply #3 on: December 20, 2005, 08:51:26 AM »
This does what you want, but it cold be laid out better

Code: [Select]
`Public Sub TESTRND()Dim num As Double, e As Doublee = 0.25 ' MUST BE INITIALIZED TO SOMETHING, OR IT REPEATS THE SAME NUMBERnum = (10 * (Rnd(e)) + 1)ThisDrawing.SetVariable "Userr1", numEnd Sub`
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

• Guest
##### Re: RND
« Reply #4 on: December 20, 2005, 10:01:51 AM »
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:

Code: [Select]
`(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
Code: [Select]
`ThisDrawing.SetVariable "USERI1", ((10 * Rnd) + 1)`will work

#### David Hall

• Automatic Duh Generator
• King Gator
• Posts: 4076
##### Re: RND
« Reply #5 on: December 20, 2005, 10:37:50 AM »
only problem I see, useri1 stores an integer, and rnd (in vba at least) generates a real (double)
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

#### Keith™

• Villiage Idiot
• Seagull
• Posts: 16899
• Superior Stupidity at its best
##### Re: RND
« Reply #6 on: December 20, 2005, 10:55:35 AM »
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
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am

Find me on https://parler.com @kblackie

#### Jürg Menzi

• Swamp Rat
• Posts: 599
• Oberegg, Switzerland
##### Re: RND
« Reply #7 on: December 28, 2005, 07:56:56 AM »
ThisDrawing.SetVariable "USERR1", (CDbl ((10 * Rnd) + 1))
should work...
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

• Guest
##### Re: RND
« Reply #8 on: January 05, 2006, 05:19:26 AM »
Nice!

Another line to the tricks book!
Thank you!

#### Kerry

• Mesozoic relic
• Seagull
• Posts: 11654
• class keyThumper<T>:ILazy<T>
##### Re: RND
« Reply #9 on: January 05, 2006, 07:15:20 AM »
I dont believe you have to cast the calc result, just make sure one of the numeric constants is a real

Code: [Select]
`ThisDrawing.SetVariable "USERR1", ((10.0 * Rnd) + 1)`or
Code: [Select]
`ThisDrawing.SetVariable "USERR1", ((10 * Rnd) + 1.0)`
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.