Older Version
Newer Version
JanetTerra
Nov 13, 2008
Those tiny buttons--we've all seen them when searching for fonts, clip-art, midis--anytime a large amount of data needs to be narrowed down to make a selection easier. It's always best to follow common conventions because the user immediately has an idea of what to do and what to expect.
Trying to zero-in on a selection in a listbox containing a large amount of data is difficult. The scroll arrows are too slow and the scroll slider is too fast and jerky. Once the number of items is filtered and reduced the scrollbar action becomes much smoother.
The entire generated list of names is loaded into masterList$() and everytime a letter is selected all 5,000 names are parsed and the names are placed into displayList$ and displayed. It shows how fast Liberty Basic can work with 'giant' strings.
Each time the masterList$() is parsed the filtered results are accurately counted. When the report is generated the count for each letter is stored in nameCount() and a running tally is assigned to totalNames.
I have illustrated how to send messgaes to the user directly into the listbox. Personally, I find the overuse of Notice and Dialog_Modal annoying. People need to know that something IS happening so they don't start clicking buttons to make it do something. Updated messages are also sent to the 'faux' statusbar, created using only native Liberty Basic controls. (The status bar idea is only one of the many great tips shared by the Liberty Basic community on conforums, yahoogroups and the fantastic newsletters.)
So many times when trying out a program I've spent a lot of time entering data only to find it didn't do what I expected or worse--the data simply evaporated. A random data generator is a handy item to keep in the tool box. It can be easily modified. For those more serious about randomization the generated report should give an indication of the usefullness/limitation of the algorithm used.
Enjoy and modify as you wish :-) -
JamesRedifer
Trying to zero-in on a selection in a listbox containing a large amount of data is difficult. The scroll arrows are too slow and the scroll slider is too fast and jerky. Once the number of items is filtered and reduced the scrollbar action becomes much smoother.
The entire generated list of names is loaded into masterList$() and everytime a letter is selected all 5,000 names are parsed and the names are placed into displayList$ and displayed. It shows how fast Liberty Basic can work with 'giant' strings.
Each time the masterList$() is parsed the filtered results are accurately counted. When the report is generated the count for each letter is stored in nameCount() and a running tally is assigned to totalNames.
I have illustrated how to send messgaes to the user directly into the listbox. Personally, I find the overuse of Notice and Dialog_Modal annoying. People need to know that something IS happening so they don't start clicking buttons to make it do something. Updated messages are also sent to the 'faux' statusbar, created using only native Liberty Basic controls. (The status bar idea is only one of the many great tips shared by the Liberty Basic community on conforums, yahoogroups and the fantastic newsletters.)
So many times when trying out a program I've spent a lot of time entering data only to find it didn't do what I expected or worse--the data simply evaporated. A random data generator is a handy item to keep in the tool box. It can be easily modified. For those more serious about randomization the generated report should give an indication of the usefullness/limitation of the algorithm used.
Enjoy and modify as you wish :-) -
' ALPHABET BUTTONS 5000
' "Quit" subs by Janet Terra
' Random name generator inspired by the "Buzz phrase generator" by JohnnyD
Dim masterList$(5000)
Dim displayList$(5000)
Dim nameCount(26)
Global sortem$, report
displayList$(1) = " Generating 5000 names" 'Always explain the delay
displayList$(2) = " and loading arrays."
displayList$(3) = " Please wait!"
Nomainwin
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0
WindowWidth = 230
WindowHeight = 400
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
Menu #main, "&File", "E&xit", quitByMenu
Listbox #main.namesList, displayList$(, showName, 15, 5, 195, 248
Button #main.showAll, "Show All", show5K, UL, 15, 292, 60, 25
Button #main.addAll, "Report", showReport, UL, 83, 292, 60, 25
Button #main.exit, "Quit", quit, UL, 150, 292, 60, 25
Button #main.A, "A", sel, UL, 15, 255, 15, 15
Button #main.B, "B", sel, UL, 30, 255, 15, 15
Button #main.C, "C", sel, UL, 45, 255, 15, 15
Button #main.D, "D", sel, UL, 60, 255, 15, 15
Button #main.E, "E", sel, UL, 75, 255, 15, 15
Button #main.F, "F", sel, UL, 90, 255, 15, 15
Button #main.G, "G", sel, UL, 105, 255, 15, 15
Button #main.H, "H", sel, UL, 120, 255, 15, 15
Button #main.I, "I", sel, UL, 135, 255, 15, 15
Button #main.J, "J", sel, UL, 150, 255, 15, 15
Button #main.K, "K", sel, UL, 165, 255, 15, 15
Button #main.L, "L", sel, UL, 180, 255, 15, 15
Button #main.M, "M", sel, UL, 195, 255, 15, 15
Button #main.N, "N", sel, UL, 15, 270, 15, 15
Button #main.O, "O", sel, UL, 30, 270, 15, 15
Button #main.P, "P", sel, UL, 45, 270, 15, 15
Button #main.Q, "Q", sel, UL, 60, 270, 15, 15
Button #main.R, "R", sel, UL, 75, 270, 15, 15
Button #main.S, "S", sel, UL, 90, 270, 15, 15
Button #main.T, "T", sel, UL, 105, 270, 15, 15
Button #main.U, "U", sel, UL, 120, 270, 15, 15
Button #main.V, "V", sel, UL, 135, 270, 15, 15
Button #main.W, "W", sel, UL, 150, 270, 15, 15
Button #main.X, "X", sel, UL, 165, 270, 15, 15
Button #main.Y, "Y", sel, UL, 180, 270, 15, 15
Button #main.Z, "Z", sel, UL, 195, 270, 15, 15
TextboxColor$ = "buttonface"
Textbox #main.statusLabel, 1, 323, 47, 20
Stylebits #main.statusLabel, _ES_READONLY, 0, 0, 0
Textbox #main.status, 48, 323, 173, 20
Stylebits #main.status, _ES_READONLY, 0, 0, 0
Open "Alphabet Buttons 5000" For Window As #main
Print #main, "Trapclose quit"
Print #main.namesList, "Font Courier_New 9"
Print #main.namesList, "singleclickselect"
Print #main.showAll, "!Font Arial_10"
Print #main.addAll, "!Font Arial_10"
Print #main.exit, "!Font Arial_10"
Print #main.statusLabel, "!font arial 8";
Print #main.statusLabel, "Status:"
Print #main.status, "!font arial 8";
Print #main.status, "Loading........"
Call gerenateNames$
Sort masterList$(), 1, 5000
Call show5K handle$
Wait
Sub show5K handle$
report = 0
For x = 1 To 5000
displayList$(x) = masterList$(x) 'copy contents of masterList$() to displayList$()
Next x
Print #main.namesList, "reload"
Print #main.status, "Displaying 5000 names."
End Sub
Sub showName handle$
Print #main.namesList, "selection? selected$"
If report <> 1 Then Print #main.status, "Name: "; selected$
End Sub
Sub showReport handle$
Redim displayList$(5000)
displayList$(1) = " Counting names and" 'Always explain the delay
displayList$(2) = " preparing report."
displayList$(3) = " Please wait!"
Print #main.namesList, "reload"
Print #main.status, "Preparing report........"
report = 1 'Set flag to prevent display of report lines in status bar.
totalNames = 0
reference$ = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
For x = 1 to 26
numNames = 0
sortem$ = word$(reference$, x)
For y = 1 To 5000
If left$(masterList$(y),1) = sortem$ Then numNames = numNames + 1
Next y
nameCount(x) = numNames
totalNames = totalNames + numNames
Next x
Redim displayList$(5000)
displayList$(1) = " REPORT"
For x = 1 to 13
displayList$(x+1) = " " + word$(reference$, x) + " = " + Str$(nameCount(x)) + _
" " + word$(reference$,x+13) + " = " + Str$(nameCount(x+13))
Next x
displayList$(15) = " TOTAL NAMES = " + Str$(totalNames)
Print #main.namesList, "reload"
Print #main.status, "Displaying report."
End Sub
Sub filterList handle$
report = 0
numNames = 0
Redim displayList$(5000)
For x = 1 To 5000
If left$(masterList$(x),1) = sortem$ Then
displayList$(x) = masterList$(x)
numNames = numNames + 1
End If
Next x
Print #main.namesList, "reload"
Print #main.status, "Displaying "; numNames; " ("; sortem$; ") names."
End Sub
Sub quit handle$
Close #main
End
End Sub
Sub quitByMenu
Call quit "#main"
End Sub
' Generate 5,000 fictious names
Sub gerenateNames$
a1$ = "A B C D E F G H I J K L M N O P Qu R S T U V W X Y Z"
a2$ = "b d ck l m n p r sh t v"
b1$ = "ally exter orbin echell alker olthar insero omestad etcher ashen anovich ordemberg atwood "
b2$ = "eston arlington eckenstein obuano auld orlique ahr ikowski oster inston inland arroll anettel"
b3$ = b1$ + b2$
c$ = "Alice John Penny George Mary Bill Ann Tom Lucy David Jane Juan Wendy Xavier Ruth Bob Cora Leon "
d$ = "Laura Steve Nancy Matt Kelly Peter Joanne Ivan Betty Lewis Cathy Patrick Phyllis Paul Helen Keith"
e$ = c$ + d$
For x = 1 To 5000
f$ = word$(a1$,int(rnd(1)*26)+1," ") 'pick first letter of surname
If f$ = "A" Or f$ = "E" Or f$ = "I" Or f$ = "O" Or f$ = "U" Then 'if vowel, add consonant
f$ = f$ + word$(a2$,int(rnd(1)*11)+1," ")
End If
g$ = word$(b3$,int(rnd(1)*26)+1," ") 'pick remainder of surname
h$ = word$(e$,int(rnd(1)*34)+1," ") 'pick first name
i$ = left$(word$(a1$,int(rnd(1)*26)+1," "),1) 'pick middle initial
masterList$(x) = f$ + g$ + ", " + h$ + " " + i$ 'assign full name to masterList$()
Next x
End Sub
Sub sel handle$
sortem$ = word$(handle$,2,"."): Call filterList handle$
End Sub