How to input data and not to 'freeze' a program

Previous topic - Next topic

Nascirek

I know that 'input' command stops a program and waits for user's data.  So how to input a data and not to stop a program? The code below shows that input command freezes 'engine' based on "while... wend" loop concept until the user inputs a data. Please, any solution for it?

WHILE TRUE
MOUSESTATE mx,my,b1,b2
PRINT "x",mx,my
IF b1=1 THEN INPUT alfa,100,100
SHOWSCREEN
WEND

Kitty Hello

User inkey$:
Code (glbasic) Select
// Test INKEY$ by replacing "INPUT" command

test$ = Inp$("What is the matrix?")
PRINT "test$ = " + test$,0,100
SHOWSCREEN
MOUSEWAIT

// ------------------------------------------------------------- //
// INPUT via INKEY$
// ------------------------------------------------------------- //
FUNCTION Inp$: name$
// Local name$
// Setup Starfield data
WHILE TRUE
IF KEY(14)
IF backspace=FALSE
name$=MID$(name$, 0, LEN(name$)-1) // Backspace
backspace=TRUE
ENDIF
ELSE
backspace=FALSE
last$ = in$
in$=INKEY$()
IF last$ <> in$ THEN name$=name$+in$
ENDIF
GOSUB ShowStarfield
PRINT name$, 0, 100
SHOWSCREEN
IF KEY(28) THEN RETURN name$ // Return pressed
WEND
ENDFUNCTION


// ------------------------------------------------------------- //
// -=#  SHOWSTARFIELD  #=-
// ------------------------------------------------------------- //
SUB ShowStarfield:
LOCAL x,y,c,d,dt
dt=GETTIMERALL()
FOR x=0 TO 639 STEP 8
c=MOD(ABS(SIN(x))*x*5, 4)+1
y=MOD(MOD(x*13 + dt*c/200, 480), 480/8) * 480/8
d=c*64 -1
WHILE d>10
FILLRECT x,y, x+8, y+8, RGB(d/8,d,d/8)
d=d*.9
y=y-8
WEND
NEXT
ENDSUB // SHOWSTARFIELD

Nascirek

Thanks, it really works for word data. But what about number data? How to convert data$ into data?

Nas'

Kitty Hello

Code (glbasic) Select
...
in$=INKEY$()
IF ASC(in$)ASC("9") THEN in$=""
...
;)

You ask if the ascii-value for the input character is in the range of "0" and "9" -> include "." if you want floating points as well.