Home Why Omnibasic Features FAQ Examples
Reviews Keyword/Syntax On-Line Manual Download Manual ScreenShots

Examples

OBDC ZipCode Program Development

OBDC ZipCode Program

The ZipCode Program shown above is an example showing the ODBC capabilities of OmniBasic. The user enters a zipcode in the zip textfield and then clicks on the find button. The city and state are then populated with data retrieved from a SQL Server table. Notice the extremely small amount of setup and select code required. Most of the code is used to construct the visual objects. The construct code was generated automatically by the IDE.

#USE obdefs.def
************ Declarations ************
DIM TempStr AS STRING * 100
DIM EnterStr AS STRING * 32
************ Construct Objects ************
**************** OBMain ****************
OBMain.POSITION=210-4,195-22
OBMain.SIZE=385,126
OBMain.ENABLED=TRUE
OBMain.BACKCOLOR=$c0c0c0
OBMain.TEXT="ZipCode"

**************** ExitButton ****************
CONSTRUCT ExitButton AS Button
ExitButton.POSITION=20,70
ExitButton.SIZE=60,40
ExitButton.VISIBLE=TRUE
ExitButton.ENABLED=TRUE
ExitButton.BACKCOLOR=$c0c0c0
ExitButton.TEXT="E&xit"
ExitButton.TEXTCOLOR=$0
ExitButton.FONT="Helvetica",8

**************** FindButton ****************
CONSTRUCT FindButton AS Button
FindButton.POSITION=262,70
FindButton.SIZE=100,40
FindButton.VISIBLE=TRUE
FindButton.ENABLED=TRUE
FindButton.BACKCOLOR=$c0c0c0
FindButton.TEXT="&Find"
FindButton.TEXTCOLOR=$0
FindButton.FONT="Helvetica",8

**************** ZipLabel ****************
CONSTRUCT ZipLabel AS Label
ZipLabel.POSITION=260,10
ZipLabel.SIZE=100,20
ZipLabel.VISIBLE=TRUE
ZipLabel.ENABLED=TRUE
ZipLabel.BACKCOLOR=$c0c0c0
ZipLabel.TEXT="Zip"
ZipLabel.TEXTCOLOR=$0
ZipLabel.FONT="Helvetica",8

**************** StateLabel ****************
CONSTRUCT StateLabel AS Label
StateLabel.POSITION=140,10
StateLabel.SIZE=100,20
StateLabel.VISIBLE=TRUE
StateLabel.ENABLED=TRUE
StateLabel.BACKCOLOR=$c0c0c0
StateLabel.TEXT="State"
StateLabel.TEXTCOLOR=$0
StateLabel.FONT="Helvetica",8

**************** CityLabel ****************
CONSTRUCT CityLabel AS Label
CityLabel.POSITION=20,10
CityLabel.SIZE=100,20
CityLabel.VISIBLE=TRUE
CityLabel.ENABLED=TRUE
CityLabel.BACKCOLOR=$c0c0c0
CityLabel.TEXT="City"
CityLabel.TEXTCOLOR=$0
CityLabel.FONT="Helvetica",8

**************** CityText ****************
CONSTRUCT CityText AS TextField
CityText.POSITION=20,30
CityText.SIZE=100,20
CityText.VISIBLE=TRUE
CityText.ENABLED=TRUE
CityText.BACKCOLOR=$ffffff
CityText.TEXT=""
CityText.TEXTCOLOR=$0
CityText.FONT="Helvetica",8

**************** StateText ****************
CONSTRUCT StateText AS TextField
StateText.POSITION=140,30
StateText.SIZE=100,20
StateText.VISIBLE=TRUE
StateText.ENABLED=TRUE
StateText.BACKCOLOR=$ffffff
StateText.TEXT=""
StateText.TEXTCOLOR=$0
StateText.FONT="Helvetica",8

**************** ZipText ****************
CONSTRUCT ZipText AS TextField
ZipText.POSITION=260,30
ZipText.SIZE=100,20
ZipText.VISIBLE=TRUE
ZipText.ENABLED=TRUE
ZipText.BACKCOLOR=$ffffff
ZipText.TEXT=""
ZipText.TEXTCOLOR=$0
ZipText.FONT="Helvetica",8


************ Initialize ************
CONSTRUCT ZipData AS DATASET' Construct the dataset object
ZipData.LOGON "UID=sa;PWD=;DSN=my_db"' Logon to database
************ Events ************
FindButton.CLICK
CityText.TEXT=""
StateText.TEXT=""
EnterStr=ZipText.TEXT
TempStr="select city, state from zipcode where zip='"+EnterStr+"'"
ZipData.SELECT TempStr' Send SQL Command to ODBC
WHILE NOT(EOF(ZipData)) DO' Loop to pull out the data
ZipData.GETDATA EnterStr
CityText.TEXT=EnterStr
ZipData.GETDATA EnterStr
StateText.TEXT=EnterStr
ENDWHILE
EXIT EVENT

ExitButton.CLICK
END
EXIT EVENT


Calculator Example

The calculator shown above was designed using the IDE. The script shown below is the code required to build the calculator. The code written by the user as well as the code generated by the IDE is combined into this single file which is then automatically sent to the compiler to produce the finished product. The code generated by the IDE is mainly concerned with the construction of the visual objects, their sizing, positioning, and other key attributes.


#USE obdefs.def
************ Declarations ************
dim i as long
dim x as long
dim row as long
dim tempstr as string *32
dim numarray(100,2) as float
dim opnumarray(100) as long
dim display as string * 11
dim acc as float
dim cur as float
dim tempfloat as float
dim memory as float
dim displayoperator as string * 6
dim opflag as byte
dim firstoperand as byte
dim pendingop as byte
dim keystrip as long
dim tmp1 as string * 12
dim tmp2 as string * 12
dim ftmp1 as float
dim ftmp2 as float
const div=1
const sq=2
const mul=3
const percent=4
const sub=5
const inverse=6
const add=7
const eq=8
const MC=1
const MR=2
const MS=3
const MA=4
const BackSpace = 1
const CE=2
const C=3
#SBRTN NumAction
#SBRTN OpsAction
#SBRTN MemAction
#SBRTN EditAction
************ Construct Objects ************
**************** OBMain ****************
OBMain.POSITION=210-4,195-22
OBMain.SIZE=252,360
OBMain.ENABLED=TRUE
OBMain.BACKCOLOR=$c0c0c0
OBMain.TEXT="OBMain"
**************** Edit(1) ****************
CONSTRUCT Edit(3) AS Button
Edit(1).POSITION=51,67
Edit(1).SIZE=62,28
Edit(1).VISIBLE=TRUE
Edit(1).ENABLED=TRUE
Edit(1).BACKCOLOR=$c0c0c0
Edit(1).TEXT="Backspace"
Edit(1).TEXTCOLOR=$80
Edit(1).FONT="Arial",8
**************** Edit(2) ****************
Edit(2).POSITION=118,67
Edit(2).SIZE=62,28
Edit(2).VISIBLE=TRUE
Edit(2).ENABLED=TRUE
Edit(2).BACKCOLOR=$c0c0c0
Edit(2).TEXT="CE"
Edit(2).TEXTCOLOR=$80
Edit(2).FONT="Arial",12
**************** Edit(3) ****************
Edit(3).POSITION=185,67
Edit(3).SIZE=62,28
Edit(3).VISIBLE=TRUE
Edit(3).ENABLED=TRUE
Edit(3).BACKCOLOR=$c0c0c0
Edit(3).TEXT="C"
Edit(3).TEXTCOLOR=$80
Edit(3).FONT="Arial",12
**************** Mem(1) ****************
CONSTRUCT Mem(4) AS Button
Mem(1).POSITION=9,104
Mem(1).SIZE=34,28
Mem(1).VISIBLE=TRUE
Mem(1).ENABLED=TRUE
Mem(1).BACKCOLOR=$c0c0c0
Mem(1).TEXT="MC"
Mem(1).TEXTCOLOR=$ff
Mem(1).FONT="Arial",11
**************** Mem(2) ****************
Mem(2).POSITION=9,137
Mem(2).SIZE=34,28
Mem(2).VISIBLE=TRUE
Mem(2).ENABLED=TRUE
Mem(2).BACKCOLOR=$c0c0c0
Mem(2).TEXT="MR"
Mem(2).TEXTCOLOR=$ff
Mem(2).FONT="Arial",11
**************** Mem(3) ****************
Mem(3).POSITION=9,170
Mem(3).SIZE=34,28
Mem(3).VISIBLE=TRUE
Mem(3).ENABLED=TRUE
Mem(3).BACKCOLOR=$c0c0c0
Mem(3).TEXT="MS"
Mem(3).TEXTCOLOR=$ff
Mem(3).FONT="Arial",11
**************** Mem(4) ****************
Mem(4).POSITION=9,203
Mem(4).SIZE=34,28
Mem(4).VISIBLE=TRUE
Mem(4).ENABLED=TRUE
Mem(4).BACKCOLOR=$c0c0c0
Mem(4).TEXT="M+"
Mem(4).TEXTCOLOR=$ff
Mem(4).FONT="Arial",11
**************** Num(1) ****************
CONSTRUCT Num(12) AS Button
Num(1).POSITION=51,203
Num(1).SIZE=34,28
Num(1).VISIBLE=TRUE
Num(1).ENABLED=TRUE
Num(1).BACKCOLOR=$c0c0c0
Num(1).TEXT="0"
Num(1).TEXTCOLOR=$ff0000
Num(1).FONT="Arial",11
**************** Num(2) ****************
Num(2).POSITION=89,203
Num(2).SIZE=34,28
Num(2).VISIBLE=TRUE
Num(2).ENABLED=TRUE
Num(2).BACKCOLOR=$c0c0c0
Num(2).TEXT="+/-"
Num(2).TEXTCOLOR=$ff0000
Num(2).FONT="Arial",11
**************** Num(3) ****************
Num(3).POSITION=127,203
Num(3).SIZE=34,28
Num(3).VISIBLE=TRUE
Num(3).ENABLED=TRUE
Num(3).BACKCOLOR=$c0c0c0
Num(3).TEXT="."
Num(3).TEXTCOLOR=$ff0000
Num(3).FONT="Arial",14
**************** Num(4) ****************
Num(4).POSITION=51,170
Num(4).SIZE=34,28
Num(4).VISIBLE=TRUE
Num(4).ENABLED=TRUE
Num(4).BACKCOLOR=$c0c0c0
Num(4).TEXT="1"
Num(4).TEXTCOLOR=$ff0000
Num(4).FONT="Arial",11
**************** Num(5) ****************
Num(5).POSITION=89,170
Num(5).SIZE=34,28
Num(5).VISIBLE=TRUE
Num(5).ENABLED=TRUE
Num(5).BACKCOLOR=$c0c0c0
Num(5).TEXT="2"
Num(5).TEXTCOLOR=$ff0000
Num(5).FONT="Arial",11
**************** Num(6) ****************
Num(6).POSITION=127,170
Num(6).SIZE=34,28
Num(6).VISIBLE=TRUE
Num(6).ENABLED=TRUE
Num(6).BACKCOLOR=$c0c0c0
Num(6).TEXT="3"
Num(6).TEXTCOLOR=$ff0000
Num(6).FONT="Arial",11
**************** Num(7) ****************
Num(7).POSITION=51,137
Num(7).SIZE=34,28
Num(7).VISIBLE=TRUE
Num(7).ENABLED=TRUE
Num(7).BACKCOLOR=$c0c0c0
Num(7).TEXT="4"
Num(7).TEXTCOLOR=$ff0000
Num(7).FONT="Arial",11
**************** Num(8) ****************
Num(8).POSITION=89,137
Num(8).SIZE=34,28
Num(8).VISIBLE=TRUE
Num(8).ENABLED=TRUE
Num(8).BACKCOLOR=$c0c0c0
Num(8).TEXT="5"
Num(8).TEXTCOLOR=$ff0000
Num(8).FONT="Arial",11
**************** Num(9) ****************
Num(9).POSITION=127,137
Num(9).SIZE=34,28
Num(9).VISIBLE=TRUE
Num(9).ENABLED=TRUE
Num(9).BACKCOLOR=$c0c0c0
Num(9).TEXT="6"
Num(9).TEXTCOLOR=$ff0000
Num(9).FONT="Arial",11
**************** Num(10) ****************
Num(10).POSITION=51,104
Num(10).SIZE=34,28
Num(10).VISIBLE=TRUE
Num(10).ENABLED=TRUE
Num(10).BACKCOLOR=$c0c0c0
Num(10).TEXT="7"
Num(10).TEXTCOLOR=$ff0000
Num(10).FONT="Arial",11
**************** Num(11) ****************
Num(11).POSITION=89,104
Num(11).SIZE=34,28
Num(11).VISIBLE=TRUE
Num(11).ENABLED=TRUE
Num(11).BACKCOLOR=$c0c0c0
Num(11).TEXT="8"
Num(11).TEXTCOLOR=$ff0000
Num(11).FONT="Arial",11
**************** Num(12) ****************
Num(12).POSITION=127,104
Num(12).SIZE=34,28
Num(12).VISIBLE=TRUE
Num(12).ENABLED=TRUE
Num(12).BACKCOLOR=$c0c0c0
Num(12).TEXT="9"
Num(12).TEXTCOLOR=$ff0000
Num(12).FONT="Arial",11
**************** Ops(1) ****************
CONSTRUCT Ops(8) AS Button
Ops(1).POSITION=173,104
Ops(1).SIZE=34,28
Ops(1).VISIBLE=TRUE
Ops(1).ENABLED=TRUE
Ops(1).BACKCOLOR=$c0c0c0
Ops(1).TEXT="/"
Ops(1).TEXTCOLOR=$ff
Ops(1).FONT="Arial",11
**************** Ops(2) ****************
Ops(2).POSITION=212,104
Ops(2).SIZE=34,28
Ops(2).VISIBLE=TRUE
Ops(2).ENABLED=TRUE
Ops(2).BACKCOLOR=$c0c0c0
Ops(2).TEXT="sqrt"
Ops(2).TEXTCOLOR=$800000
Ops(2).FONT="Arial",11
**************** Ops(3) ****************
Ops(3).POSITION=173,137
Ops(3).SIZE=34,28
Ops(3).VISIBLE=TRUE
Ops(3).ENABLED=TRUE
Ops(3).BACKCOLOR=$c0c0c0
Ops(3).TEXT="*"
Ops(3).TEXTCOLOR=$ff
Ops(3).FONT="Arial",11
**************** Ops(4) ****************
Ops(4).POSITION=212,137
Ops(4).SIZE=34,28
Ops(4).VISIBLE=TRUE
Ops(4).ENABLED=TRUE
Ops(4).BACKCOLOR=$c0c0c0
Ops(4).TEXT="%"
Ops(4).TEXTCOLOR=$800000
Ops(4).FONT="Arial",11
**************** Ops(5) ****************
Ops(5).POSITION=173,170
Ops(5).SIZE=34,28
Ops(5).VISIBLE=TRUE
Ops(5).ENABLED=TRUE
Ops(5).BACKCOLOR=$c0c0c0
Ops(5).TEXT="-"
Ops(5).TEXTCOLOR=$ff
Ops(5).FONT="Arial",11
**************** Ops(6) ****************
Ops(6).POSITION=212,170
Ops(6).SIZE=34,28
Ops(6).VISIBLE=TRUE
Ops(6).ENABLED=TRUE
Ops(6).BACKCOLOR=$c0c0c0
Ops(6).TEXT="1/x"
Ops(6).TEXTCOLOR=$800000
Ops(6).FONT="Arial",11
**************** Ops(7) ****************
Ops(7).POSITION=173,203
Ops(7).SIZE=34,28
Ops(7).VISIBLE=TRUE
Ops(7).ENABLED=TRUE
Ops(7).BACKCOLOR=$c0c0c0
Ops(7).TEXT="+"
Ops(7).TEXTCOLOR=$ff
Ops(7).FONT="Arial",11
**************** Ops(8) ****************
Ops(8).POSITION=212,203
Ops(8).SIZE=34,28
Ops(8).VISIBLE=TRUE
Ops(8).ENABLED=TRUE
Ops(8).BACKCOLOR=$c0c0c0
Ops(8).TEXT="="
Ops(8).TEXTCOLOR=$ff
Ops(8).FONT="Arial",11
**************** table ****************
CONSTRUCT table AS Table
table.POSITION=9,240
table.SIZE=235,112
table.VISIBLE=TRUE
table.ENABLED=TRUE
table.BACKCOLOR=$ffffff
**************** TextField1 ****************
CONSTRUCT TextField1 AS TextField
TextField1.POSITION=8,32
TextField1.SIZE=236,28
TextField1.VISIBLE=TRUE
TextField1.ENABLED=TRUE
TextField1.BACKCOLOR=$ffffff
TextField1.TEXT="0"
TextField1.TEXTCOLOR=$0
TextField1.FONT="Arial",11
**************** MemW ****************
CONSTRUCT MemW AS TextField
MemW.POSITION=15,70
MemW.SIZE=24,22
MemW.VISIBLE=TRUE
MemW.ENABLED=TRUE
MemW.BACKCOLOR=$ffffff
MemW.TEXT=""
MemW.TEXTCOLOR=$0
MemW.FONT="Helvetica",8
************ Initialize ************
table.tablesize=100,3
table.backcolor=OBYellow
table.gridcolor=OBGray
table.shadowcolor=OBMint
table.textcolor=OBDkGreen
table.selbackcolor=OBViolet
table.seltextcolor=OBYellow
table.colwidth=0,100
table.colwidth=1,20
table.colwidth=2,100
table.fixedrowstop=0
table.fixedrowsbottom=0
table.fixedcolsleft=0
table.width = 238
for i=0 to 99
	table.rowheight=i,15
next i
tablepointer = 0
firstoperand = 0
DECIMALS 5
OBMain.Text = "Calculator"
************ Functions ************
*************************************************
NumAction
*************************************************
if opflag<>0 then
	opflag=0
	display=""
endif
IF OBSel=2 THEN
	display = str$(FVAL(display)*(-1))
ELSE
	tempstr=Num(OBSel).text
	display=display+tempstr
ENDIF
cur = VAL(display)   \variable cur equals display
TextField1.text=display   \puts display in text field
Return
*************************************************
EditAction
*************************************************
Select Case OBSel
	Case BackSpace
		tempstr = display
		IF LEN(tempstr)>1 THEN
			display = LEFT$(tempstr,(LEN(tempstr)-1))
			TextField1.text = display
		ENDIF
	Case CE
		display="0"
		TextField1.text=display
		cur = 0
		x=0
	Case C
		display = "0"
		TextField1.text=display
		cur = 0
		x=0
		acc = 0
		pendingop = 0   \clears pending operation array
		firstoperand = 0
		for i = 0 to 99
			table.textmatrix = i,0,""   \clears table
			table.textmatrix = i,1,""
			table.textmatrix = i,2,""
		next i
		row = 0
End Select
Return
*************************************************
MemAction
*************************************************
Select Case OBSel
	Case MC
		memory = 0
		MemW.text = " "
	Case MR
		cur = memory
		display = str$(cur)
		TextField1.text=display
	Case MS
		memory = FVAL(display)
		MemW.text = "   M"
	Case MA
		memory = memory+FVAL(display)
		MemW.text = "   M"
End Select
Return
*************************************************
OpsAction
*************************************************
display=TextField1.text
x=val(display)
*getdisplay()
opflag=$ff
*The first row of table takes a special case
IF row = 0 then
	IF firstoperand = 0 then
		table.textmatrix = row,0,str$(cur)   \puts current display in 1st row, 1st & 3rd col's
		table.textmatrix = row,2,str$(cur)
	ELSE
		table.textmatrix = row+1,0,str$(cur)   \puts successive displays in next row down
	ENDIF
ELSE
	table.textmatrix = row,0,str$(cur)
	table.textmatrix = row,2,str$(cur)
END IF
pendingop = OBSel   \key selection becomes pending operation
displayoperator = Ops(pendingop).text
table.textmatrix = row,1,displayoperator   \displays operation in center col
opnumarray(row) = pendingop   \puts pending operation in an array
*All Rows after the first one solves and places the result on the
*next row, first column. The first row doesn't solve until after
*the second operator.
IF row > 0 Then   \after first row, it's necessary to always perform the previous operation
	SELECT CASE opnumarray(row-1)
		case add
			tmp1= table.textmatrix(row,0)  \typ example of current display operating on previous result
			tmp2 = table.textmatrix(row-1,2)
			ftmp1=fval(tmp1)
			ftmp2=fval(tmp2)
			acc=ftmp1 + ftmp2
		case sub
			tmp1= table.textmatrix(row,0)
			tmp2 = table.textmatrix(row-1,2)
			ftmp1=fval(tmp1)
			ftmp2=fval(tmp2)
			acc=ftmp2 - ftmp1
		case div
			tmp1= table.textmatrix(row,0)
			tmp2 = table.textmatrix(row-1,2)
			ftmp1=fval(tmp1)
			ftmp2=fval(tmp2)
*		  * Test for divide by zero condition
		  IF ftmp1<>0 THEN
			acc=ftmp2/ftmp1
		  ELSE
			TextField1.text = "Attempted divide by zero"
		  ENDIF
		case mul
			tmp1= table.textmatrix(row,0)
			tmp2 = table.textmatrix(row-1,2)
			ftmp1=fval(tmp1)
			ftmp2=fval(tmp2)
			acc=ftmp1 * ftmp2
		case sq
			tmp1= table.textmatrix(row,0)
			ftmp1=fval(tmp1)
			acc=SQR(ftmp1)
		case percent
			tmp1= table.textmatrix(row,0)
			tmp2 = table.textmatrix(row-1,2)
			ftmp1=fval(tmp1)
			ftmp2=fval(tmp2)
			tempfloat = ftmp2/100
			acc = ftmp1 * tempfloat
		case inverse
			tempfloat = FVAL(display)
			acc=tempfloat/1
			display = str$(acc)
			TextField1.text = display
	END SELECT
	table.textmatrix = row,2,str$(acc)
ELSE
	acc=cur   \for first row, the current value becomes the accumulated value
ENDIF
firstoperand = 1
row = row + 1
IF row = 100 then
	row = 0
ENDIF
display=str$(acc)   \displays accumulated value
TextField1.text=display
Return
************ Events ************
REM *** Number Keys 
Num.click
Gosub NumAction
EXIT EVENT
REM *** Edit Keys
Edit.click
Gosub EditAction
Exit Event
REM *** Memory Keys
Mem.click
Gosub MemAction
Exit Event
REM *** Operations Keys
Ops.click
Gosub OpsAction
Exit Event
OBMain.keydown
keystrip=OBCode
IF OBCode > $ffaf AND OBCode< $ffba Then
	keystrip = OBCode - $ffb0
Endif
IF OBCode >$2f AND OBCode < $3a Then
	keystrip= OBCode - $30
Endif
IF OBCode=$ff0d OR OBCode=$3d THEN
	keystrip=$3d
ENDIF
IF OBCode>$ffa9 AND OBCode<$ffb0 THEN
	keystrip=OBCode-$ff80
ENDIF
IF keystrip < 10 AND keystrip > 0 THEN
Num(keystrip+3).state = 1
OBSel = keystrip+3
Gosub NumAction
ENDIF
If keystrip = 0 THEN
Num(1).state = 1
OBSel = 1
Gosub NumAction
ENDIF
IF keystrip >9 THEN
	Select Case keystrip
		Case $2f \ divide key /
			OBSel=1
			Ops(1).state=1
			Gosub OpsAction
		Case $2e \ decimal key .
			OBSel=3
			Num(3).state=1
			Gosub NumAction
		Case $2d \ minus key -
			OBSel=5
			Ops(5).state=1
			Gosub OpsAction
		Case $2b \ plus key +
			OBSel=7
			Ops(7).state=1
			Gosub OpsAction
		Case $2a \ multiply key *
			OBSel=3
			Ops(3).state=1
			Gosub OpsAction
		Case $3d \ equal key =
			OBSel=8
			Ops(8).state=1
			Gosub OpsAction
		Case $d \ Enterkey
			OBSel=8
			Ops(8).state=1
			Gosub OpsAction
		Case $25 \ percent key %
			OBSel=4
			Ops(4).state=1
			Gosub OpsAction
		Case $ff1b \ Esc key for clear
			OBSel=3
			Edit(3).state=1
			Gosub EditAction
		Case $ffff \ Del key for Clear Entry
			OBSel=2
			Edit(2).state=1
			Gosub EditAction
		Case $ff08 \ Backspace key
			OBSel=1
			Edit(1).state=1
			Gosub EditAction
	EndSelect
EndIf
keystrip =$ff & OBCode
MemW.Text=HEX$(keystrip)
Exit Event
OBMain.keyup
For i=1 to 12
	If i <4 THEN
		Edit(i).state=0
	ENDIF
	If i < 5 THEN
		Mem(i).state=0
	ENDIF
	If i <9 THEN
		Ops(i).state=0
	ENDIF
	Num(i).state=0
Next i
Exit Event


The following are examples of actual OmniBasic code in Console Mode.

 A simple program to "list" text files.            A formatted hexadecimal file dump program.

********************************
* PROGRAM: lst                *
* Lists a file and adds line *
* numbers                       *
********************************
dim InpFile:byte
dim Buf:string[300]
dim LineNum:short
Start
LineNum=0
Buf=NextArg
if len(Buf)=0 then
    print "No file specified"
    end
endif
on error goto BadFile
open #InpFile,Buf:read
on error
while not(eof(#InpFile)) do
    read #InpFile,Buf
    inc LineNum
    print right$(zstr$(LineNum),5);" ";Buf
endwhile
end
BadFile
print "Cannot open ";Buf
* FDUMP File Dump Program provides formatted hexadecimal dump of file

  DIM Character:BYTE
  DIM FileNum:BYTE
  DIM FileName:STRING[32]
  DIM ByteCtr:LONG
  DIM AddrCtr:LONG
  DIM ASCII:STRING[16]
  DIM Hex:STRING[60]
  DIM LineCtr:LONG
  DIM HitEnter:STRING[1]

  AddrCtr=0
  LineCtr=0
  ON ERROR GOTO BadFile
  FileName=NextArg
  IF len(FileName)=0 THEN Help
  IF FileName="-?" OR FileName="--help" THEN Help
  OPEN #FileNum,FileName:READ+BINARY
  Lp1
  ByteCtr=0
  ASCII=" "
  Hex=ZHEX$(AddrCtr)+" "
  AddrCtr=AddrCtr+16
  Lp2
  GOSUB GetByte
  IF STATUS<1 THEN
        IF ByteCtr>0 THEN
             GOSUB Display
       ENDIF
       CLOSE #FileNum
       END
  ENDIF
  INC ByteCtr
  IF Character>$1f AND Character<$7f THEN
      MID$(ASCII,ByteCtr,1)=CHR$(Character)
  ELSE
      MID$(ASCII,ByteCtr,1)="."
  ENDIF
  Hex=Hex+RIGHT$(ZHEX$(Character),2)+" "
  IF ByteCtr=16 THEN
      GOSUB Display
      GOTO Lp1
  ENDIF
  GOTO Lp2

  Display
  PRINT Hex;TAB(60);ASCII
  INC LineCtr
  IF LineCtr=16 THEN
       LineCtr=0
       INPUT "Hit ENTER to continue>",HitEnter
  ENDIF
  RETURN

  GetByte
  GET #FileNum,Character
  RETURN

BadFile
      PRINT "Cannot open ";FileName
  END

Help
  PRINT
  PRINT "fdump FileName"
  PRINT
  PRINT "Performs hexadecimal and ASCII dump of file specified"
  PRINT
  END

Home || Why Omnibasic || Features || FAQ || Examples
Reviews || Links || Privacy Statement || Top of Page

 

   Innomation Systems, Inc.

117 Morrison Ave. Morrison, MO 65061 (573) 294-6130

OmniBasic is a trademark of Innomation Systems, Inc., other trademarks are the property of their respective owners.
Innomation Systems, Inc. reserves the right to change prices and specifications without prior notice.
Copyright © 2000, 2001, 2002 Innomation Systems, Inc.