|
Post by cassiope34 on Sept 3, 2018 11:41:47 GMT
It was on the old forum and just given as an example file with JustBasic 4.0 I think...
' http://justbasic.conforums.com/index.cgi?board=code&action=display&num=1182331516
[init] 'predefine item array dim items$(1)
'get database contents gosub [OpenDB] gosub [ReadDB] gosub [CloseDB]
[MainGUI] 'Form created with the help of Freeform 3 v01-28-07 'Generated on Jun 19, 2007 at 22:50:13
nomainwin WindowWidth = 440 WindowHeight = 230 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
listbox #main.itemlist, items$(, [DisplayItem], 5, 5, 175, 185 statictext #main.NumberTxt, "Item Number:", 200, 7, 80, 25 statictext #main.NumberDisp, "", 300, 7, 95, 25 statictext #main.NameTxt, "Item Name:", 200, 32, 80, 25 statictext #main.NameDisp, "", 300, 32, 95, 25 statictext #main.PrizeTxt, "Item Prize:", 200, 57, 80, 25 statictext #main.PrizeDisp, "", 300, 57, 95, 25 button #main.add, "Add Item", [add], UL, 200, 112, 63, 25 button #main.edit, "Edit Item", [edit], UL, 275, 112, 63, 25 button #main.delete,"Delete Item",[delete], UL, 350, 112, 75, 25 button #main.search,"Search", [search], UL, 200, 162, 63, 25 button #main.exit, "EXIT", [quit.main], UL, 350, 162, 39, 25
open "Simple Database Framework" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]" #main.itemlist "singleclickselect" wait
[add] extension$ = "add" gosub [CheckButton] wait
[edit] extension$ = "edit" gosub [CheckButton] wait
[delete] extension$ = "delete" gosub [CheckButton] wait
[DisplayItem] 'get index of selected item #main.itemlist "selectionindex? SelectedItem"
#main.NameDisp word$(items$(SelectedItem), 1, chr$(0)) #main.NumberDisp word$(items$(SelectedItem), 2, chr$(0)) #main.PrizeDisp word$(items$(SelectedItem), 3, chr$(0)) wait
[search] 'search in the database WindowWidth = 430 WindowHeight = 190
'position of dialogs are relative to previous open window UpperLeftX=1 UpperLeftY=1
textbox #search.String, 5, 5, 175, 25 button #search.default, "Search", [doSearch], UL, 200, 5, 75, 25 listbox #search.itemlist, search$(,[doDisplay], 5, 35, 175, 120 statictext #search.NumberTxt, "Item Number:", 200, 35, 80, 25 statictext #search.NumberDisp, "", 300, 35, 95, 25 statictext #search.NameTxt, "Item Name:", 200, 60, 80, 25 statictext #search.NameDisp, "", 300, 60, 95, 25 statictext #search.PrizeTxt, "Item Prize:", 200, 85, 80, 25 statictext #search.PrizeDisp, "", 300, 85, 95, 25 button #search.cancel, "Close",[quit.search], UL, 300, 127, 63, 25
'modal windows block access to the previous window open "Search Database for Name" for dialog_modal as #search print #search, "font ms_sans_serif 10" print #search, "trapclose [quit.search]" #search.itemlist "singleclickselect" wait
[doSearch] redim search$(MaxItems) foundItem = 0
' search by name = field 1 FieldNumber = 1
#search.String "!contents? SearchString$"
for Count = 1 to MaxItems 'ignore case using LOWER$() if instr(lower$(word$(items$(Count), FieldNumber, chr$(0))), lower$(SearchString$)) > 0 then foundItem = foundItem + 1 search$(foundItem) = items$(Count) end if next
#search.itemlist "reload" #search.itemlist "selectindex 0" wait
[doDisplay] 'get index of selected item #search.itemlist "selectionindex? index"
#search.NameDisp word$(search$(index), 1, chr$(0)) #search.NumberDisp word$(search$(index), 2, chr$(0)) #search.PrizeDisp word$(search$(index), 3, chr$(0)) wait
[quit.search] close #search wait
[quit.main] close #main END
[CheckButton] 'select action based on pushed button select case extension$ case "add" SelectedItem = MaxItems DialogCaption$ = "Add Item" gosub [DisplayDialog]
case "edit" DialogCaption$ = "Edit Item" if SelectedItem > 0 then gosub [DisplayDialog]
case "delete" if SelectedItem > 0 then gosub [DeleteItem] end select
'refresh listbox contents #main.itemlist "reload"
'cancel selection to allow reselection of currently selected item #main.itemlist "selectindex 0" return
[DisplayDialog] 'Form created with the help of Freeform 3 v01-28-07 'Generated on Jun 19, 2007 at 22:59:56
WindowWidth = 275 WindowHeight = 195
'position of dialogs is relative to previous open window UpperLeftX=1 UpperLeftY=1
statictext #item.NumberTxt, "Item Number:", 10, 7, 80, 25 statictext #item.NameTxt, "Item Name:", 10, 42, 80, 25 statictext #item.PrizeTxt, "Item Prize:", 10, 77, 80, 25 textbox #item.Number, 105, 7, 150, 25 textbox #item.Name, 105, 42, 150, 25 textbox #item.Prize, 105, 77, 150, 25 button #item.cancel, "Close",[quit.item], UL, 95, 127, 63, 25 button #item.default, "Apply",[apply], UL, 180, 127, 75, 25
'modal windows block access to the previous window open DialogCaption$; " - "; SelectedItem for dialog_modal as #item print #item, "font ms_sans_serif 10" print #item, "trapclose [quit.item]"
if SelectedItem <> MaxItems then #item.Name word$(items$(SelectedItem), 1, chr$(0)) #item.Number word$(items$(SelectedItem), 2, chr$(0)) #item.Prize word$(items$(SelectedItem), 3, chr$(0)) end if #item.Number "!setfocus" wait
[apply] ' apply changes #item.Number "!contents? Temp1$" #item.Name "!contents? Name$" #item.Prize "!contents? Temp2$"
' Make sure info in boxes is the proper type of data (number/string) if Temp1$ = str$(val(Temp1$)) then Number = val(Temp1$) else ' Item entered in the Number box is not a number ! notice "Item Number must be numeric only." wait end if if Temp2$ = str$(val(Temp2$)) then Prize = val(Temp2$) else ' Item entered in the Prize box is not a number ! notice "Item Prize must be numeric only." wait end if
'fill the array element with the data 'separate fields by CHR$(0) to display only the first field in the listbox items$(SelectedItem) = trim$(Name$); chr$(0); Number; chr$(0); Prize
gosub [ApplyItemData] wait
[quit.item] 'exit dialog close #item return
[ApplyItemData] gosub [BackupDB] gosub [OpenDB] gosub [WriteDB] gosub [ReadDB] gosub [CloseDB] return
[DeleteItem] confirm "Delete Item ... "+str$(SelectedItem)+chr$(13)+_ "Name ..... "+word$(items$(SelectedItem), 1, chr$(0))+chr$(13)+_ "Number ... "+word$(items$(SelectedItem), 2, chr$(0))+chr$(13)+_ "Prize .... "+word$(items$(SelectedItem), 3, chr$(0)); answer
if answer then items$(SelectedItem) = ""
gosub [BackupDB] gosub [OpenDB] gosub [WriteDB] gosub [ReadDB] gosub [CloseDB] end if return
[OpenDB] 'open database and define record length open "database.dat" for random as #db len=150
'set the fields, include some extra space for future use field #db,_ 40 as ItemName$,_ 10 as ItemNumber,_ 10 as ItemPrize,_ 90 as Reserve$ return
[CloseDB] close #db return
[ReadDB] 'get the number of records in the database '= length of database file divided by the record length TotalRecords = lof(#db)/150
'check if the database is corrupted if TotalRecords <> int(TotalRecords) then notice "Database corrupted"; chr$(13); "Please check its contents!" TotalRecords = int(TotalRecords + .5) end if
'dimension array to enable adding one record MaxItems = TotalRecords + 1 redim items$(MaxItems)
for Record = 1 to TotalRecords get #db, Record
'fill the array with the data 'separate fields by CHR$(0) to display only the first field in the listbox items$(Record) = trim$(ItemName$); chr$(0); ItemNumber; chr$(0); ItemPrize next return
[WriteDB] Record = 1
for Count = 1 to MaxItems if items$(Count) <> "" then ItemName$ = word$(items$(Count), 1, chr$(0)) ItemNumber = val(word$(items$(Count), 2, chr$(0))) ItemPrize = val(word$(items$(Count), 3, chr$(0)))
put #db, Record Record = Record + 1 end if next return
[BackupDB] if FileExists("database.bak") then kill "database.bak"
name "database.dat" as "database.bak" return
function FileExists(FilePath$) ' returns zero if file does not exist ' returns one if file exists dim FileExistsInfo$(1,1)
files "", FilePath$, FileExistsInfo$(
FileExists = val(FileExistsInfo$(0,0)) end function /code]
|
|
|
Post by tanger32au on Sept 4, 2018 5:26:52 GMT
Below is my code. What I want to do is once I have done a search as below, add a button to edit the data for the highlighted search result. The same as the edit button on the main screen, just editing the search result highlighted. ' TGLogITx ' *** - Update version date every time a change to the code is made. *** ' *** - Add more infomation about via Notice screen ' *** - Check all code for errors. VersionDate$ = "V01092018"
DBWrites = 1 DeleteMode$ = "D" EditMode = 1 On error goto [ErrorHandler]
[init]
[LoadProgram] 'define global variables global MaxItems
'predefine item array dim items$(1), search$(1)
open "VTK3431W.DLL" for input as #GP2 input #GP2, pwd$ close #GP2
if pwd$ = "BLANK" then gosub [ResetPasswordNew]
WindowWidth = 285 : WindowHeight= 130 'center the window UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 'graphicbox is used to capture key input graphicbox #pass.gb, 0,0,0,0 textbox #pass.tb, 1,20,275,25 'ok button optional button #pass.default, "Ok", [ok],UL 100,60,70,25 open "FreqLogITx" for window as #pass print #pass, "trapclose [quitpass]" print #pass, "font courier_new 10 bold" print #pass.gb, "setfocus" print #pass.tb, "Enter password" print #pass.gb, "when characterInput [pwd]" c=0:p$="":flg=0 goto[denytb] wait [pwd] timer 0 if flg=1 goto [pwd1] #pass.gb,"setfocus" k=asc(mid$(Inkey$,len(Inkey$),1)) print k if k=13 then goto[end1] if k<>8 and k<>13 then c=c+1:p$=p$+chr$(k) if k=8 and flg=0 and c>0 then timer 0:c=c-1:p$=left$(p$,c):flg=1 m$="" for i=1 to c m$=m$+"*" next #pass.tb,m$:#pass.gb,"setfocus":goto[denytb] wait [pwd1] timer 0:#pass.gb,"setfocus" flg=0 goto[denytb] [denytb] timer 500,[t]:#pass.gb,"setfocus" wait [t] timer 0:#pass.gb,"setfocus" goto[denytb] [ok] [end1] if p$=pwd$ then gosub [LoadMe] else gosub [PasswordFailed]
[quitpass] close#pass end
[LoadMe] close#pass if FileExists("FreqLogITx.Lck") then gosub [IncorrectPasswordHistory] 'get database contents call OpenDB call ReadDB call CloseDB
open "Reports\SearchResults_PUBLIC.txt" for append as #SRF close #SRF kill "Reports\SearchResults_PUBLIC.txt"
open "Reports\SearchResults.txt" for append as #SRF close #SRF kill "Reports\SearchResults.txt"
fileNameSR$ = "Reports\SearchResults.txt" FileSet1$ = "1"
open fileNameSR$ for append as #log print #log, "-------------------------" print #log, "**FreqLogITx - Report**" print #log, "Report Date: " + date$("mm/dd/yyyy") print #log, "Report Time: " + time$() close #log
open "Reports\SearchResults_PUBLIC.txt" for append as #log print #log, "-------------------------" print #log, "**FreqLogITx - Report**" print #log, "Report Date: " + date$("mm/dd/yyyy") print #log, "Report Time: " + time$() close #log
Notice "FreqLogITx" + chr$(13) + "FreqLogITx - " + VersionDate$
[MainGUI]
BackgroundColor$ = "darkgrey" ForegroundColor$ = "black" TextboxColor$ = "yellow" ListboxColor$ = "green"
'Form created with the help of Freeform 3 v01-28-07 'Generated on Jun 19, 2007 at 22:50:13
nomainwin WindowWidth = 1000 WindowHeight = 515 'Menus bmpbutton #main.arrow, "Logo.bmp", [Website], UL, 400, 10 if EditMode = 1 then Menu #main, "&File", "&About FreqLogITx", [about], "&Backup Database", [BackupDB_Date], "&RESET DATABASE", [ResetDB1], "&RESET Password", [ResetPasswordMenu], "&Reward", [RewardDisplay], "&Exit", [quit.main] UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
listbox #main.itemlist, items$(, [DisplayItem], 5, 5, 225, 450 statictext #main.NumberTxt, "Freq / Name:", 250, 160, 180, 25 statictext #main.NumberDisp, "", 390, 160, 395, 25 statictext #main.NameTxt, "Date / Site:", 250, 200, 180, 25 statictext #main.NameDisp, "", 390, 200, 395, 25 statictext #main.PrizeTxt, "Notes:", 250, 240, 80, 25 statictext #main.PrizeDisp, "", 390, 240, 630, 150 if EditMode = 1 then button #main.add, "Add", CheckButton, UL, 250, 400, 63, 45 if EditMode = 1 then button #main.edit, "Edit", CheckButton, UL, 330, 400, 63, 45 if EditMode = 1 then button #main.delete,"Delete",CheckButton, UL, 415, 400, 75, 45 button #main.search,"Search Freq / Name", [search_Freq], UL, 525, 400, 163, 45 button #main.searchC,"Search Date / Site", [search_TXNotes], UL, 710, 400, 143, 45 button #main.searchC,"Search Notes", [search_Notes], UL, 870, 400, 100, 45 button #main.WWW, "My Blog", [Website], UL, 825, 10, 139, 45 button #main.Records, "Total Records:";MaxItems, [Refreash], UL, 825, 65, 139, 45 if EditMode <> 1 then button #main.EditMode, "Edit Mode", [EditModeEnabled], UL, 825, 120, 139, 45
open "FreqLogITx - " + VersionDate$ for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]" #main.itemlist "singleclickselect" wait
[DisplayItem] 'get index of selected item #main.itemlist "selectionindex? index"
#main.NumberDisp word$(items$(index), 1,chr$(0)) #main.NameDisp word$(items$(index), 2, chr$(0)) #main.PrizeDisp word$(items$(index), 3, chr$(0))
wait
[about] Notice "FreqLogITx - " + VersionDate$ + chr$(13) + "This program is designed for logging radio scanner frequencies" + chr$(13) + "Please contact me via email for help and support: tanger32au@gmail.com" + chr$(13) + "http://thegeekyradioenthusiast.blogspot.com.au" wait
[Refreash] close #main gosub [MainGUI] wait
[EditModeEnabled] if EditMode = 1 then wait EditMode = 1 Notice "FreqLogITx - " + VersionDate$ + chr$(13) + "Edit mode enabled - close and reopen FreqLogITx to disable" gosub [Refreash] wait
[Website] run "explorer http://thegeekyradioenthusiast.blogspot.com.au" gosub [Refreash] wait
[BackupDB_Date] if FileExists("Backups\" + date$() + "_FreqLogITx.bak") then kill "Backups\" + date$() + "_FreqLogITx.bak"
name "FreqLogITx.dat" as "Backups\" + date$() + "_FreqLogITx.bak" notice "FreqLogITx" + chr$(13) + "Database backed up"
call OpenDB call WriteDB call ReadDB call CloseDB gosub [Refreash]
[ResetPasswordMenu] prompt "Enter new password"; NewPassword$ open "VTK3431W.DLL" for output as #NPWOut print #NPWOut, ""; NewPassword$ close #NPWOut notice "FreqLogITx" + chr$(13) + "Password updated" gosub [Refreash]
[ResetPasswordNew] Notice "FreqLogITx - " + VersionDate$ + chr$(13) + "No password has been set" prompt "Enter a new password"; NewPassword$ open "VTK3431W.DLL" for output as #NPWOut print #NPWOut, ""; NewPassword$ close #NPWOut notice "FreqLogITx" + chr$(13) + "Password updated" gosub [LoadProgram]
[search_Freq] 'search in the database WindowWidth = 900 WindowHeight = 500 'position of dialogs are relative to previous open window UpperLeftX=1 UpperLeftY=1
textbox #search.String, 5, 5, 275, 25 button #search.default, "Search", [doSearch_Freq], UL, 300, 5, 75, 25 listbox #search.itemlist, search$(,[doDisplay], 5, 35, 275, 425 statictext #search.NumberTxt, "Freq / Name:", 300, 65, 180, 25 statictext #search.NumberDisp, "", 420, 65, 395, 25 statictext #search.NameTxt, "Date / Site:", 300, 90, 80, 25 statictext #search.NameDisp, "", 420, 90, 395, 25 statictext #search.PrizeTxt, "Notes:", 300, 115, 80, 25 statictext #search.PrizeDisp, "", 420, 115, 395, 200 button #search.cancel, "Close",[quit.search], UL, 825, 435, 63, 25
'modal windows block access to the previous window open "Search Database for Freq / Name" for dialog_modal as #search print #search, "font ms_sans_serif 10" print #search, "trapclose [quit.search]" #search.itemlist "singleclickselect" wait
[doSearch_Freq] redim search$(MaxItems) foundItem = 0
' search by name = field 1 FieldNumber = 1
#search.String "!contents? SearchString$"
for Count = 1 to MaxItems 'ignore case using LOWER$() if instr(lower$(word$(items$(Count), FieldNumber, chr$(0))), lower$(SearchString$)) > 0 then foundItem = foundItem + 1 search$(foundItem) = items$(Count) end if next
#search.itemlist "reload" #search.itemlist "selectindex 0"
if foundItem = 0 then notice "No search results found" wait
[search_TXNotes] 'search in the database WindowWidth = 900 WindowHeight = 500 'position of dialogs are relative to previous open window UpperLeftX=1 UpperLeftY=1
WindowWidth = 900 WindowHeight = 500 'position of dialogs are relative to previous open window UpperLeftX=1 UpperLeftY=1
textbox #search.String, 5, 5, 275, 25 button #search.default, "Search", [doSearch_TXNotes], UL, 300, 5, 75, 25 listbox #search.itemlist, search$(,[doDisplay], 5, 35, 275, 425 statictext #search.NumberTxt, "Freq / Name:", 300, 65, 180, 25 statictext #search.NumberDisp, "", 420, 65, 395, 25 statictext #search.NameTxt, "Date / Site:", 300, 90, 80, 25 statictext #search.NameDisp, "", 420, 90, 395, 25 statictext #search.PrizeTxt, "Notes:", 300, 115, 80, 25 statictext #search.PrizeDisp, "", 420, 115, 395, 200 button #search.cancel, "Close",[quit.search], UL, 825, 435, 63, 25
'modal windows block access to the previous window open "Search Database for Date / Site" for dialog_modal as #search print #search, "font ms_sans_serif 10" print #search, "trapclose [quit.search]" #search.itemlist "singleclickselect" wait
[doSearch_TXNotes] redim search$(MaxItems) foundItem = 0
' search by name = field 1 FieldNumber = 2
#search.String "!contents? SearchString$"
for Count = 1 to MaxItems 'ignore case using LOWER$() if instr(lower$(word$(items$(Count), FieldNumber, chr$(0))), lower$(SearchString$)) > 0 then foundItem = foundItem + 1 search$(foundItem) = items$(Count) end if next
#search.itemlist "reload" #search.itemlist "selectindex 0" if foundItem = 0 then notice "No search results found" wait
[search_Notes] 'search in the database WindowWidth = 900 WindowHeight = 500 'position of dialogs are relative to previous open window UpperLeftX=1 UpperLeftY=1
textbox #search.String, 5, 5, 275, 25 button #search.default, "Search", [doSearch_Notes], UL, 300, 5, 75, 25 listbox #search.itemlist, search$(,[doDisplay], 5, 35, 275, 425 statictext #search.NumberTxt, "Freq / Name:", 300, 65, 180, 25 statictext #search.NumberDisp, "", 420, 65, 395, 25 statictext #search.NameTxt, "Date / Site:", 300, 90, 80, 25 statictext #search.NameDisp, "", 420, 90, 395, 25 statictext #search.PrizeTxt, "Notes:", 300, 115, 80, 25 statictext #search.PrizeDisp, "", 420, 115, 395, 200 button #search.cancel, "Close",[quit.search], UL, 825, 435, 63, 25
'modal windows block access to the previous window open "Search Database for Notes" for dialog_modal as #search print #search, "font ms_sans_serif 10" print #search, "trapclose [quit.search]" #search.itemlist "singleclickselect" wait
[doSearch_Notes]
redim search$(MaxItems) foundItem = 0
' search by name = field 1 FieldNumber = 3
#search.String "!contents? SearchString$"
for Count = 1 to MaxItems 'ignore case using LOWER$() if instr(lower$(word$(items$(Count), FieldNumber, chr$(0))), lower$(SearchString$)) > 0 then foundItem = foundItem + 1 search$(foundItem) = items$(Count) end if next
#search.itemlist "reload" #search.itemlist "selectindex 0" if foundItem = 0 then notice "No search results found" wait
[doDisplay] 'get index of selected item #search.itemlist "selectionindex? index"
#search.NumberDisp word$(search$(index), 1, chr$(0)) #search.NameDisp word$(search$(index), 2, chr$(0)) #search.PrizeDisp word$(search$(index), 3, chr$(0))
ItemNumSR$ = word$(search$(index), 1, chr$(0)) ItemNameSR$ = word$(search$(index), 2, chr$(0)) ItemPrizeSR$ = word$(search$(index), 3, chr$(0)) 'if FileSet1$ <> "1" then filedialog "Save Search Results to file (default file = SearchResults.txt", "*.txt", fileNameSR$ 'if fileNameSR$ = "" then fileNameSR$ = "Reports\SearchResults.txt" fileNameSRP$ = "Reports\SearchResults_PUBLIC.txt" FileSet1$ = "1"
open fileNameSR$ for append as #log print #log, "" print #log, " Freq / Name: "; ItemNumSR$ print #log, " Date / Site: "; ItemNameSR$ print #log, " Notes: "; ItemPrizeSR$ close #log
open fileNameSRP$ for append as #log print #log, "" print #log, " Freq / Name: "; ItemNumSR$ print #log, " Date / Site: "; ItemNameSR$ close #log
wait
[quit.search] close #search FileSet1$ = "0" wait
[quit.main] confirm "Are you sure you want to exit FreqLogITx?"; answer$ if answer$ = "no" then wait
close #main END
sub CheckButton handle$ 'get extension of button extension$ = word$(handle$, 2, ".")
'get index of selected item #main.itemlist "selectionindex? index"
'select action based on pushed button select case extension$ case "add" call DisplayDialog "Add Item", MaxItems
case "edit" if index > 0 then call DisplayDialog "Edit Item", index
case "delete" if index > 0 then call DeleteItem index end select
'refresh listbox contents #main.itemlist "reload"
'cancel selection to allow reselection of currently selected item #main.itemlist "selectindex 0" end sub
sub DisplayDialog Caption$, ItemNumber 'Form created with the help of Freeform 3 v01-28-07 'Generated on Jun 19, 2007 at 22:59:56
WindowWidth = 800 WindowHeight = 300
'position of dialogs are relative to previous open window UpperLeftX=50 UpperLeftY=50
statictext #item.NumberTxt, "Freq / Name:", 10, 7, 150, 25 statictext #item.NameTxt, "Date / Site:", 10, 42, 80, 25 statictext #item.PrizeTxt, "Notes:", 10, 77, 80, 25 textbox #item.Number, 145, 7, 625, 25 textbox #item.Name, 145, 42, 625, 25 textbox #item.Prize, 145, 77, 625, 25 button #item.cancel, "Close",[quit.item], UL, 95, 227, 63, 25 button #item.default, "Apply",[apply], UL, 180, 227, 75, 25
'modal windows block access to the previous window open Caption$; " - "; ItemNumber$ for dialog_modal as #item print #item, "font ms_sans_serif 10" print #item, "trapclose [quit.item]"
if ItemNumber <> MaxItems then #item.Number word$(items$(ItemNumber), 1, chr$(0)) #item.Name word$(items$(ItemNumber), 2, chr$(0)) #item.Prize word$(items$(ItemNumber), 3, chr$(0))
#item.Prize, "!contents? checkCTCSS$"; 'this sets the variable's value to the textbox contents if instr(checkCTCSS$, "CTCSS")<> 1 then notice "No CTCSS Tones logged for this frequency" 'this checks the contents and issues NOTICE
end if #item.Number "!setfocus"
wait
[apply] ' apply changes #item.Number "!contents? Temp1$" #item.Name "!contents? Name$" #item.Prize "!contents? Temp2$"
' Make sure info in boxes is the proper type of data (Number/string) Number$ = Temp1$ Prize$ = Temp2$
'fill the array element with the data 'separate fields by CHR$(0) to display only the first field in the listbox items$(ItemNumber) = trim$(Number$); chr$(0); Name$; chr$(0); Prize$
call ApplyItemData gosub [quit.item]
[quit.item] 'exit dialog close #item end sub
sub ApplyItemData call BackupDB call OpenDB call WriteDB call ReadDB call CloseDB end sub
sub DeleteItem ItemIndex
confirm "Delete Item ... "+str$(ItemIndex)+chr$(13)+_ "Freq / Name ..... "+word$(items$(ItemIndex), 1, chr$(0))+chr$(13)+_ "Date / Site ... "+word$(items$(ItemIndex), 2, chr$(0))+chr$(13)+_ "Notes .... "+word$(items$(ItemIndex), 3, chr$(0)); answer
if answer then items$(ItemIndex) = ""
call BackupDB call OpenDB call WriteDB call ReadDB call CloseDB end if end sub
sub OpenDB 'open database and define record length open "FreqLogITx.dat" for random as #db len=900
'set the fields, include some extra space for future use field #db,_ 50 as ItemName$,_ 100 as ItemNumber$,_ 660 as ItemPrize$,_ 90 as Reserve$ end sub
sub CloseDB close #db end sub
sub ReadDB
'get the number of records in the database '= length of database file divided by the record length TotalRecords = lof(#db)/900
'check if the database is corrupted if TotalRecords <> int(TotalRecords) then notice "Database corrupted"; chr$(13); "Please check its contents!" TotalRecords = int(TotalRecords + .5) end if
'dimension array to enable adding one record MaxItems = TotalRecords + 1 redim items$(MaxItems)
for Record = 1 to TotalRecords get #db, Record
'fill the array with the data 'separate fields by CHR$(0) to display only the first field in the listbox items$(Record) = trim$(ItemNumber$); chr$(0); ItemName$; chr$(0); ItemPrize$ next 'sort array 'added code: simple selection sort 'of cource qsort will be faster, but then it's bigger for i = 1 to TotalRecords minPos = i minVal$ = items$(i) 'select minimal item for j = i+1 to TotalRecords if items$(j) < minVal$ then minVal$ = items$(j) minPos = j end if next 'then swap it to i-th place tmp$=items$(minPos) items$(minPos)=items$(i) items$(i)=tmp$ next end sub
sub WriteDB Record = 1
for Count = 1 to MaxItems if items$(Count) <> "" then ItemNumber$ = word$(items$(Count), 1, chr$(0)) ItemName$ = word$(items$(Count), 2, chr$(0)) ItemPrize$ = word$(items$(Count), 3, chr$(0))
put #db, Record Record = Record + 1 end if next notice "FreqLogITx" + chr$(13) + "Database updated"
end sub
sub BackupDB if FileExists("Backups\_FreqLogITx.bak") then kill "Backups\_FreqLogITx.bak"
name "FreqLogITx.dat" as "Backups\_FreqLogITx.bak" end sub
function FileExists(FilePath$) ' returns zero if file does not exist ' returns one if file exists dim FileExistsInfo$(1,1)
files "", FilePath$, FileExistsInfo$(
FileExists = val(FileExistsInfo$(0,0)) end function
[ResetDB1] prompt "YES to reset database file to blank"; ConfirmResetDB$ if ConfirmResetDB$ <> "YES" then wait prompt "Enter your password to delete all records"; ConfirmResetDB1$ if ConfirmResetDB1$ = pwd$ then gosub [ResetDB2] else gosub [Refreash1]
[ResetDB2] name "FreqLogITx.dat" as "Backups\" + date$() + "_FreqLogITx_PreDBReset.bak" Notice "Database has been reset - FreqLogITx will now close" close #main END
[Refreash1] Notice "Unable to reset database, returning to main menu" gosub [Refreash]
[ErrorHandler] Notice "FreqLogITx" + chr$(13) + "Error Detected - :(" Notice "Error Code: "; Err Notice "Error Message: "; Err$
open "FreqLogITx.log" for append as #log print #log, "" print #log, "**FreqLogITx**" print #log, "Program Closed Date: " + date$("mm/dd/yyyy") print #log, "Program Closed Time: " + time$() print #log, "EVENT: Program closed due to error" print #log, "Error Code: "; Err print #log, "Error Message: "; Err$ close #log END
[PasswordFailed] open "FreqLogITx.Lck" for append as #log print #log, "" print #log, "-------------------------" print #log, "Attempt Date: " + date$("mm/dd/yyyy") print #log, "Attempt Time: " + time$() close #log
notice "Wrong password entered - closing FreqLogITx" close#pass END
[IncorrectPasswordHistory] Notice"Invalid Password Attempts Detected - Please close and reopen FreqLogITx to clear this" if FileExists("FreqLogITx_History.Lck") then kill "FreqLogITx_History.Lck" if FileExists("FreqLogITx.Lck") then name "FreqLogITx.Lck" as "FreqLogITx_History.Lck" end
|
|