Post by meerkat on May 20, 2019 18:11:58 GMT -5
Being a novice to LB, I wanted a input form that was easy to use. I tried the form that comes with LB, but for large input forms it takes a long time.
So I wrote a program that uses a editable input file.
Seemed to work ok for my purposes, so I decided to post the code if anyone was interested.
This is the first cut so there may be some errors
Please post any errors.
Hope this helps..
Dan
The docs:
Program:
Sample input:
sample generated output
So I wrote a program that uses a editable input file.
Seemed to work ok for my purposes, so I decided to post the code if anyone was interested.
This is the first cut so there may be some errors
Please post any errors.
Hope this helps..
Dan
The docs:
VID 5 interface Design..
This generates a window based on a command file
These Commands direct VID layout
row {+/-}n | +n will increase the current row by n
| -n will decrease the current row by n
| n will set current row to n
col {+/-}n | +n will increase the current column by n
| -n will decrease the current column b n
| n will set the current column to n
window (wxh) | set the current window width to w
| and the window height to h
| default window width is 1000
| default window height is 800
lm n | set the current left margin to n
rm n | set the right margin to n spaces from the window width
return | returns the current col to left margin
| and the current row plus the previous facet height
style name | creates a style called name
| styles can have (wwxhh) for width and height as (100x200)
| align=left align=right align=center
| example style xxx (100,20) align=right
| *will be adding fonts and colors in the future
-------------|-------------------------------------
Faces | all widths and heights are enclosed in ()
| a x separating the width and height as in (200x50)
| all labels are enclosed in [] or {}
| [] enclosed are labels with brackets.. such as [chkName]
| {} enclosed are labels without brackets.. such as {chkName}
|
| faces can refer to a style as face/xxx where xxx is the style name
|
-------------+------------------+------------------------------------------------------------------------
Example faces |
window "Test Window" (800x600) | describes a window named "Test Window" that is 800 wide and 600 high
style xxx (200x20) align=right | defines a style names xxx that is 200 wide and 20 high aligned to the right
statictext/xxx "User Name" | generates static test using style xxx.
textbox (150) | generates a textbox that is 150 pixels wide
listbox ary$() [lb1] (100x200) | generates a listbox that uses ary$() for values and goes program
| [lb1] when clicked and is 100 pixels wide and 200 pixels down
checkbox "Chk Me" [ch1] [ck2] | generates a checkbox with name "Chk Me"
| goes to label [ch1] to set and [chk2] to reset
texteditor (300x100) | generates a texteditor box that is 300 pixels wide and 100 pixels high
--------------------------------+-----------------------------------------------------------------------
Program:
' -----------------------------------------------
' VID Five (V) interface Design
' -----------------------------------------------
dim sty$(30)
dim sty1$(30)
winWi = 1000 ' window width default
winHi = 800 ' window height default
lm = 1 ' left margin
rm = 1 ' right margin
hi = 20 ' row height
lf$ = chr$(10)
cr$ = chr$(13)
tab$ = chr$(9)
q$ = chr$(34)
curCol = 1
curRow = 1
' -----------------------------------------------
' faces
' -----------------------------------------------
'facet |id|cap|ary|b1|b2|ul|wid|hig|
faces$ = "
window |wi| Y | N |N |N |N |800|600|
button |bt| Y | N |Y |N |Y | 40| 20|
statictext |st| Y | N |N |N |N | 40| 20|
groupbox |gp| Y | N |N |N |N |100|100|
combobox |cb| N | Y |Y |N |N | 80| 20|
listbox |lb| N | Y |Y |N |N | 80| 20|
checkbox |cb| Y | N |Y |Y |N | 80| 20|
radiobutton|rb| Y | N |Y |Y |N | 5| 20|
textbox |tb| N | N |N |N |N | 40| 20|
texteditor |te| N | N |N |N |N |200|100|
"
while instr(faces$," ") > 0
faces$ = strRep$(faces$," ","")
wend
dim face$(11)
for i = 1 to 11
face$(i) = word$(faces$,i,cr$)
next i
print tab$;"VID Five Interface Design"
' -----------------------------------------------
' user input param
' -----------------------------------------------
filedialog "Find a VID File", "*.*", vid$
if vid$ = "" then
notice "No VID file selected. Thank you and have a great day!"
end
end if
print "VID: ";vid$;" window View Interface Design"
' -------------------------------
' open file input
' -------------------------------
[filOpen]
OPEN vid$ FOR INPUT as #f
[loop]
if eof(#f) <> 0 then [inpEnd]
line input #f, x$
a$ = a$ + x$ + cr$
goto [loop]
[inpEnd]
close #f
' ------------- Output file ------------
fileOut$ = word$(vid$,1,".") + "Out.vid"
print "Output VID file:";fileOut$
OPEN fileOut$ for OUTPUT as #f
' ---------------------------------------------------------
' make string of individual commands
' with <CR> between each command
' and chr$(251) at end
' a1$ will have single commands per line with <CR> at tne
' ---------------------------------------------------------
qt$ = "cc" ' encounter quote [Y]es or [cc]o
a$ = strRep$(a$," "," ")
a$ = a$ + cr$ + chr$(251) + cr$
for i = 1 to len(a$)
x$ = mid$(a$,i,1)
if x$ = chr$(9) then x$ = " " ' make tabs into space
if x$ = "'" or x$ = """" then ' found quote so don look for (:) between quotes
x$ = """" ' and convert single qoute (') to double (")
if qt$ = "Y" then
qt$ = "cc"
else
qt$ = "Y"
end if
end if
if qt$ = "cc" and x$ = ":" then x$ = chr$(13)
a1$ = a1$ + x$
next i
print "============ VID file input ====================="
print a1$
' --------------------------------------------
' read each command line and
' layout the form based on data on each
' command line
' --------------------------------------------
for i = 1 to len(a1$)
a$ = trim$(word$(a1$,i,chr$(13)))
if instr(a$,chr$(251)) <> 0 then exit for
if a$ = cr$ then goto [nxtCmd]
if a$ = "" then goto [nxtCmd]
la$ = lower$(a$)
cmd$ = word$(la$,1," ")
if instr(cmd$,"/") then
style$ = word$(cmd$,2,"/")
cmd$ = word$(cmd$,1,"/")
for j = 1 to numSty
if style$ = sty$(j) then
a$ = a$ + " " + sty1$(j)
la$ = lower$(a$)
exit for
end if
next j
end if
lCmd$ = lower$(cmd$)
' ---------- row position ----------
if lCmd$ = "row" then
x$ = word$(a$,2," ")
row = val(x$)
if left$(x$,1) = "+" then
row = val(mid$(x$,2))
curRow = curRow + row
goto [nxtCmd]
end if
if left$(x$,1) = "-" then
curRow = curRow - row
goto [nxtCmd]
end if
curRow = row
goto [nxtCmd]
end if
' ---------- col position ----------
if lCmd$ = "col" then
x$ = word$(a$,2," ")
col = val(x$)
if left$(x$,1) = "+" then
col = val(mid$(x$,2))
curCol = curCol + col
if curCol > winWi - rm then curRow = curRow + preHi
goto [nxtCmd]
end if
if left$(x$,1) = "-" then
curCol = curCol - col
curCol = max(lm,curCol)
goto [nxtCmd]
end if
curCol = col
goto [nxtCmd]
end if
' ----------------------------------------
' gets value in (ccxrr)
' could be width x height
' or col x row
' ----------------------------------------
cc = -1
rr = -1
if instr(a$,"(") > 0 then
ccrr$ = word$(a$,2,"(")
x$ = word$(a$,1,"(")
if right$(x$,1) = "$" then
ccrr$ = word$(a$,3,"(")
if x$ = "" then goto [nocc]
end if
ccrr$ = lower$(ccrr$)
ccrr$ = word$(ccrr$,1,")") + "x"
cc$ = trim$(word$(ccrr$,1,"x"))
rr$ = trim$(word$(ccrr$,2,"x"))
if cc$ <> "" then cc = val(cc$)
if rr$ <> "" then rr = val(rr$)
end if
[nocc]
' -------------------------------
' layout commands
' -------------------------------
' ---------- lm left margin ----------
if lCmd$ = "lm" then
lm = val(word$(a$,2," "))
curCol = max(lm,curCol)
goto [nxtCmd]
end if
' ---------- rm right margin ----------
if lCmd$ = "rm" then
rm = val(word$(a$,2," "))
if curCol > winWi - rm then
curCol = lm
curRow = curRow + hi
end if
goto [nxtCmd]
end if
' ---------- return ----------
if lCmd$ = "return" then
curCol = lm
curRow = curRow + hi
goto [nxtCmd]
end if
' ---------- style----------
if lCmd$ = "style" then
a$ = trim$(mid$(a$,6))
st$ = lower$(word$(a$,1," "))
j = instr(a$," ")
st1$ = trim$(mid$(a$,j+1)) + " "
numSty = numSty + 1
sty$(numSty) = st$
sty1$(numSty) = st1$
goto [nxtCmd]
end if
' --------------------------------
' layout commands
' --------------------------------
for j = 1 to 11
if lCmd$ = word$(face$(j),1,"|") then
faceCmd$ = word$(face$(j),1,"|")
exit for
end if
next j
if lCmd$ <> faceCmd$ then
print "** Unknown command ";a$
goto [nxtCmd]
end if
faceCd$ = word$(face$(j),2,"|")
caption$ = word$(face$(j),3,"|")
array$ = word$(face$(j),4,"|")
branch1$ = word$(face$(j),5,"|")
branch2$ = word$(face$(j),6,"|")
ul$ = word$(face$(j),7,"|")
defWide$ = word$(face$(j),8,"|")
defWide = val(defWide$)
defHigh$ = word$(face$(j),9,"|")
defHigh = val(defHigh$)
'----- need caption ?
bq = 0 ' begin quote
eq = 0 ' end quote
if caption$ = "Y" then ' does it need a caption
bq = instr(a$,"""") ' begin quote location
eq = instr(a$,"""",bq +1) ' end quote location
if eq = 0 then
print "** Layout needs a caption between quotes ";a$
goto [nxtCmd]
end if
cap$ = mid$(a$,bq+1,eq - bq -1)
a$ = strRep$(a$,cap$,"")
end if
' ---------- window ----------
if lCmd$ = "window" then
if cc = -1 then cc = 800
if rr = -1 then rr = 600
print #f, "WindowWidth = ";cc
print #f, "WindowHeight = ";rr
winWi = cc
winHi = rr
openWin$ = "open """;cap$;""" for window as #w"
goto [nxtCmd]
end if
'----- need array ?
ary$ = ""
if array$ = "Y" then
j = instr(a$,"$(")
if j = 0 then
print "** Need array defined for this command:";a$
goto [nxtCmd]
end if
ary$ = ""
for k = j to 1 step -1
if mid$(a$,k,1) = " " or k = 1 then
x$ = mid$(a$,k)
ary$ = trim$(word$(x$,1,")"))
ary$ = ary$ + ")"
exit for
end if
next k
if ary$ = "" then
print "** Need array defined ";a$
goto [nxtCmd]
end if
end if
' ----- need branch 1 label
br1$ = ""
br2$ = ""
' branches may be enclosed in {} for sub or [] for label
if branch1$ = "Y" then
gosub [getBranch]
if b1$ = "" then
print "** Need branch label ;";a$
goto [nxtCmd]
end if
br1$ = b1$
end if
if branch2$ = "Y" then
gosub [getBranch]
if b1$ = "" then
print "** Need second branch label ;";a$
goto [nxtCmd]
end if
br2$ = b1$
end if
' -----------------------------
' create layout
' -----------------------------
seq = seq + 1
print #f, align$(lCmd$,12,"l");"#w.";faceCd$;fmt$(seq);
if caption$ = "Y" then
if cc > 0 then wi = cc else wi = len(cap$) * 10
else
if cc > 0 then wi = cc else wi = defHigh
end if
if rr > 0 then hi = rr else hi = defHigh
if caption$ = "Y" then
if instr(la$,"align=r") then cap$ = align$(cap$,wi/10,"r")
if instr(la$,"align=l") then cap$ = align$(cap$,wi/10,"l")
if instr(la$,"align=c") then cap$ = align$(cap$,wi/10,"c")
print #f, tab$;",";q$;cap$;q$;
else
print #f, tab$;tab$;
end if
if array$ = "Y" then
print #f, tab$;",";ary$;
dims$ = dims$ + cr$ + "'--- #w.";faceCd$;fmt$(seq)+ cr$ + "dim ";word$(ary$,1,")") + "10)"
else
print #f, tab$;
end if
if branch1$ = "Y" then
print #f, " ,";br1$;
brch$ = brch$ + cr$ + "'--- #w.";faceCd$;fmt$(seq)+ cr$ + br1$ + cr$ + "' do something" + cr$ + "wait" + cr$
else
print #f, tab$;
end if
if branch2$ = "Y" then
print #f, " ,";br2$;
brch$ = brch$ + cr$ + "'--- #w.";faceCd$;fmt$(seq)+ cr$ + br2$ + cr$ + "' do something" + cr$ + "wait" + cr$
else
print #f, tab$;
end if
if ul$ = "Y" then
print #f, tab$;",UL";
else
print #f, tab$;
end if
if curCol + wi > winWi - rm then ' does current column exceed width of window
curCol = lm ' if it does - go back to the left margin
curRow = curRow + preHi ' and go down a row based on the previous height
end if
preHi = hi
print #f, tab$;",";fmt$(curCol);",";fmt$(curRow);",";fmt$(wi);",";fmt$(hi)
if faceCmd$ = "groupbox" then hi = 20
'if faceCmd$ = "listbox" then hi = 20
[nxtCmd]
curCol = curCol + wi
wi = 0
next i
print #f, openWin$
print #f, "print #w, ""font Courier New 10 bold"""
print #f, dims$
print #f, brch$
print #f, "'--- ejoj" + cr$ + "end"
close #f
print "===== VID Complete ======="
print "Output VID file:";fileOut$
print " Have a great day!"
end
' -----------------------------------
' get branch babel from cmd line a$
' -----------------------------------
[getBranch]
b1$ = word$(a$,2,"{")
b1$ = word$(b1$,1,"}")
if b1$ <> "" then
i = instr(a$,"{")
a$ = left$(a$,i-1) + mid$(a$,i+1) ' get rid of "{"
end if
if b1$ = "" then
b1$ = word$(a$,2,"[")
b1$ = word$(b1$,1,"]")
if b1$ <> "" then
b1$ = "[" + b1$ + "]"
i = instr(a$,"[")
a$ = left$(a$,i-1) + mid$(a$,i+1) ' get rid of "["
end if
end if
RETURN
' --------------------------------
' string replace rep str with
' --------------------------------
FUNCTION strRep$(str$,rep$,with$)
ln = len(rep$)
ln1 = ln - 1
i = 1
while i <= len(str$)
if mid$(str$,i,ln) = rep$ then
strRep$ = strRep$ + with$
i = i + ln1
else
strRep$ = strRep$ + mid$(str$,i,1)
end if
i = i + 1
WEND
END FUNCTION
' --------------------------
' zero fill positions
' --------------------------
FUNCTION fmt$(fld)
fmt$ = str$(fld)
ln = len(fmt$)
ln = max(ln,3)
fmt$ = right$("000000";str$(fld),ln)
END FUNCTION
' -------------------------------------
' Align fld$ to left right or center
' of a given width
' -------------------------------------
FUNCTION align$(fld$,width,lrc$)
f = len(fld$)
s = width - f
if s < 1 then
align$ = fld$
else
b$ = space$(width)
if lrc$ = "l" then align$ = fld$;left$(b$,s)
if lrc$ = "r" then align$ = left$(b$,s);fld$
if lrc$ = "c" then align$ = left$(b$,int(s / 2));fld$;left$(b$,int(s / 2) + (s and 1))
end if
END FUNCTION
Sample input:
style xxx (200x20) align=right
lm 10
rm 10
window "Test Window" (800x800)
statictext/xxx "User Num" :textbox (60) :return
statictext/xxx "User Name" :textbox (120) :return
statictext/xxx "Address" :textbox (200) :return
statictext/xxx "City" :textbox (120) :return
statictext/xxx "State Id" :listbox stateId$() [stateId] (100x90) :return
statictext/xxx "Email Address" :textbox (200) :return
statictext/xxx "Phone" :textbox (150) :return
statictext/xxx "Date/Time" :textbox (150) :return
statictext/xxx "Notes:" :texteditor (90x110) :return
col 200
button "Add" [add]
button "Chg" [chg]
button "Del" [del]
button "Exit" [exit]
return
statictext "--- End of userFile Info" (500) align=center :return
listbox array$() [listb1] (100x200) :return
statictext "--- End of listbox ----" :return
checkbox "Check my Box" [ch1] [ck2]
statictext "Editor"
texteditor (300x100) :return
statictext " --------- text editor --------" :return
statictext "-One>" :statictext "-Two>" :statictext "-Three>" :statictext "-Four>" :statictext "-Five>"
statictext "-Six>" :statictext "-Seven>" :statictext "-Eight>" :statictext "-Nine>" :statictext "-ten>"
statictext "-Eleven>" :statictext "-Twelve>" :statictext "-Thirteen>" :statictext "-Fourteen>" :statictext "-Fifteen>"
return
checkbox "Check Box 1" [chk1] [chk11]
checkbox "Check Box 2" [chk2] [chk22]
checkbox "Check Box 3" [chk3] [chk33]
checkbox "Check Box 4" [chk4] [chk44]
checkbox "Check Box 5" [chk5] [chk55]
:return
sample generated output
WindowWidth = 800
WindowHeight = 800
statictext #w.st001 ," User Num" ,010,001,200,020
textbox #w.tb002 ,210,001,060,020
statictext #w.st003 ," User Name" ,010,021,200,020
textbox #w.tb004 ,210,021,120,020
statictext #w.st005 ," Address" ,010,041,200,020
textbox #w.tb006 ,210,041,200,020
statictext #w.st007 ," City" ,010,061,200,020
textbox #w.tb008 ,210,061,120,020
statictext #w.st009 ," State Id" ,010,081,200,020
listbox #w.lb010 ,stateId$() ,[stateId] ,210,081,100,090
statictext #w.st011 ," Email Address" ,010,171,200,020
textbox #w.tb012 ,210,171,200,020
statictext #w.st013 ," Phone" ,010,191,200,020
textbox #w.tb014 ,210,191,150,020
statictext #w.st015 ," Date/Time" ,010,211,200,020
textbox #w.tb016 ,210,211,150,020
statictext #w.st017 ," Notes:" ,010,231,200,020
texteditor #w.te018 ,210,231,090,110
button #w.bt019 ,"Add" ,[add] ,UL ,200,341,030,020
button #w.bt020 ,"Chg" ,[chg] ,UL ,230,341,030,020
button #w.bt021 ,"Del" ,[del] ,UL ,260,341,030,020
button #w.bt022 ,"Exit" ,[exit] ,UL ,290,341,040,020
statictext #w.st023 ," --- End of userFile Info " ,010,361,500,020
listbox #w.lb024 ,array$() ,[listb1] ,010,381,100,200
statictext #w.st025 ,"--- End of listbox ----" ,010,581,230,020
checkbox #w.cb026 ,"Check my Box" ,[ch1] ,[ck2] ,010,601,120,020
statictext #w.st027 ,"Editor" ,130,601,060,020
texteditor #w.te028 ,190,601,300,100
statictext #w.st029 ," --------- text editor --------" ,010,701,310,020
statictext #w.st030 ,"-One>" ,010,721,050,020
statictext #w.st031 ,"-Two>" ,060,721,050,020
statictext #w.st032 ,"-Three>" ,110,721,070,020
statictext #w.st033 ,"-Four>" ,180,721,060,020
statictext #w.st034 ,"-Five>" ,240,721,060,020
statictext #w.st035 ,"-Six>" ,300,721,050,020
statictext #w.st036 ,"-Seven>" ,350,721,070,020
statictext #w.st037 ,"-Eight>" ,420,721,070,020
statictext #w.st038 ,"-Nine>" ,490,721,060,020
statictext #w.st039 ,"-ten>" ,550,721,050,020
statictext #w.st040 ,"-Eleven>" ,600,721,080,020
statictext #w.st041 ,"-Twelve>" ,680,721,080,020
statictext #w.st042 ,"-Thirteen>" ,010,741,100,020
statictext #w.st043 ,"-Fourteen>" ,110,741,100,020
statictext #w.st044 ,"-Fifteen>" ,210,741,090,020
checkbox #w.cb045 ,"Check Box 1" ,[chk1] ,[chk11] ,010,761,110,020
checkbox #w.cb046 ,"Check Box 2" ,[chk2] ,[chk22] ,120,761,110,020
checkbox #w.cb047 ,"Check Box 3" ,[chk3] ,[chk33] ,230,761,110,020
checkbox #w.cb048 ,"Check Box 4" ,[chk4] ,[chk44] ,340,761,110,020
checkbox #w.cb049 ,"Check Box 5" ,[chk5] ,[chk55] ,450,761,110,020
open "Test Window" for window as #w
print #w, "font Courier New 10 bold"
'--- #w.lb010
dim stateId$(10)
'--- #w.lb024
dim array$(10)
'--- #w.lb010
[stateId]
' do something
wait
'--- #w.bt019
[add]
' do something
wait
'--- #w.bt020
[chg]
' do something
wait
'--- #w.bt021
[del]
' do something
wait
'--- #w.bt022
[exit]
' do something
wait
'--- #w.lb024
[listb1]
' do something
wait
'--- #w.cb026
[ch1]
' do something
wait
'--- #w.cb026
[ck2]
' do something
wait
'--- #w.cb045
[chk1]
' do something
wait
'--- #w.cb045
[chk11]
' do something
wait
'--- #w.cb046
[chk2]
' do something
wait
'--- #w.cb046
[chk22]
' do something
wait
'--- #w.cb047
[chk3]
' do something
wait
'--- #w.cb047
[chk33]
' do something
wait
'--- #w.cb048
[chk4]
' do something
wait
'--- #w.cb048
[chk44]
' do something
wait
'--- #w.cb049
[chk5]
' do something
wait
'--- #w.cb049
[chk55]
' do something
wait
'--- ejoj
end