DEMOS:
VIRTUAL TABS
Here's a way to make data in a non-fixed font (like Arial) look like it's tabbed. The right-justified sample uses LB3's 'stringwidth' command (many thanks, Carl). That command also works great for centering a string. I suppose one could even line up decimal points of a column of numbers, by making a left and right string out of each one.
'------------- start of demo -----------------
' tabArial.bas -- virtual tabbing with
' non-fixed fonts in LB3.
' Demo by Bill Jennings, Jan 2003.
nomainwin
WindowWidth=500 : WindowHeight=480
graphicbox #w1.g1,1,1,500,480
open "" for window as #w1
print #w1, "trapclose [quit]"
gosub [getData]
print #w1.g1,"font Arial 0 18"
gosub [display]
WAIT
[display] '*** in 3 columns
print #w1.g1, "down"
for border=1 to 4
x=150*(border-1)+10
print #w1.g1, "line ";x;" 28 ";x;" 414"
next border
print #w1.g1, "place 182 20"
print #w1.g1, "\- Left justified -"
print #w1.g1, "place 178 230"
print #w1.g1, "\- Right justified -"
'*** left-justified
for col=1 to 3
for row=1 to 9
nData=(col-1)*9+row
x=150*(col-1)+20
print #w1.g1, "place ";x;" ";20*(row-1)+40
print #w1.g1, "\";a$(nData)
next row
next col
'*** right-justified
'Uses "stringwidth" command.
for col=1 to 3
for row=1 to 9
nData=(col-1)*9+row : b$=a$(nData)
print #w1.g1, "stringwidth? b$ width"
x=150*(col-1)+150-width
print #w1.g1, "place ";x;" ";20*(row-1)+250
print #w1.g1, "\";a$(nData)
next row
next col
RETURN
[getData] '*** make 27 strings
DIM a$(27)
for d=1 to 27
nChrs=int(rnd(1)*6)+3
a$(d)="data "
for h=1 to nChrs
nAsc=int(rnd(1)*74)+48
if nAsc=92 then nAsc=45
a$(d)=a$(d)+chr$(nAsc)
next h
next d
RETURN
[quit]
close #w1 : END
'------------- end of code -----------------
HOT KEYS AND MOUSE CLICKS
This demo will:
each array item, and the user can input that number followed by the enter
key. No mouse required, but that could work too.
' hotClicks.bas -- demo of hotkeys in combination and mouseclicks,
' simultaneously enabled. Jan 2003, Bill Jennings
' Thanks to Doyle and Alyce for clarifying the 'setfocus' command.
nomainwin
UpperLeftX=40 : UpperLeftY=80
WindowWidth=640 : WindowHeight=300
b1$="Alt-X will hotkey this EXIT button"
b2$="Input a multi-digit number"
button #w1.b1,b1$,[quit],UL,20,40
button #w1.b2,b2$,[number],UL,20,108
statictext #w1.st1,"",40,160,600,160
statictext #w1.st2,"",320,150,300,30
graphicbox #w1.g1,0,0,0,0
open "" for window_popup as #w1
print #w1, "trapclose [quit]"
print #w1, "font Arial 0 22"
print #w1.g1, "when characterInput [key]"
print #w1.g1, "setfocus"
'*** buffer$ is used in [scanLoop]:
buffer$ = space$(256) + chr$(0)
[scanLoop] '*** Scan sets focus back to the window
' for mouse clicks after pressing a hot key.
SCAN
'*** Check for Alt-X keys combination:
calldll #user32, "GetKeyboardState",_
buffer$ as ptr, result as void
Alt$=mid$(buffer$,19)
'*** 19 is the VK code decimal value + 1.
if asc(Alt$)>127 then Alt=1 '*** Alt key pressed
X$=mid$(buffer$,89)
if asc(X$)>127 then X=1 '*** X key pressed
if Alt and X then [quit]
'*** 1 ms delay to save processor cycles:
calldll #kernel32,"Sleep",1 as ulong,r as void
goto [scanLoop]
[quit]
close #w1
END
[key]
Alt=0 : X=0 '*** reset
key$ = Inkey$
ndx=asc(right$(key$,1))
if number then gosub [numberPressed]
goto [scanLoop]
[number]
decimal=0
print #w1.st1, ""
print #w1.g1,"locate 300 106 300 30"
print #w1, "refresh"
print #w1.g1, "cls"
prompt "maximum number "; mxNum$
if mxNum$="" then [scanLoop]
mxNum=val(mxNum$)
tx1$="Max number= "+mxNum$+chr$(13)+chr$(13)+_
"Start pressing keys."+chr$(13)+_
"The number will stop building when you press enter"+_
chr$(13)+"or when you exceed the maximum number."
print #w1.st1, tx1$
print #w1.g1, "setfocus" 'reset for key input.
number=1
goto [scanLoop]
[numberPressed]
ok=0
if ndx=46 and not(decimal) then_
decimal=1 : ok=1 '*** decimal point
if ndx>47 and ndx<58 then ok=1 '*** a number
if ok then
num$=num$+chr$(ndx)
if val(num$)>mxNum then_
num$=left$(num$,len(num$)-1) : done=1
print #w1.st2, num$
end if
if ndx=13 or done then '*** Enter key
print #w1.st2, ""
print #w1.g1,"place 10 18"
print #w1.g1, "down;\the number is ";num$
num$="" : done=0 : number=0
end if
RETURN