1. Converting from atom to sequence & Vica Versa

------=_NextPart_000_0007_01C045D1.1030F820
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

Help please

I can now convert a atom to a sequence but how to I go the other way.
I need to create three random numbers between 1 and 99. The third number =
must be between the NullFrom and the NullTo fields.

--  code generated by Win32Lib IDE v0.9

include Win32Lib.ew
without warning

-------------------------------------------------------------------------=
-------
--  Window SafeWindow
global constant SafeWindow =3D create( Window, "Random Safe Codes", 0, =
90, 148, 680, 696, 0 )
global constant OneNumber =3D create( EditText, "", SafeWindow, 48, 68, =
36, 20, 0 )
global constant TwoNumber =3D create( EditText, "", SafeWindow, 108, 68, =
36, 20, 0 )
global constant ThreeNumber =3D create( EditText, "", SafeWindow, 164, =
68, 36, 20, 0 )
global constant CreateButton =3D create( PushButton, "Create Code", =
SafeWindow, 80, 104, 90, 30, 0 )
global constant LText6 =3D create( LText, "Last Wheel Null Zone", =
SafeWindow, 32, 184, 116, 20, 0 )
global constant NullFrom =3D create( EditText, "", SafeWindow, 172, 184, =
40, 20, 0 )
global constant NullTo =3D create( EditText, "", SafeWindow, 224, 184, =
40, 20, 0 )
-------------------------------------------------------------------------=
-------
procedure CreateButton_onClick ()
object temp, temp2
temp =3D rand(99)
setText(OneNumber,sprintf("%d", temp))=20
temp =3D rand(99)
setText(TwoNumber,sprintf("%d", temp))

-- here is where I want this last number to be between NullFrom and =
NullTo
-- It must loop until a random number is created within this parametre

temp =3D rand(99)
setText(ThreeNumber,sprintf("%d", temp))
end procedure




onClick[CreateButton] =3D routine_id("CreateButton_onClick")



WinMain( SafeWindow, Normal )


------=_NextPart_000_0007_01C045D1.1030F820
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Help please</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I can now convert a atom to a sequence =
but how=20
to&nbsp;I go the other way.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I need to create three random numbers =
between 1 and=20
99. The third number must be between the NullFrom and the NullTo=20
fields.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>--&nbsp; code generated by Win32Lib IDE =

v0.9</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>include Win32Lib.ew<BR>without =
warning</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
----------------<BR>--&nbsp;=20
Window SafeWindow<BR>global constant SafeWindow =3D create( Window, =
"Random Safe=20
Codes", 0, 90, 148, 680, 696, 0 )<BR>global constant OneNumber =3D =
create(=20
EditText, "", SafeWindow, 48, 68, 36, 20, 0 )<BR>global constant =
TwoNumber =3D=20
create( EditText, "", SafeWindow, 108, 68, 36, 20, 0 )<BR>global =
constant=20
ThreeNumber =3D create( EditText, "", SafeWindow, 164, 68, 36, 20, 0 =
)<BR>global=20
constant CreateButton =3D create( PushButton, "Create Code", SafeWindow, =
80, 104,=20
90, 30, 0 )<BR>global constant LText6 =3D create( LText, "Last Wheel =
Null Zone",=20
SafeWindow, 32, 184, 116, 20, 0 )<BR>global constant NullFrom =3D =
create(=20
EditText, "", SafeWindow, 172, 184, 40, 20, 0 )<BR>global constant =
NullTo =3D=20
create( EditText, "", SafeWindow, 224, 184, 40, 20, 0=20
------------<BR>procedure=20
CreateButton_onClick ()<BR>object temp, temp2<BR>temp =3D=20
rand(99)<BR>setText(OneNumber,sprintf("%d", temp)) <BR>temp =3D=20
rand(99)<BR>setText(TwoNumber,sprintf("%d", temp))</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-- here is where I want this last =
number to be=20
between NullFrom and NullTo<BR>-- It must loop until a random number is =
created=20
within this parametre</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>temp =3D=20
rand(99)<BR>setText(ThreeNumber,sprintf("%d", temp))<BR>end=20
procedure</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><BR>onClick[CreateButton] =3D=20
routine_id("CreateButton_onClick")</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>WinMain( SafeWindow, Normal=20

------=_NextPart_000_0007_01C045D1.1030F820--

new topic     » topic index » view message » categorize

2. Re: Converting from atom to sequence & Vica Versa

Hi Tony,

> The third number must be between the NullFrom and the NullTo fields.

I assume by this mean that the fields NullFrom and NullTo are expected to
contain integers. And that you what a random number in this range. I'll also
guess that these values are inclusive values.

Given these assumptions, try someting like this (my code is indented, also
use integer rather than object whenever you can - its faster) ...

--  code generated by Win32Lib IDE v0.9

include Win32Lib.ew
without warning

----------------------------------------------------------------------------
----
--  Window SafeWindow
global constant SafeWindow = create( Window, "Random Safe Codes", 0, 90,
148, 680, 696, 0 )
global constant OneNumber = create( EditText, "", SafeWindow, 48, 68, 36,
20, 0 )
global constant TwoNumber = create( EditText, "", SafeWindow, 108, 68, 36,
20, 0 )
global constant ThreeNumber = create( EditText, "", SafeWindow, 164, 68, 36,
20, 0 )
global constant CreateButton = create( PushButton, "Create Code",
SafeWindow, 80, 104, 90, 30, 0 )
global constant LText6 = create( LText, "Last Wheel Null Zone", SafeWindow,
32, 184, 116, 20, 0 )
global constant NullFrom = create( EditText, "", SafeWindow, 172, 184, 40,
20, 0 )
global constant NullTo = create( EditText, "", SafeWindow, 224, 184, 40, 20,
0 )
----------------------------------------------------------------------------
----
procedure CreateButton_onClick ()
integer temp, temp2, temp3

    -- I've chosen to do the third number first because we must
    -- check for faulty user input data.

    temp = floor(getNumber(NullFrom))
    if temp < 1 then return end if

    temp2 = floor(getNumber(NullTo))
    if temp2 < 1 then return end if

    -- Make sure the two numbers are the right way round.
    if temp > temp2 then
        temp3 = temp2
        temp2 = temp
        temp  = temp3
    end if

    -- Calculate the difference plus one
    -- Its this value we need to randomize.
    -- eg. (100 - 90) + 1 ==> 11
    temp3 = temp2 - temp + 1

    -- Add the random # to the lowest user value
    -- subtract one to bring it back into range.
    --eg.  90 + rand(11) - 1  ==> gives a number from 90 to 100, inclusive.
    temp  = temp + rand(temp3) - 1

setText(ThreeNumber,sprintf("%d", temp))

temp = rand(99)
setText(OneNumber,sprintf("%d", temp))
temp = rand(99)
setText(TwoNumber,sprintf("%d", temp))

end procedure
onClick[CreateButton] = routine_id("CreateButton_onClick")

WinMain( SafeWindow, Normal )

------
Derek Parnell
Melbourne, Australia
(Vote [1] The Cheshire Cat for Internet Mascot)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu