May 08, 2024, 01:10:42 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


ARRAY ? + GETKEYSTATE ?; emergence Basic, windows

Started by hugh, May 01, 2008, 01:32:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

hugh

I have two problems which i need someones HELP ON. source included

PROBLEM #1
          counter=1
LABEL getitnum       
          rnum = RAND 1,90
          PRINT rnum
          counter=counter+1     
          IF counter<90 THEN GOTO getitnum

How do i check to make sure that a random number is not repeated, ie, 90 different random numbers. for CONSOLE + WINDOWS

PROBLEM #2

LABEL iskeyhit
GETKEY
IF GETKEYSTATE (32) THEN GOTO clearboard:     REM spacebar
IF GETKEYSTATE (13) THEN GOTO shownum:     REM enter key
IF GETKEYSTATE (27) THEN GOTO done:           REM escape key
GOTO iskeyhit

my problem with the above is, the cursor is always the hour glass and my program locks.
this is the only getkey i have in my windows program.
The same INKEY$ routine works perfectly in the console mode
HOW DO I RECTIFY THIS PROBLEM....?



This is the program, you may modify as you wish, just want to get it working.

REM         ..............by, Hugh Mc Afee........................
REM ......sample program to run as a bingo machine TEST # 9
REM ......have to create routine to store random numbers called
REM ......and store them in an array, this is to check if a number
REM ......has already been selected, if so ,then the number is
REM ......discarded and loop back to select a number that is not stored
REM ......in the array Thus ensuring only 1 number of each 1 to 90 is selected
REM             .............................................................
REM
REM .................HELP PLEASE!!!!!!!!..............
LABEL restart: REM if the Space key is hit then close the window and come here
DEF w1 AS WINDOW
OPENWINDOW w1,0,0,1020,750,@NOAUTODRAW|@MINBOX|@SIZE,0,"DEMO_BINGO",&mustexit
DEF str AS STRING
mycount=1
REM ........................ Draw the Bingo board
FLOODFILL w1, 10, 20, RGB(255,0,0)
colnum=300
rownum=50
scount=1
ecount=10
FOR k=1 TO 90 STEP 10
FOR x = scount TO ecount
GETDATA mydata,Str
MOVE w1,colnum,rownum
SETFONT w1, "Ariel", 12, 700, @SFITALIC
FRONTPEN w1,RGB(50,255,60)
FRONTPEN w1,RGB(0,0,0)
PRINT w1,str
colnum=colnum+30
NEXT x
colnum=300
scount=scount+10
ecount=ecount+10
rownum=rownum+40
next k
SETLINESTYLE w1, @LSSOLID, 2
RECT w1, 290,40,310,360,RGB(14,1,255)
FOR j=80 TO 400 STEP 40
LINE w1, 290, j, 600, j, RGB(0,255,0)
NEXT j
FOR j=325 TO 325+(14*20) STEP 30
LINE w1, j,40,j,400,RGB(0,255,0)
NEXT j
scount=1
RESTORE mydata
MOVE w1,350,10:PRINT w1,"HUGH,S DEMO BINGO"
MOVE w1,160,580
PRINT w1,"ESCAPE Key = Endgame.....SPACEBAR = New Game......ENTER Key = Start"
MOVE w1,450,630
PRINT w1,"DEMO"
GOTO iskeyhit
LABEL bingonumber
REM IF mycount>=10 THEN STOP
rnum=RAND 1,90
num$=STR$(rnum)
num1$=LTRIM$(num$)
l=LEN(num1$)
IF l<2 THEN GOTO singledigit
l$=LEFT$(num1$,1)
r$=RIGHT$(num1$,1)
IF r$="0" THEN GOTO  zero
IF l$="1" THEN r=90
IF l$="2" THEN r=130
IF l$="3" THEN r=170
IF l$="4" THEN r=210
IF l$="5" THEN r=250
IF l$="6" THEN r=290
IF l$="7" THEN r=330
IF l$="8" THEN r=370
IF r$="1" THEN c=300
IF r$="2" THEN c=330
IF r$="3" THEN c=360
IF r$="4" THEN c=390
IF r$="5" THEN c=420
IF r$="6" THEN c=450
IF r$="7" THEN c=480
IF r$="8" THEN c=510
IF r$="9" THEN c=540
GOTO shownumbers
LABEL singledigit
r$=RIGHT$(num1$,1)
l$="0":r=50
IF r$="1" THEN c=300
IF r$="2" THEN c=330
IF r$="3" THEN c=360
IF r$="4" THEN c=390
IF r$="5" THEN c=420
IF r$="6" THEN c=450
IF r$="7" THEN c=480
IF r$="8" THEN c=510
IF r$="9" THEN c=540
GOTO shownumbers
LABEL zero
r$="0"
c=570
IF l$="1" THEN r=50
IF l$="2" THEN r=90
IF l$="3" THEN r=130
IF l$="4" THEN r=170
IF l$="5" THEN r=210
IF l$="6" THEN r=250
IF l$="7" THEN r=290
IF l$="8" THEN r=330
IF l$="9" THEN r=370
GOTO shownumbers
LABEL iskeyhit
GETKEY
IF GETKEYSTATE (27) THEN GOTO done
IF GETKEYSTATE (13) THEN GOTO bingonumber
IF GETKEYSTATE (32) THEN GOTO again
GOTO iskeyhit
LABEL done
CLOSEWINDOW w1
END
LABEL again
CLOSEWINDOW w1
GOTO restart
LABEL shownumbers
SETFONT w1, "Ariel", 12, 700, @SFITALIC
MOVE w1,750,620:PRINT w1,"Numbers= "
num1$=l$+r$
MOVE w1,c,r
BACKPEN w1, RGB(0,255,0)
PRINT w1,num1$
SETFONT w1, "Ariel", 60, 700, @SFITALIC
MOVE w1,400,450
PRINT w1,"     "
MOVE w1,400,450
BACKPEN w1, RGB(0,255,0)
FRONTPEN w1,RGB(0,0,0)
PRINT w1,num1$
SETFONT w1, "Ariel", 12, 700, @SFITALIC
MOVE w1,850,620:PRINT w1,"     "
MOVE w1,850,620:PRINT w1,mycount
mycount=mycount+1

GOTO iskeyhit
SUB mustexit
IF @MESSAGE = @IDCLOSEWINDOW
        REM closes the window and sets w1 = 0
        CLOSEWINDOW w1
    ENDIF
RETURN
ENDSUB
DATABEGIN mydata
DATA "01","02","03","04","05","06","07","08","09","10"
DATA "11","12","13","14","15","16","17","18","19","20"
DATA "21","22","23","24","25","26","27","28","29","30"
DATA "31","32","33","34","35","36","37","38","39","40"
DATA "41","42","43","44","45","46","47","48","49","50"
DATA "51","52","53","54","55","56","57","58","59","60"
DATA "61","62","63","64","65","66","67","68","69","70"
DATA "71","72","73","74","75","76","77","78","79","80"
DATA "81","82","83","84","85","86","87","88","89","90"
DATAEND



THIS IS THE CONSOLE program, need to store random numbers and check to make sure a number is not called more than once


           REM make grid of 90 numbers color black on white background
           REM select a random number between 1 and 90 and display it
           REM in the exact row and column of the grid, but highlight
           REM in a diferent color ie black on yellow, this denotes
           REM that this number has been called and can be checked on the board
           REM need routine to store called numbers and compare to make sure
           REM that , If a RANDOM # appears more than once then discard it
           REM and select another RANDOM number, and decrease the counter
           REM ********************Bingo, by Hugh Mc Afee***********************

OPENCONSOLE
DEF l$,r$,num$,num1$:STRING
DEF bingonumbers as STRING
DEF xx[90] as INT
DEF x[90] as INT
DEF counter,rnumbr,cnumbr,r,c:INT
LABEL newgame
rr=3
FOR z=1 TO 60
COLOR 0,12
LOCATE z,1
PRINT SPACE$(80)
NEXT z
r=1:c=37:counter=1:v=1
COLOR 15,0
LOCATE r,c
PRINT "BINGO"
LABEL drawboard           
COLOR 0,15
r=5:c=23
FOR k = 1 TO 90 STEP 10   
FOR j = 1 to 10           
    GETDATA bingo, bingonumbers
LOCATE r,c
    PRINT bingonumbers
c=c+3
NEXT j
r=r+1
c=23
NEXT k
RESTORE bingo
r=22:c=9
LOCATE r,c
COLOR 1,14
PRINT "....Spacebar.=.next_number..Enterkey = Newgame....ESCkey.=.quit...."
goto key
LABEL bingonumber
COLOR 1,14
r=17:c=34
FOR j=r TO r+2             
LOCATE j,c
PRINT "    "                 
NEXT j
LABEL checkit
x=RAND 1,90
num$=STR$(x):           REM need this to for trimming and seperate if double digit
num1$=LTRIM$(num$)
LOCATE 24,27
COLOR 14,0
PRINT "Numbers Called= ",counter
l=LEN(num1$)
IF l<2 THEN GOTO singledigit:      REM      its a # 1 to 9 go and add a ZERO b4 the #
l$=LEFT$(num1$,1)
r$=RIGHT$(num1$,1)
IF r$="0" THEN GOTO zero:         REM       it ends in ZERO so the column # stays the same, go and select row #
IF l$="1" THEN r=6:                    REM       stay here because its a double digit
IF l$="2" THEN r=7
IF l$="3" THEN r=8
IF l$="4" THEN r=9
IF l$="5" THEN r=10
IF l$="6" THEN r=11
IF l$="7" THEN r=12
IF l$="8" THEN r=13
IF r$="1" THEN c=23
IF r$="2" THEN c=26
IF r$="3" THEN c=29
IF r$="4" THEN c=32
IF r$="5" THEN c=35
IF r$="6" THEN c=38
IF r$="7" THEN c=41
IF r$="8" THEN c=44
IF r$="9" THEN c=47
GOSUB numbers
GOTO key
LABEL singledigit:           REM jumped to here to add a ZERO b4 the single digit,we know row #, so select column #
r$=RIGHT$(num1$,1)
l$="0":r=5
IF r$="1" THEN c=23
IF r$="2" THEN c=26
IF r$="3" THEN c=29
IF r$="4" THEN c=32
IF r$="5" THEN c=35
IF r$="6" THEN c=38
IF r$="7" THEN c=41
IF r$="8" THEN c=44
IF r$="9" THEN c=47
num1$=l$+r$
GOSUB numbers
GOTO key
LABEL zero:              REM # ends in (0, ZERO) we know column #, so get row #
c=50
IF l$="1" THEN r=5
IF l$="2" THEN r=6
IF l$="3" THEN r=7
IF l$="4" THEN r=8
IF l$="5" THEN r=9
IF l$="6" THEN r=10
IF l$="7" THEN r=11
IF l$="8" THEN r=12
IF l$="9" THEN r=13
num1$=l$+r$
GOSUB numbers
LABEL key
xx[counter]=x[counter]:        REM trying to store numbers to check for duplicate random numbers,need help on this
v$=INKEY$
if v$=chr$(32) then goto bingonumber
IF v$=CHR$(13) THEN GOTO newgame
if v$=CHR$(27) then goto exit
GOTO key
LABEL exit
closeconsole
end
SUB numbers
counter=counter+1
num1$=l$+r$
LOCATE r,c:         REM row and column
COLOR 14,1
PRINT num1$
LOCATE 18,35
COLOR 0,14
PRINT num1$
RETURN
ENDSUB
DATABEGIN bingo
DATA "01","02","03","04","05","06","07","08","09","10"
DATA "11","12","13","14","15","16","17","18","19","20"
DATA "21","22","23","24","25","26","27","28","29","30"
DATA "31","32","33","34","35","36","37","38","39","40"
DATA "41","42","43","44","45","46","47","48","49","50"
DATA "51","52","53","54","55","56","57","58","59","60"
DATA "61","62","63","64","65","66","67","68","69","70"
DATA "71","72","73","74","75","76","77","78","79","80"
DATA "81","82","83","84","85","86","87","88","89","90"
DATAEND

pistol350

All i can say now is that the major part of your program needs to be rewritten.
I may help later if i ever have  some free time.
Regards,

Peter B.

hugh

Hello Peter b.

Thank you for your comments.
You are correct.
So i am going to sit down and have a good look at the windows program again.

Thanks again.

Regards.

Hugh

LarryMc

May 01, 2008, 07:45:47 AM #3 Last Edit: May 01, 2008, 01:57:43 PM by Larry McCaughn
Here's a rewrite of your windows program.

The keyboard input works correctly.
The cursor is correct.
Duplicate numbers can't be selected.
Everything will reset without closing and reopening the window.
The "numbers " count acts properly.
The program won't try to pick another number once 90 have been picked.
No longer need datablock
All the move and print statements are gone.
And it gets rid of all those nasty GOTO statements ;)

Hope this helps.

Larry

Modified: added mycount=0 to reset as mentioned in later post

DEF w1 AS WINDOW
STRING str, l$,r$,num1$
int mycount,r,c,x,y,z,rnum
int picked[91]
for x=1 to 90
picked[x]=0
next x
mycount=0
OPENWINDOW w1,0,0,1020,750,@MINBOX|@SIZE,0,"DEMO_BINGO",&w1handler
SETWINDOWCOLOR w1, RGB(255,0,0)

CONTROL w1,@STATIC,"HUGH,S DEMO BINGO",350,10,175,20,0, 100
SETFONT w1, "Ariel", 12, 700, @SFITALIC,100
CONTROL w1,@STATIC,"ESCAPE Key = Endgame.....SPACEBAR = New Game......ENTER Key = Start",160,580,650,20,1, 101
SETFONT w1, "Ariel", 12, 700, @SFITALIC,101
CONTROL w1,@STATIC,"DEMO",450,630,60,20,1, 102
SETFONT w1, "Ariel", 12, 700, @SFITALIC,102
CONTROL w1,@STATIC," Numbers = 0",750,620,120,20,0, 103
SETFONT w1, "Ariel", 12, 700, @SFITALIC,103
CONTROL w1,@STATIC,"",400,450,110,100,1, 104
SETFONT w1, "Ariel", 60, 700, @SFITALIC,104
SETCONTROLCOLOR(w1,104,RGB(0,0,0),RGB(0,255,0))

SETLINESTYLE w1, @LSSOLID, 2
RECT w1, 290,40,306,360,RGB(14,1,255)
FOR j=80 TO 390 STEP 40
LINE w1, 290, j, 593, j, RGB(0,255,0)
NEXT j
FOR j=325 TO 325+(13*20) STEP 30
LINE w1, j,40,j,400,RGB(0,255,0)
NEXT j

REM ........................ Draw the Bingo board

c=300
r=50
for y=1 to 90 step 10
c=300
for x=1 to 10
z=x+y-1
CONTROL w1,@STATIC,ltrim$(str$(z)),c,r,20,18,1, z
c=c+30
next x
r=r+40
next y
for z = 1 to 90
SETFONT w1, "Ariel", 12, 700, @SFITALIC,z
next z

WAITUNTIL w1 = 0
end

SUB w1handler()
select @MESSAGE
case @idcreate

case @IDCLOSEWINDOW
CLOSEWINDOW w1
CASE @IDKEYDOWN
IF GETKEYSTATE (27) THEN  CLOSEWINDOW w1
IF GETKEYSTATE (13)
if mycount < 90 then bingonumber()
endif
IF GETKEYSTATE (32) THEN resetboard()
   ENDselect
RETURN
ENDSUB

sub bingonumber()
do
rnum=RAND 1,90
until picked[rnum]=0
picked[rnum]=1
SETCONTROLCOLOR(w1,rnum,RGB(0,0,0),RGB(0,255,0))
mycount++
SETCONTROLTEXT w1, 103, " Numbers = "+str$(mycount)
SETCONTROLTEXT w1, 104, ltrim$(str$(rnum))
return
endsub

sub resetboard()
for x=1 to 90
picked[x]=0
SETCONTROLCOLOR(w1,x,RGB(0,0,0),RGB(255,255,255))
next x
SETCONTROLTEXT w1, 104, ""
SETCONTROLTEXT w1, 103, " Numbers = 0"
                mycount=0
return
endsub

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

hugh

Hello Larry, and Thank you very much. The Program Works as i wanted it to.
Im baffled  as to how quick you changed everything.
The last time i wrote a program, was in the Old standard Basic, on a COMMODORE VIC20.
You would have to look it up in COMPUTER HISTORY.
I just started three weeks ago, but not much time on my hands.
Once again, my sincere thanks to you.

With regards.

Hugh

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Needs a mycount=0 somewhere in the resetboard() sub

It would be fun to plug in the speech code from Paul, also!

Brian

LarryMc

Quote from: Brian Pugh on May 01, 2008, 12:13:38 PM
Needs a mycount=0 somewhere in the resetboard() sub
Taken care of.  I modified post above.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

hugh

Thank you, Larry; and ; Brian.
I was thinking of that this evening about voice. Its 21.14, 1/5/08 here in U.K.
Now i have to get off the computer for a while, eyes are not as good as they used to be.

Best wishes to everyone.

I should be back tomorrow  a.m.


Regards

Hugh

Locodarwin

Loved my VIC-20.  Compuserve at 300 baud.  Never in my life have I had more fun doing absolutely nothing useful.

Went straight to a C-128D from there.  Still have it, in fact.

-S

Brian

Hugh,

I'm not a million miles away from you in Halifax

Brian

hugh

Hello Everyone,
Yes;  those were the days, 2k  memory, Blue Meanies, Sprites, etc, When the vic20 first came out, it cost, ÂÃ,£299.99 .
Now we are into the ;"Gig" +++,era, but some things never change, DOS, Batch Files, The old symptom,
"AUTOEXEC.bat missing?.
Well in this day and age, I still have to sit and read, and refer to the EBASIC help file, when i first seen the "CONTROL" i thought it was
something like an INT(interupt) call, Yes laugh you may, Now i just look at it as the old, PRINT@.
Now i am wondering as to why there is no, "INPUT" command in the windows. Why has such a basic and well known function like that been omitted?, or have i missed it in the help file!!!.
I am still working on the bingo program, sitting, reading, jotting down notes, whatif, whynot, maybe!,couldbe!, maybenot,etc.
number of bingo books, how many pages in book (3 or 5), 9 columns by 3 rows per ticket.
Oh yes Brian, You are in Yorkshire, I thought it was , the NOVA SCOTIA! 1.
Well got to go now. thanks for your help.

Regards.

Hugh Mc Afee

LarryMc

Quote from: hugh on May 04, 2008, 04:47:22 AM
... when i first seen the "CONTROL" i thought ...... Now i just look at it as the old, PRINT@.
The CONTROL command is not like a PRINT statement at all.  You might have gotten that impression because your bingo program is only using the "static" control type.
The CONTROL command adds a "control" to a window or dialog.  The window or dialog is considered the parent and the "control" is a child of that parent.  controls in reality are windows themselves.  There are a basic set of  controls built into the windows OS and thus into EBasic.  Paul has made them easy to implement.  You can create custom controls as I have done and posted in the offering forum.

Quote from: hugh on May 04, 2008, 04:47:22 AM
Now i am wondering as to why there is no, "INPUT" command in the windows. Why has such a basic and well known function like that been omitted?, or have i missed it in the help file!!!.
There is an INPUT command in EBasic when you are in a console type program; kinda like what you got with the old DOS window.

If you want a prompt and data enter you can use an "edit" type control.
Also, if you want to use the mouse instead of the keyboard to start/stop/pick a number you can use  "button" type controls.

You really need to go through the examples that were supplied with EBasic.

Larry

Because of the message handler associated with windows type programs you have to use commands/messages/functions that work with a message handler.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Hugh,

to help a little with the CONTROL concept I have taken the version of your bingo that I modified and posted above and modified it again.

I have removed the STATIC control that had the text for the keyboard keys.
I also removed the code in the window's message handler that responded to the keyboard keys.

I added three BUTTON controls to replace the 3 keyboard keys.
I also added the code in the window's message handler that will respond to mouse clicks on the buttons.

I didn't actually remove the old code; i just commented it out.
If you wanted both the mouse and the keyboard to work all you have to do is remove the 2 sets of /* */ that I put in the program.

Download the attached file; unzip it into your project directory and then open it.
Compile as WINDOWS.exe type and see the difference.

Hope this helps.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

hugh

Thanks Larry; and Yes you are correct,  i do have to delve into the HELP file more often.

Buttons a good idea.

Regards

Hugh