|
Post by wexhammer on Jan 7, 2020 13:41:24 GMT -5
I am playing around with the code and editing it slightly. Closing #current when i want to edit data. But when i click on a name in the listbox i get an os error. Why could this be?
Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount Global filterCount, oldStage$, openFlag Nomainwin Dim name$(1000), nameSearch$(1000), stage$(20), type$(20) Dim builder$(1000, 13), existInfo$(10,10), hContents$(20)
dupo=0 addName=1
[GUI]
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0 WindowWidth = 495 '595 695 795 WindowHeight = 460 UpperLeftX=Int((DisplayWidth-WindowWidth)/2) UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
Statictext #main, "Shortcuts", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 140, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 160, 25 Statictext #main.3, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 160, 25
button #main.browse, "Open", loadnames, UL, 320, 80, 50, 20 ' button #main.run, "Open", [open], UL, 435, 10, 40, 20 button #main.run2, "Save File As", [save], UL, 375, 80, 90, 20
Button #main.new, "&New Entry", addRecord, UL, 10, 360
Button #main.remove, "&Remove Entry", removeEntry , UL, 190, 360
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save Entry", acceptEntry, UL, 350, 360 Open "Test" For Window As #main Print #main, "Trapclose endProgram"
Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect" #main.contacts "Setfocus"
#main.number "!show"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop] Wait
[addRecord] Call addRecord handle$ Wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ if openFlag then close #current close #main end End Sub
Sub loadnames handle$
if openFlag then close #current
'get user to open main file filedialog "Open Original file...","*.dat",file$ Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ if lof(#current)=0 then name$ = "0" put #current, 1 else get #current, 1 contactCount = Val(name$) end if openFlag=1 call populateList end Sub '[skipIt] 'End Sub
Sub initializeNames
Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #current, 1 Close #current End Sub
[moveOn]
Sub modifyRecord handle$ if openFlag then close #current
addName = 0
Print #main.contacts, "Selection? selection$" If selection$ = "" Then [noName]
Print #main.contacts, "SelectionIndex? index" If index = 0 Then [noName] 'This should never need to happen recordIndex=val(selection$) [getContactRecord] getIndex=recordIndex+1 Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Gettrim #current, getIndex ' Close #current Print #main.name, name$ 'Print #main.number, number$
[noName] End Sub
Sub addRecord handle$ addName = 1 Print #main.contacts, "SelectIndex 0" Print #main.name, "" Print #main.number, ""
' Print #main.stage, "SelectIndex 20" ' Print #main.type, "SelectIndex 20"
Print #main.name, "!SetFocus"
End Sub
Sub populateList ' Open file$ For random As #current3 Len = 710 ' Field #current3, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
for index = 2 to contactCount + 1 gettrim #current, index name$(index)=name$ next index #main.contacts "reload"
End Sub
Sub saveList For index2 = 2 To contactCount + 1 For column=1 To 4 Select Case column Case 1 name$=builder$(index2, column) Case 2 number$=builder$(index2, column) Case 3 stage$=builder$(index2, column) Case 4 type$=builder$(index2, column)
End Select Next column Put #current, index2 Next index2
Close #current ' If exists("contact4recoverold.bak") Then ' Kill "contact4recoverold.bak" ' End If ' If exists("contact4recover.bak") Then ' Name "contact4recover.bak" As "contact4recoverold.bak" ' End If ' Name file$ As "contact4recover.bak" ' Name "contact.dat" As file$ End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry handle$ ' Print #main.filtertype, "selection? filter$" If addName=0 Then Confirm "YOU ARE ABOUT TO DELETE THIS RECORD"+Chr$(13)+" "+Chr$(13)+Chr$(34)_ +name$(recordIndex)+Chr$(34)+Chr$(13)+" "+Chr$(13)+"Do you want to proceed?";delAns$ If Lower$(delAns$)="no" Then [noDelete] WindowWidth=150 WindowHeight=75 StaticText #patience, "PLEASE WAIT...", 10, 15, 100, 25 Open "DELETING...", For Dialog_Modal As #patience
Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #current, moveRecords+1 Put #current, moveRecords Next moveRecords
Get #current, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #current, 1
Close #current Close #patience Call loadnames handle$ Notice "RECORD DELETED"+Chr$(13)+"Names reloaded" Else Notice "NO RECORD SELECTED!"+Chr$(13)+"Please select a record," _ +Chr$(13)+"then select delete from the menu." End If
[noDelete] End Sub
|
|
|
Post by Chris Iverson on Jan 7, 2020 13:51:22 GMT -5
Scope.
You have "open file$ for Random as #current Len = 710" in the sub, but file$ is never defined in the sub, and is not a global variable. So file$ is blank. You're trying to open a file with no name.
|
|
|
Post by Rod on Jan 7, 2020 14:59:39 GMT -5
I thought we had discussed opening the file once and once only? I specifically said to remove all of your open and close code from within subs.
|
|
|
Post by wexhammer on Jan 8, 2020 3:05:39 GMT -5
Ok, so after a good nights sleep i have re-done the code as you said Rod. There is progress being made. However i am getting a couple of errors when trying to delete a record or just simply exit the program.
[Initialize] Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount Global filterCount, oldStage$, openFlag Nomainwin Dim name$(1000), nameSearch$(1000), stage$(20), type$(20) Dim builder$(1000, 13), existInfo$(10,10), hContents$(20)
dupo=0 addName=1
Call loadNames
[GUI]
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0 WindowWidth = 495 '595 695 795 WindowHeight = 460 UpperLeftX=Int((DisplayWidth-WindowWidth)/2) UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
Statictext #main, "Shortcuts", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 140, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 160, 25 Statictext #main.3, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 160, 25
button #main.browse, "Open", [open], UL, 320, 80, 50, 20 ' button #main.run, "Open", [open], UL, 435, 10, 40, 20 button #main.run2, "Save File As", [save], UL, 375, 80, 90, 20
button #main.browse, "Remove", removeEntry, UL, 320, 130, 50, 20 Button #main.new, "&New Entry", addRecord, UL, 10, 360
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save Entry", acceptEntry, UL, 350, 360 Open "Test" For Window As #main Print #main, "Trapclose endProgram"
Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect"
#main.number "!show"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop] Wait
[acceptEntry] Call acceptEntry handle$ Wait
[addRecord] Call addRecord handle$ Wait
[save]
'FileDialog "Select a file", "*.bak*;*.dat*", nameoffile$ 'if nameoffile$="" then wait prompt "Enter the file name to save"; newfilename$ ' if newfilename$ <> "" then ' notice "j" ' else
'file$ open file$ for input as #old open newfilename$;".dat" for output as #new open newfilename$;".bak" for output as #new1 #new, input$(#old,lof(#old)); close #old close #new close #new1
wait
[open]
'prompt, "name"
'filedialog "Save",filePath$+"\*.dat",savefile$ 'if savefile$="" then wait 'if instr(savefile$,".")=0 then savefile$=savefile$+".dat"
wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ if openFlag then close #current close #main end End Sub
Sub loadNames if openFlag then close #current
'get user to open main file filedialog "Open Original file...","*.dat",file$ if file$="" then wait Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index ' Close #current ' Close #currentCopy [skipIt] End Sub
Sub initializeNames
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #current, 1 ' Close #current End Sub
[moveOn]
Sub modifyRecord handle$ addName = 0
Print #main.contacts, "Selection? selection$" If selection$ = "" Then [noName]
Print #main.contacts, "SelectionIndex? index" If index = 0 Then [noName] 'This should never need to happen recordIndex=val(selection$) [getContactRecord] getIndex=recordIndex+1 'Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Gettrim #current, getIndex ' Close #current Print #main.name, name$ Print #main.number, number$
[noName] End Sub
Sub addRecord handle$ addName = 1 Print #main.contacts, "SelectIndex 0" Print #main.name, "" Print #main.number, ""
' Print #main.stage, "SelectIndex 20" ' Print #main.type, "SelectIndex 20"
Print #main.name, "!SetFocus"
End Sub
Sub acceptEntry handle$ Print #main.name, "!contents? name$"; If name$<>"" Then Print #main.name, "!contents? number$"; Print #main.number, "!contents? number$"; ' Print #main.type, "Selection? type$"; 'Print #main.stage, "Selection? stage$"; If addName = 1 Then contactCount = contactCount + 1 recordIndex = contactCount End If name$(recordIndex) = Str$(recordIndex)+") "+name$ Print #main.contacts, "Reload" date$=Date$() If oldStage$="Opening Mailer" And stage$="Follow Up Call" then mailDate$=Date$() End If [saveContactRecord] ' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Put #current, recordIndex + 1 ' Close #current If addName = 0 Then [goBack] ' Open file$ For Random As #current Len = 710 Field #current, 35 As count$, 675 As fill$ count$ = Str$(contactCount) Put #current, 1 ' Close #current addName = 0 [goBack] Print #main.contacts, "SelectIndex ";recordIndex Call addRecord handle$ Else Notice "NO BUSINESS NAME"+Chr$(13)+"The business name must be entered, "_ +Chr$(13)+"before a record can be saved. " End If End Sub
Sub populateList ' Open file$ For random As #current3 Len = 710 ' Field #current3, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact.dat" For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
Get #current3, 1 contactCount = Val(name$) Put #current, 1
For index2 = 2 To contactCount + 1 Gettrim #current3, index2 For column=1 To 4 Select Case column Case 1 builder$(index2, column)=name$ Case 2 builder$(index2, column)=number$
Case 3 builder$(index2, column)=stage$ Case 4 builder$(index2, column)=type$
End Select Next column Next index2 End Sub
Sub saveList For index2 = 2 To contactCount + 1 For column=1 To 4 Select Case column Case 1 name$=builder$(index2, column) Case 2 number$=builder$(index2, column) Case 3 stage$=builder$(index2, column) Case 4 type$=builder$(index2, column)
End Select Next column Put #current, index2 Next index2
' Close #current3 Close #current
End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry handle$ ' Print #main.filtertype, "selection? filter$" If addName=0 Then Confirm "YOU ARE ABOUT TO DELETE THIS RECORD"+Chr$(13)+" "+Chr$(13)+Chr$(34)_ +name$(recordIndex)+Chr$(34)+Chr$(13)+" "+Chr$(13)+"Do you want to proceed?";delAns$ If Lower$(delAns$)="no" Then [noDelete] WindowWidth=150 WindowHeight=75 StaticText #patience, "PLEASE WAIT...", 10, 15, 100, 25 Open "DELETING...", For Dialog_Modal As #patience
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #current, moveRecords+1 Put #current, moveRecords Next moveRecords
Get #current, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #current, 1
' Close #current Close #patience Call loadNames Notice "RECORD DELETED"+Chr$(13)+"Names reloaded" Else Notice "NO RECORD SELECTED!"+Chr$(13)+"Please select a record," _ +Chr$(13)+"then select delete from the menu." End If
[noDelete] End Sub
Below is another amended version, this time i have removed the open file on start up and decided to put it in the open button instead. Same code nothings changed yet, the listbox isnt loading the names? I am absolutely clueless now. Whats going on here?
[Initialize] Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount Global filterCount, oldStage$, openFlag Nomainwin Dim name$(1000), nameSearch$(1000), stage$(20), type$(20) Dim builder$(1000, 13), existInfo$(10,10), hContents$(20)
dupo=0 addName=1
'Call loadNames
[GUI]
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0 WindowWidth = 495 '595 695 795 WindowHeight = 460 UpperLeftX=Int((DisplayWidth-WindowWidth)/2) UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
Statictext #main, "Shortcuts", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 140, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 160, 25 Statictext #main.3, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 160, 25
button #main.browse, "Open", [load], UL, 320, 80, 50, 20 ' button #main.run, "Open", [open], UL, 435, 10, 40, 20 button #main.run2, "Save File As", [save], UL, 375, 80, 90, 20
button #main.browse, "Remove", removeEntry, UL, 320, 130, 50, 20 Button #main.new, "&New Entry", addRecord, UL, 10, 360
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save Entry", acceptEntry, UL, 350, 360 Open "Test" For Window As #main Print #main, "Trapclose endProgram"
Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect"
#main.number "!show"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop] Wait
[acceptEntry] Call acceptEntry handle$ Wait
[addRecord] Call addRecord handle$ Wait
[save]
'FileDialog "Select a file", "*.bak*;*.dat*", nameoffile$ 'if nameoffile$="" then wait prompt "Enter the file name to save"; newfilename$ ' if newfilename$ <> "" then ' notice "j" ' else
'file$ open file$ for input as #old open newfilename$;".dat" for output as #new open newfilename$;".bak" for output as #new1 #new, input$(#old,lof(#old)); close #old close #new close #new1
wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ if openFlag then close #current close #main end End Sub
[load] if openFlag then close #current
'get user to open main file filedialog "Open Original file...","*.dat",file$ if file$="" then wait Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index ' Close #current ' Close #currentCopy [skipIt] wait
Sub initializeNames
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #current, 1 ' Close #current End Sub
[moveOn]
Sub modifyRecord handle$ addName = 0
Print #main.contacts, "Selection? selection$" If selection$ = "" Then [noName]
Print #main.contacts, "SelectionIndex? index" If index = 0 Then [noName] 'This should never need to happen recordIndex=val(selection$) [getContactRecord] getIndex=recordIndex+1 'Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Gettrim #current, getIndex ' Close #current Print #main.name, name$ Print #main.number, number$
[noName] End Sub
Sub addRecord handle$ addName = 1 Print #main.contacts, "SelectIndex 0" Print #main.name, "" Print #main.number, ""
' Print #main.stage, "SelectIndex 20" ' Print #main.type, "SelectIndex 20"
Print #main.name, "!SetFocus"
End Sub
Sub acceptEntry handle$ Print #main.name, "!contents? name$"; If name$<>"" Then Print #main.name, "!contents? number$"; Print #main.number, "!contents? number$"; ' Print #main.type, "Selection? type$"; 'Print #main.stage, "Selection? stage$"; If addName = 1 Then contactCount = contactCount + 1 recordIndex = contactCount End If name$(recordIndex) = Str$(recordIndex)+") "+name$ Print #main.contacts, "Reload" date$=Date$() If oldStage$="Opening Mailer" And stage$="Follow Up Call" then mailDate$=Date$() End If [saveContactRecord] ' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Put #current, recordIndex + 1 ' Close #current If addName = 0 Then [goBack] ' Open file$ For Random As #current Len = 710 Field #current, 35 As count$, 675 As fill$ count$ = Str$(contactCount) Put #current, 1 ' Close #current addName = 0 [goBack] Print #main.contacts, "SelectIndex ";recordIndex Call addRecord handle$ Else Notice "NO BUSINESS NAME"+Chr$(13)+"The business name must be entered, "_ +Chr$(13)+"before a record can be saved. " End If End Sub
Sub populateList ' Open file$ For random As #current3 Len = 710 ' Field #current3, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact.dat" For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
Get #current3, 1 contactCount = Val(name$) Put #current, 1
For index2 = 2 To contactCount + 1 Gettrim #current3, index2 For column=1 To 4 Select Case column Case 1 builder$(index2, column)=name$ Case 2 builder$(index2, column)=number$
Case 3 builder$(index2, column)=stage$ Case 4 builder$(index2, column)=type$
End Select Next column Next index2 End Sub
Sub saveList For index2 = 2 To contactCount + 1 For column=1 To 4 Select Case column Case 1 name$=builder$(index2, column) Case 2 number$=builder$(index2, column) Case 3 stage$=builder$(index2, column) Case 4 type$=builder$(index2, column)
End Select Next column Put #current, index2 Next index2
' Close #current3 Close #current
End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry handle$ ' Print #main.filtertype, "selection? filter$" If addName=0 Then Confirm "YOU ARE ABOUT TO DELETE THIS RECORD"+Chr$(13)+" "+Chr$(13)+Chr$(34)_ +name$(recordIndex)+Chr$(34)+Chr$(13)+" "+Chr$(13)+"Do you want to proceed?";delAns$ If Lower$(delAns$)="no" Then [noDelete] WindowWidth=150 WindowHeight=75 StaticText #patience, "PLEASE WAIT...", 10, 15, 100, 25 Open "DELETING...", For Dialog_Modal As #patience
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #current, moveRecords+1 Put #current, moveRecords Next moveRecords
Get #current, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #current, 1
' Close #current Close #patience openFlag =1 goto [load] Notice "RECORD DELETED"+Chr$(13)+"Names reloaded" Else Notice "NO RECORD SELECTED!"+Chr$(13)+"Please select a record," _ +Chr$(13)+"then select delete from the menu." End If
[noDelete] End Sub
|
|
|
Post by wexhammer on Jan 8, 2020 5:21:10 GMT -5
Ok everyone, I have finally got my head around how this is supposed to work and have finally got it working! And i will make one last call for help on this individual thread.
So far i can edit records in multiple files and delete them. However when i open another file for editing, the listbox reloads as should but some of the names from other files are still appearing in the list. Now is this a bug in Liberty Basic? Because the debug console is telling me that i have closed #current and have then opened the new data file, its loaded the names as normal, and then reloaded the listbox. How can that listbox be flushed for good so the old names arnt appearing?
[Initialize] Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount Global filterCount, oldStage$, openFlag Nomainwin Dim name$(1000), nameSearch$(1000), stage$(20), type$(20) Dim builder$(1000, 13), existInfo$(10,10), hContents$(20)
dupo=0 addName=1
' Call loadNames
[GUI]
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0 WindowWidth = 495 '595 695 795 WindowHeight = 460 UpperLeftX=Int((DisplayWidth-WindowWidth)/2) UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
Statictext #main, "Shortcuts", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 140, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 160, 25 Statictext #main.3, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 160, 25
button #main.browse, "Open", loadNames, UL, 320, 80, 50, 20 ' button #main.run, "Open", [open], UL, 435, 10, 40, 20 button #main.run2, "Save File As", [save], UL, 375, 80, 90, 20
button #main.browse, "Remove", removeEntry, UL, 320, 130, 50, 20 Button #main.new, "&New Entry", addRecord, UL, 10, 360
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save Entry", acceptEntry, UL, 350, 360 Open "Test" For Window As #main Print #main, "Trapclose endProgram"
Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect"
#main.number "!show"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop] Wait
[acceptEntry] Call acceptEntry handle$ Wait
[addRecord] Call addRecord handle$ Wait
[save]
'FileDialog "Select a file", "*.bak*;*.dat*", nameoffile$ 'if nameoffile$="" then wait prompt "Enter the file name to save"; newfilename$ ' if newfilename$ <> "" then ' notice "j" ' else
'file$ open file$ for input as #old open newfilename$;".dat" for output as #new open newfilename$;".bak" for output as #new1 #new, input$(#old,lof(#old)); close #old close #new close #new1
wait
[open]
'prompt, "name"
'filedialog "Save",filePath$+"\*.dat",savefile$ 'if savefile$="" then wait 'if instr(savefile$,".")=0 then savefile$=savefile$+".dat" 'call loadNames
wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ if openFlag then close #current close #main end End Sub
Sub loadNames handle$ if openFlag=1 then close #current
filedialog "Open Original file...","*.dat",file$ Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index #main.contacts "reload" openFlag=1 ' Close #current ' Close #currentCopy
else if openFlag = 2 then
' Open file$ For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index #main.contacts "reload" openFlag=1
else 'get user to open main file filedialog "Open Original file...","*.dat",file$ Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ end if ' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index #main.contacts "reload" openFlag=1 ' Close #current ' Close #currentCopy end if [skipIt] End Sub
Sub initializeNames
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #current, 1 #main.contacts "reload" ' Close #current End Sub
[moveOn]
Sub modifyRecord handle$ addName = 0
Print #main.contacts, "Selection? selection$" If selection$ = "" Then [noName]
Print #main.contacts, "SelectionIndex? index" If index = 0 Then [noName] 'This should never need to happen recordIndex=val(selection$) [getContactRecord] getIndex=recordIndex+1 'Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Gettrim #current, getIndex ' Close #current Print #main.name, name$ Print #main.number, number$
[noName] End Sub
Sub addRecord handle$ addName = 1 Print #main.contacts, "SelectIndex 0" Print #main.name, "" Print #main.number, ""
' Print #main.stage, "SelectIndex 20" ' Print #main.type, "SelectIndex 20"
Print #main.name, "!SetFocus"
End Sub
Sub acceptEntry handle$ Print #main.name, "!contents? name$"; If name$<>"" Then Print #main.name, "!contents? number$"; Print #main.number, "!contents? number$"; ' Print #main.type, "Selection? type$"; 'Print #main.stage, "Selection? stage$"; If addName = 1 Then contactCount = contactCount + 1 recordIndex = contactCount End If name$(recordIndex) = Str$(recordIndex)+") "+name$ Print #main.contacts, "Reload" date$=Date$() If oldStage$="Opening Mailer" And stage$="Follow Up Call" then mailDate$=Date$() End If [saveContactRecord] ' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Put #current, recordIndex + 1 ' Close #current If addName = 0 Then [goBack] ' Open file$ For Random As #current Len = 710 Field #current, 35 As count$, 675 As fill$ count$ = Str$(contactCount) Put #current, 1 ' Close #current addName = 0 [goBack] Print #main.contacts, "SelectIndex ";recordIndex Call addRecord handle$ Else Notice "NO BUSINESS NAME"+Chr$(13)+"The business name must be entered, "_ +Chr$(13)+"before a record can be saved. " End If End Sub
Sub populateList ' Open file$ For random As #current3 Len = 710 ' Field #current3, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact.dat" For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
Get #current3, 1 contactCount = Val(name$) Put #current, 1
For index2 = 2 To contactCount + 1 Gettrim #current3, index2
For column=1 To 4 Select Case column Case 1 builder$(index2, column)=name$ Case 2 builder$(index2, column)=number$
Case 3 builder$(index2, column)=stage$ Case 4 builder$(index2, column)=type$
End Select Next column Next index2 #main.contacts "reload" End Sub
Sub saveList For index2 = 2 To contactCount + 1 For column=1 To 4 Select Case column Case 1 name$=builder$(index2, column) Case 2 number$=builder$(index2, column) Case 3 stage$=builder$(index2, column) Case 4 type$=builder$(index2, column)
End Select Next column Put #current, index2 Next index2
' Close #current3 Close #current
End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry handle$ ' Print #main.filtertype, "selection? filter$" If addName=0 Then Confirm "YOU ARE ABOUT TO DELETE THIS RECORD"+Chr$(13)+" "+Chr$(13)+Chr$(34)_ +name$(recordIndex)+Chr$(34)+Chr$(13)+" "+Chr$(13)+"Do you want to proceed?";delAns$ If Lower$(delAns$)="no" Then [noDelete] WindowWidth=150 WindowHeight=75 StaticText #patience, "PLEASE WAIT...", 10, 15, 100, 25 Open "DELETING...", For Dialog_Modal As #patience
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #current, moveRecords+1 Put #current, moveRecords Next moveRecords
Get #current, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #current, 1
' Close #current Close #patience openFlag = 2 Call loadNames handle$ Notice "RECORD DELETED"+Chr$(13)+"Names reloaded" Else Notice "NO RECORD SELECTED!"+Chr$(13)+"Please select a record," _ +Chr$(13)+"then select delete from the menu." End If
[noDelete] End Sub
|
|
|
Post by Rod on Jan 8, 2020 6:01:03 GMT -5
Well these rogue names are either in the database file or in the array that drives the listbox. did you redim the listbox array prior to loading the new database?
|
|
|
Post by wexhammer on Jan 8, 2020 6:51:30 GMT -5
Nope . There is my answer, thanks Rod!
|
|
|
Post by wexhammer on Jan 8, 2020 7:34:13 GMT -5
There is one more error! It seems when i open a file then want to open another file but change my mind and press cancel then press the open button again i get another error. I have tried to set a flag for if file$="" then openFlag = 1 This doesnt seem to work....
[Initialize] Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount Global filterCount, oldStage$, openFlag Nomainwin Dim name$(1000), nameSearch$(1000), stage$(20), type$(20) Dim builder$(1000, 13), existInfo$(10,10), hContents$(20)
dupo=0 addName=1
' Call loadNames
[GUI]
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0 WindowWidth = 495 '595 695 795 WindowHeight = 460 UpperLeftX=Int((DisplayWidth-WindowWidth)/2) UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
Statictext #main, "Shortcuts", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 140, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 160, 25 Statictext #main.3, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 160, 25
button #main.browse, "Open", loadNames, UL, 320, 80, 50, 20 ' button #main.run, "Open", [open], UL, 435, 10, 40, 20 button #main.run2, "Save File As", [save], UL, 375, 80, 90, 20
button #main.browse, "Remove", removeEntry, UL, 320, 130, 50, 20 Button #main.new, "&New Entry", addRecord, UL, 10, 360
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save Entry", acceptEntry, UL, 350, 360 Open "Test" For Window As #main Print #main, "Trapclose endProgram"
Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect"
#main.number "!show"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop] Wait
[acceptEntry] Call acceptEntry handle$ Wait
[addRecord] Call addRecord handle$ Wait
[save]
'FileDialog "Select a file", "*.bak*;*.dat*", nameoffile$ 'if nameoffile$="" then wait prompt "Enter the file name to save"; newfilename$ ' if newfilename$ <> "" then ' notice "j" ' else
'file$ open file$ for input as #old open newfilename$;".dat" for output as #new open newfilename$;".bak" for output as #new1 #new, input$(#old,lof(#old)); close #old close #new close #new1
wait
[open]
'prompt, "name"
'filedialog "Save",filePath$+"\*.dat",savefile$ 'if savefile$="" then wait 'if instr(savefile$,".")=0 then savefile$=savefile$+".dat" 'call loadNames
wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ if openFlag then close #current close #main end End Sub
Sub loadNames handle$ redim name$(1000) #main.contacts "reload" #main.contacts "hide" #main.contacts "show" 'Print #main.contacts, "SelectIndex 0" if openFlag=1 then close #current
filedialog "Open Original file...","*.dat",file$ if file$="" then wait
Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 ' Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$ #main.contacts "reload" Next index #main.contacts "reload" openFlag=1 ' Close #current ' Close #currentCopy
else if openFlag = 2 then
' Open file$ For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index #main.contacts "reload" openFlag=1
else 'get user to open main file filedialog "Open Original file...","*.dat",file$ if file$ = "" then wait Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ end if ' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index #main.contacts "reload" openFlag=1 ' Close #current ' Close #currentCopy end if [skipIt] End Sub
Sub initializeNames
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #current, 1 #main.contacts "reload" ' Close #current End Sub
[moveOn]
Sub modifyRecord handle$ addName = 0
Print #main.contacts, "Selection? selection$" If selection$ = "" Then [noName]
Print #main.contacts, "SelectionIndex? index" If index = 0 Then [noName] 'This should never need to happen recordIndex=val(selection$) [getContactRecord] getIndex=recordIndex+1 'Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Gettrim #current, getIndex ' Close #current Print #main.name, name$ Print #main.number, number$
[noName] End Sub
Sub addRecord handle$ addName = 1 Print #main.contacts, "SelectIndex 0" Print #main.name, "" Print #main.number, ""
' Print #main.stage, "SelectIndex 20" ' Print #main.type, "SelectIndex 20"
Print #main.name, "!SetFocus"
End Sub
Sub acceptEntry handle$ Print #main.name, "!contents? name$"; If name$<>"" Then Print #main.name, "!contents? number$"; Print #main.number, "!contents? number$"; ' Print #main.type, "Selection? type$"; 'Print #main.stage, "Selection? stage$"; If addName = 1 Then contactCount = contactCount + 1 recordIndex = contactCount End If name$(recordIndex) = Str$(recordIndex)+") "+name$ Print #main.contacts, "Reload" date$=Date$() If oldStage$="Opening Mailer" And stage$="Follow Up Call" then mailDate$=Date$() End If [saveContactRecord] ' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Put #current, recordIndex + 1 ' Close #current If addName = 0 Then [goBack] ' Open file$ For Random As #current Len = 710 Field #current, 35 As count$, 675 As fill$ count$ = Str$(contactCount) Put #current, 1 ' Close #current addName = 0 [goBack] Print #main.contacts, "SelectIndex ";recordIndex Call addRecord handle$ Else Notice "NO BUSINESS NAME"+Chr$(13)+"The business name must be entered, "_ +Chr$(13)+"before a record can be saved. " End If End Sub
Sub populateList ' Open file$ For random As #current3 Len = 710 ' Field #current3, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact.dat" For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ #main.contacts "reload"
Get #current3, 1 contactCount = Val(name$) Put #current, 1
For index2 = 2 To contactCount + 1 Gettrim #current3, index2
For column=1 To 4 Select Case column Case 1 builder$(index2, column)=name$ Case 2 builder$(index2, column)=number$
Case 3 builder$(index2, column)=stage$ Case 4 builder$(index2, column)=type$
End Select Next column Next index2 #main.contacts "reload" End Sub
Sub saveList For index2 = 2 To contactCount + 1 For column=1 To 4 Select Case column Case 1 name$=builder$(index2, column) Case 2 number$=builder$(index2, column) Case 3 stage$=builder$(index2, column) Case 4 type$=builder$(index2, column)
End Select Next column Put #current, index2 Next index2
' Close #current3 Close #current
End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry handle$ ' Print #main.filtertype, "selection? filter$" If addName=0 Then Confirm "YOU ARE ABOUT TO DELETE THIS RECORD"+Chr$(13)+" "+Chr$(13)+Chr$(34)_ +name$(recordIndex)+Chr$(34)+Chr$(13)+" "+Chr$(13)+"Do you want to proceed?";delAns$ If Lower$(delAns$)="no" Then [noDelete] WindowWidth=150 WindowHeight=75 StaticText #patience, "PLEASE WAIT...", 10, 15, 100, 25 Open "DELETING...", For Dialog_Modal As #patience
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #current, moveRecords+1 Put #current, moveRecords Next moveRecords
Get #current, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #current, 1
' Close #current Close #patience openFlag = 2 Call loadNames handle$ Notice "RECORD DELETED"+Chr$(13)+"Names reloaded" Else Notice "NO RECORD SELECTED!"+Chr$(13)+"Please select a record," _ +Chr$(13)+"then select delete from the menu." End If
[noDelete] End Sub
|
|
|
Post by Rod on Jan 8, 2020 7:46:21 GMT -5
In loadnames sub try changing to
if openFlag then close #current openFlag=0 End if
That way if the task gets cancelled openFlag will contain the correct value.
|
|
|
Post by wexhammer on Jan 8, 2020 8:07:38 GMT -5
Okay thanks that works but when i click on a name in the list box after canceling an opening of a file i get a #current error
|
|
|
Post by Rod on Jan 8, 2020 8:31:11 GMT -5
Well yes, you closed the file. If you cancel you either close down or go back to the start of loadnames till they do actually choose a file. Don’t call loadnames again just go back to a [branch label] at the top or make the thing a while wend loop till a file is chosen.
|
|
|
Post by wexhammer on Jan 8, 2020 9:45:38 GMT -5
I can't get my head around this. I need the openFlag to be set to 1 when i have opened a file so that if i re-open another file the #current can close resulting in me being able to open another file. If the flag is now set at 1 then how can i avoid closing #current when canceling open. I have tried going back to a branch label but the flag is still set at 1. And a while wend loop will result in me opening a file dialogue twice which is not user friendly. I am having no luck spent over an hour on this now . Surely its much simpler than this...
[Initialize] Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount Global filterCount, oldStage$, openFlag Nomainwin Dim name$(1000), nameSearch$(1000), stage$(20), type$(20) Dim builder$(1000, 13), existInfo$(10,10), hContents$(20)
dupo=0 addName=1
' Call loadNames
[GUI]
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0 WindowWidth = 495 '595 695 795 WindowHeight = 460 UpperLeftX=Int((DisplayWidth-WindowWidth)/2) UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
Statictext #main, "Shortcuts", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 140, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 160, 25 Statictext #main.3, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 160, 25
button #main.browse, "Open", [load], UL, 320, 80, 50, 20 ' button #main.run, "Open", [open], UL, 435, 10, 40, 20 button #main.run2, "Save File As", [save], UL, 375, 80, 90, 20
button #main.browse, "Remove", removeEntry, UL, 320, 130, 50, 20 Button #main.new, "&New Entry", addRecord, UL, 10, 360
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save Entry", acceptEntry, UL, 350, 360 Open "Test" For Window As #main Print #main, "Trapclose endProgram"
Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect"
#main.number "!show"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop] Wait
[acceptEntry] Call acceptEntry handle$ Wait
[addRecord] Call addRecord handle$ Wait
[save]
'FileDialog "Select a file", "*.bak*;*.dat*", nameoffile$ 'if nameoffile$="" then wait prompt "Enter the file name to save"; newfilename$ ' if newfilename$ <> "" then ' notice "j" ' else
'file$ open file$ for input as #old open newfilename$;".dat" for output as #new open newfilename$;".bak" for output as #new1 #new, input$(#old,lof(#old)); close #old close #new close #new1
wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ if openFlag =1 then close #current if openFlag =3 then close #current close #main end End Sub
[load] call loadNames handle$ wait
Sub loadNames handle$
'Print #main.contacts, "SelectIndex 0"
redim name$(1000) filedialog "Open Original file...","*.dat",file$ if file$="" then openFlag =3
if openFlag =1 then close #current
'goto [reset]
openFlag=3 ' 'while file$="" 'openFlag=2 'close openFLag =1 'openFlag =1 'wend
Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 ' Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$ #main.contacts "reload"
Next index
#main.contacts "reload" redim name$(1000) openFlag=1 ' Close #current ' Close #currentCopy
else if openFlag = 2 then
' Open file$ For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index
#main.contacts "reload" redim name$(1000) openFlag=1
else 'get user to open main file ' filedialog "Open Original file...","*.dat",file$ ' if file$ = "" then wait Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ end if ' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index
#main.contacts "reload" redim name$(1000) openFlag=1 ' Close #current ' Close #currentCopy
end if [skipIt] End Sub
Sub initializeNames
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #current, 1 #main.contacts "reload" ' Close #current End Sub
[moveOn]
Sub modifyRecord handle$ addName = 0
Print #main.contacts, "Selection? selection$" If selection$ = "" Then [noName]
Print #main.contacts, "SelectionIndex? index" If index = 0 Then [noName] 'This should never need to happen recordIndex=val(selection$) [getContactRecord] getIndex=recordIndex+1 'Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Gettrim #current, getIndex ' Close #current Print #main.name, name$ Print #main.number, number$
[noName] End Sub
Sub addRecord handle$ addName = 1 Print #main.contacts, "SelectIndex 0" Print #main.name, "" Print #main.number, ""
' Print #main.stage, "SelectIndex 20" ' Print #main.type, "SelectIndex 20"
Print #main.name, "!SetFocus"
End Sub
Sub acceptEntry handle$ Print #main.name, "!contents? name$"; If name$<>"" Then Print #main.name, "!contents? number$"; Print #main.number, "!contents? number$"; ' Print #main.type, "Selection? type$"; 'Print #main.stage, "Selection? stage$"; If addName = 1 Then contactCount = contactCount + 1 recordIndex = contactCount End If name$(recordIndex) = Str$(recordIndex)+") "+name$ Print #main.contacts, "Reload" redim name$(1000) date$=Date$() If oldStage$="Opening Mailer" And stage$="Follow Up Call" then mailDate$=Date$() End If [saveContactRecord] ' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Put #current, recordIndex + 1 ' Close #current If addName = 0 Then [goBack] ' Open file$ For Random As #current Len = 710 Field #current, 35 As count$, 675 As fill$ count$ = Str$(contactCount) Put #current, 1 ' Close #current addName = 0
[goBack] Print #main.contacts, "SelectIndex ";recordIndex Call addRecord handle$ Else Notice "NO BUSINESS NAME"+Chr$(13)+"The business name must be entered, "_ +Chr$(13)+"before a record can be saved. " End If End Sub
Sub populateList ' Open file$ For random As #current3 Len = 710 ' Field #current3, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact.dat" For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ #main.contacts "reload"
Get #current3, 1 contactCount = Val(name$) Put #current, 1
For index2 = 2 To contactCount + 1 Gettrim #current3, index2
For column=1 To 4 Select Case column Case 1 builder$(index2, column)=name$ Case 2 builder$(index2, column)=number$
Case 3 builder$(index2, column)=stage$ Case 4 builder$(index2, column)=type$
End Select Next column Next index2 #main.contacts "reload" End Sub
Sub saveList For index2 = 2 To contactCount + 1 For column=1 To 4 Select Case column Case 1 name$=builder$(index2, column) Case 2 number$=builder$(index2, column) Case 3 stage$=builder$(index2, column) Case 4 type$=builder$(index2, column)
End Select Next column Put #current, index2 Next index2
' Close #current3 Close #current
End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry handle$ ' Print #main.filtertype, "selection? filter$" If addName=0 Then Confirm "YOU ARE ABOUT TO DELETE THIS RECORD"+Chr$(13)+" "+Chr$(13)+Chr$(34)_ +name$(recordIndex)+Chr$(34)+Chr$(13)+" "+Chr$(13)+"Do you want to proceed?";delAns$ If Lower$(delAns$)="no" Then [noDelete] WindowWidth=150 WindowHeight=75 StaticText #patience, "PLEASE WAIT...", 10, 15, 100, 25 Open "DELETING...", For Dialog_Modal As #patience
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #current, moveRecords+1 Put #current, moveRecords Next moveRecords
Get #current, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #current, 1
' Close #current Close #patience openFlag = 2 Call loadNames handle$ Notice "RECORD DELETED"+Chr$(13)+"Names reloaded" Else Notice "NO RECORD SELECTED!"+Chr$(13)+"Please select a record," _ +Chr$(13)+"then select delete from the menu." End If
[noDelete] End Sub
[reset] openFlag =2 wait
|
|
|
Post by Rod on Jan 8, 2020 9:54:50 GMT -5
if the file is closed openFlag should be 0 if it is open it should be 1. That part is easy. So if your code cancels when a file is open it should close the file and set openFlag to 0. If it cancels when the file is yet to be opened openFlag should remain at 0 Then repeating loadnames knows what it is dealing with. An open file or not. We will make a programmer of you yet 😀
|
|
|
Post by wexhammer on Jan 8, 2020 10:42:41 GMT -5
Ok so now i can still select a name but now it cant find my branch label even though it found it the first time. So something is seriously wrong here
[Initialize] Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount Global filterCount, oldStage$, openFlag Nomainwin Dim name$(1000), nameSearch$(1000), stage$(20), type$(20) Dim builder$(1000, 13), existInfo$(10,10), hContents$(20)
dupo=0 addName=1
' Call loadNames
[GUI]
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0 WindowWidth = 495 '595 695 795 WindowHeight = 460 UpperLeftX=Int((DisplayWidth-WindowWidth)/2) UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
Statictext #main, "Shortcuts", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 140, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 160, 25 Statictext #main.3, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 160, 25
button #main.browse, "Open", [load], UL, 320, 80, 50, 20 ' button #main.run, "Open", [open], UL, 435, 10, 40, 20 button #main.run2, "Save File As", [save], UL, 375, 80, 90, 20
button #main.browse, "Remove", removeEntry, UL, 320, 130, 50, 20 Button #main.new, "&New Entry", addRecord, UL, 10, 360
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save Entry", acceptEntry, UL, 350, 360 Open "Test" For Window As #main Print #main, "Trapclose endProgram"
Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect"
#main.number "!show"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop] Wait
[acceptEntry] Call acceptEntry handle$ Wait
[addRecord] Call addRecord handle$ Wait
[save]
'FileDialog "Select a file", "*.bak*;*.dat*", nameoffile$ 'if nameoffile$="" then wait prompt "Enter the file name to save"; newfilename$ ' if newfilename$ <> "" then ' notice "j" ' else
'file$ open file$ for input as #old open newfilename$;".dat" for output as #new open newfilename$;".bak" for output as #new1 #new, input$(#old,lof(#old)); close #old close #new close #new1
wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ if openFlag =1 then close #current if openFlag =3 then close #current close #main end End Sub
[load] call loadNames handle$ wait
Sub loadNames handle$
'Print #main.contacts, "SelectIndex 0"
redim name$(1000) filedialog "Open Original file...","*.dat",file$ if file$="" then wait
if openFlag =1 then close #current
'goto [reset]
openFlag=3 ' 'while file$="" 'openFlag=2 'close openFLag =1 'openFlag =1 'wend
Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 ' Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$ #main.contacts "reload"
Next index
#main.contacts "reload" redim name$(1000) openFlag=1 ' Close #current ' Close #currentCopy
else if openFlag = 2 then
' Open file$ For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index
#main.contacts "reload" redim name$(1000) openFlag=1
else 'get user to open main file ' filedialog "Open Original file...","*.dat",file$ ' if file$ = "" then wait Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ end if ' Open "contact4.bak" For Random As #currentCopy Len = 710 ' Field #currentCopy, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ ' If Eof(#current) <> 0 Then ' Close #current ' Close #currentCopy Call initializeNames Goto [skipIt] End If
Get #current, 1 Get #current, 1 ' Put #currentCopy, 1
contactCount = Val(name$) If contactCount = 0 Then ' Close #current ' Close #currentCopy Goto [skipIt] openFlag=1 call populateList End If For index = 2 To contactCount + 1 Gettrim #current, index Put #current, index name$(index - 1) = str$(index-1)+") "+name$
Next index
#main.contacts "reload" redim name$(1000) openFlag=1 ' Close #current ' Close #currentCopy
end if [skipIt] End Sub
Sub initializeNames
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #current, 1 #main.contacts "reload" ' Close #current End Sub
[moveOn]
Sub modifyRecord handle$ addName = 0
Print #main.contacts, "Selection? selection$" If selection$ = "" Then [noName]
Print #main.contacts, "SelectionIndex? index" If index = 0 Then [noName] 'This should never need to happen recordIndex=val(selection$) [getContactRecord] getIndex=recordIndex+1 'Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Gettrim #current, getIndex ' Close #current Print #main.name, name$ Print #main.number, number$
[noName] End Sub
Sub addRecord handle$ addName = 1 Print #main.contacts, "SelectIndex 0" Print #main.name, "" Print #main.number, ""
' Print #main.stage, "SelectIndex 20" ' Print #main.type, "SelectIndex 20"
Print #main.name, "!SetFocus"
End Sub
Sub acceptEntry handle$ Print #main.name, "!contents? name$"; If name$<>"" Then Print #main.name, "!contents? number$"; Print #main.number, "!contents? number$"; ' Print #main.type, "Selection? type$"; 'Print #main.stage, "Selection? stage$"; If addName = 1 Then contactCount = contactCount + 1 recordIndex = contactCount End If name$(recordIndex) = Str$(recordIndex)+") "+name$ Print #main.contacts, "Reload" redim name$(1000) date$=Date$() If oldStage$="Opening Mailer" And stage$="Follow Up Call" then mailDate$=Date$() End If [saveContactRecord] ' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ Put #current, recordIndex + 1 ' Close #current If addName = 0 Then [goBack] ' Open file$ For Random As #current Len = 710 Field #current, 35 As count$, 675 As fill$ count$ = Str$(contactCount) Put #current, 1 ' Close #current addName = 0
[goBack] Print #main.contacts, "SelectIndex ";recordIndex Call addRecord handle$ Else Notice "NO BUSINESS NAME"+Chr$(13)+"The business name must be entered, "_ +Chr$(13)+"before a record can be saved. " End If End Sub
Sub populateList ' Open file$ For random As #current3 Len = 710 ' Field #current3, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
' Open "contact.dat" For Random As #current Len = 710 ' Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$ #main.contacts "reload"
Get #current3, 1 contactCount = Val(name$) Put #current, 1
For index2 = 2 To contactCount + 1 Gettrim #current3, index2
For column=1 To 4 Select Case column Case 1 builder$(index2, column)=name$ Case 2 builder$(index2, column)=number$
Case 3 builder$(index2, column)=stage$ Case 4 builder$(index2, column)=type$
End Select Next column Next index2 #main.contacts "reload" End Sub
Sub saveList For index2 = 2 To contactCount + 1 For column=1 To 4 Select Case column Case 1 name$=builder$(index2, column) Case 2 number$=builder$(index2, column) Case 3 stage$=builder$(index2, column) Case 4 type$=builder$(index2, column)
End Select Next column Put #current, index2 Next index2
' Close #current3 Close #current
End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry handle$ ' Print #main.filtertype, "selection? filter$" If addName=0 Then Confirm "YOU ARE ABOUT TO DELETE THIS RECORD"+Chr$(13)+" "+Chr$(13)+Chr$(34)_ +name$(recordIndex)+Chr$(34)+Chr$(13)+" "+Chr$(13)+"Do you want to proceed?";delAns$ If Lower$(delAns$)="no" Then [noDelete] WindowWidth=150 WindowHeight=75 StaticText #patience, "PLEASE WAIT...", 10, 15, 100, 25 Open "DELETING...", For Dialog_Modal As #patience
' Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #current, moveRecords+1 Put #current, moveRecords Next moveRecords
Get #current, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #current, 1
' Close #current Close #patience openFlag = 2 Call loadNames handle$ Notice "RECORD DELETED"+Chr$(13)+"Names reloaded" Else Notice "NO RECORD SELECTED!"+Chr$(13)+"Please select a record," _ +Chr$(13)+"then select delete from the menu." End If
[noDelete] End Sub
[reset] openFlag =2 wait
|
|
|
Post by Rod on Jan 8, 2020 11:02:45 GMT -5
Give us a clue, what branch label? If you are going to mess with code as complex as this you need to be more precise and more descriptive. I don't feel that I am giving you useful advice. We just keep stumbling around. We have stumbled to the current problem, how to deal with a change of file that is cancelled. Here is one way.
global contactCount,openFlag dim name$(100)
[GUI]
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0 WindowWidth = 495 '595 695 795 WindowHeight = 460 UpperLeftX=Int((DisplayWidth-WindowWidth)/2) UpperLeftY=Int((DisplayHeight-WindowHeight)/2) Statictext #main, "Shortcuts", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 140, 120 Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 160, 25 Statictext #main.3, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 160, 25 button #main.browse, "Open", loadNames, UL, 320, 80, 50, 20 button #main.run2, "Save File As", saveit, UL, 375, 80, 90, 20 Button #main.new, "&New Entry", addRecord, UL, 10, 360 Button #main.remove, "&Remove Entry", removeEntry , UL, 190, 360 Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save Entry", acceptEntry, UL, 350, 360 Open "Test" For Window As #main #main "Trapclose endProgram" #main.contacts "SingleClickSelect" #main.namel "SingleClickSelect" #main.contacts "Setfocus" Wait
Sub endProgram handle$ if openFlag then close #current close #main end End Sub
Sub loadNames handle$
'get new file name filedialog "Open Original file...","*.dat",file$
'if it is "" do nothing if files$="" then [abort]
'else close old file open the new one and load the data if openFlag then close #current Open file$ For Random As #current Len = 710 Field #current, 335 As name$, 335 As number$, 20 As stage$, 20 As type$
'if it is a new blank file set contactCount if lof(#current)=0 then name$ = "0" put #current, 1 else get #current, 1 contactCount = Val(name$) end if
'set the flag so we know if a file is open or not when we end the program openFlag=1
'now update all the arrays call populateList
'bale out doing nothing here [abort] end Sub
Sub populateList for index = 2 to contactCount + 1 gettrim #current, index name$(index)=name$ next index #main.contacts "reload" End Sub
|
|