|
Post by tsh73 on Jan 10, 2020 14:13:22 GMT -5
To make count respect your filters you should base on loadNamesFiltered, not on loadNames BTW I see filters
Print #filter, "All" Print #filter, "Complete" Print #filter, "Incomplete" Print #filter, "Neutral" - where you got "JAN"?
|
|
|
Post by wexhammer on Jan 10, 2020 14:18:08 GMT -5
I pasted the wrong code sorry
[Initialize] Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount Global filterCount, oldStage$ Nomainwin Dim name$(1000), nameSearch$(1000), stage$(20), type$(20) Dim builder$(1000, 13), existInfo$(10,10), hContents$(20)
If Not(exists("filter.lst")) Then Open "filter.lst" For Output As #filter Print #filter, 4 Print #filter, "All" Print #filter, "JAN" Print #filter, "FEB" Print #filter, "MARCH
Close #filter End If
Open "filter.lst" For Input As #filter Input #filter, filterCount For filterIndex=0 to filterCount-1 Input #filter, filterName$ stage$(filterIndex)=filterName$ Next filterIndex Close #filter
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, "Names", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 160, 120 Statictext #main, "Filter stage", 10, 170, 160, 20 Combobox #main.filterstage, stage$(, loadNamesFiltered, 10, 190, 160, 120 'Statictext #main, "Filter type", 10, 220, 160, 20 'Combobox #main.filtertype, type$(, loadNamesFiltered, 10, 240, 160, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 225, 25 Statictext #main, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 225, 25
Statictext #main, "Stage", 195, 70, 50, 20 Combobox #main.stage, stage$(, [inputLoop], 250, 70, 225, 110 'Statictext #main, "Type", 195, 100, 50, 20 ' Combobox #main.type, type$(, [inputLoop], 250, 100, 225, 110 statictext #main, "Total of numbers:", 10, 235,90, 15 Textbox #main.totalofall, 100, 235, 70, 25 Button #main.new, "Calc", [calculate], UL, 180, 235, 40, 20
Button #main.new, "&New", addRecord, UL, 365, 120
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save", acceptEntry, UL, 420, 120 Open "Test" For Window As #main Print #main, "Trapclose endProgram" 'Print #main.filtertype, "Select All"; Print #main.filterstage, "Select All"; Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop] Wait
[acceptEntry] Call acceptEntry handle$ Wait
[addRecord] Call addRecord handle$ Wait
[calculate] Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ 'gettrim #contacts, number
get #contacts, 1
contactCount = Val(name$) matchup = val(stage$) '(1) - contactCount - done
'(2) total = 0 'init total with 0, May be up there but I moved it to a loop 'the loop For index = 2 To contactCount + 1
'(3) for each loop iteration '--get info Gettrim #contacts, index 'add number total = total + val(number$) Next index
For index = 2 To matchup + 1 Gettrim #contacts, index matchup = matchup * val(number$) If stage$ = "JAN" then ' stage$(index - 1) = str$(index-1)+") " = number$ Else stage$(index - 1) = "" total = total + val(number$) End If Next index 'we are through - close the file close #contacts
'(4) we got the total, show it print #main.totalofall, total
'that's all, really
wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ close #main end End Sub
Sub loadNames If exists("contact4old.bak") Then Kill "contact4old.bak" End If If exists("contact4.bak") Then Name "contact4.bak" As "contact4old.bak" End If Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
Open "contact4.bak" For Random As #contactsCopy Len = 110 Field #contactsCopy, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
If Eof(#contacts) <> 0 Then Close #contacts Close #contactsCopy Call initializeNames Goto [skipIt] End If
Get #contacts, 1 Put #contactsCopy, 1
contactCount = Val(name$) If contactCount = 0 Then Close #contacts Close #contactsCopy Goto [skipIt] End If For index = 2 To contactCount + 1 Gettrim #contacts, index Put #contactsCopy, index name$(index - 1) = str$(index-1)+") "+name$
Next index Close #contacts Close #contactsCopy [skipIt] End Sub
Sub initializeNames
Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #contacts, 1 Close #contacts End Sub
Sub loadNamesFiltered handle$ redim name$(1000) 'show records matching filter Call addRecord handle$ Print #main.filterstage, "selection? filter$"
Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ Get #contacts, 1 contactCount = Val(name$) If contactCount = 0 Then Close #contacts Goto [moveOn] End If 'compare stage to filter
For index = 2 To contactCount + 1 Gettrim #contacts, index If filter$ = stage$ or filter$ = "All" Then 'If filter2$ = type$ or filter2$ = "All" Then name$(index - 1) = str$(index-1)+") "+name$ Else name$(index - 1) = ""
end if
Next index
Close #contacts
Print #main.contacts, "Reload"
[moveOn]
End Sub
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 "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ Gettrim #contacts, getIndex Close #contacts Print #main.name, name$ Print #main.number, number$
Print #main.stage, "SelectIndex 20" 'Print #main.type, "SelectIndex 20" For stageIndex = 0 To filterCount-1 If stage$(stageIndex) = stage$ Then
Print #main.stage, "SelectIndex "; stageIndex + 1 end if
Next stageIndex
oldStage$=stage$ [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 "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ Put #contacts, recordIndex + 1 Close #contacts If addName = 0 Then [goBack] Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As count$, 75 As fill$ count$ = Str$(contactCount) Put #contacts, 1 Close #contacts addName = 0 Call loadNamesFiltered " " [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 "contact4.dat" For random As #contacts3 Len = 110 Field #contacts3, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
Open "contact.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
Get #contacts3, 1 contactCount = Val(name$) Put #contacts, 1
For index2 = 2 To contactCount + 1 Gettrim #contacts3, 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 #contacts, index2 Next index2
Close #contacts3 Close #contacts If exists("contact4recoverold.bak") Then Kill "contact4recoverold.bak" End If If exists("contact4recover.bak") Then Name "contact4recover.bak" As "contact4recoverold.bak" End If Name "contact4.dat" As "contact4recover.bak" Name "contact.dat" As "contact4.dat" End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry ' 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 "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #contacts, moveRecords+1 Put #contacts, moveRecords Next moveRecords
Get #contacts, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #contacts, 1
Close #contacts Close #patience Call loadNames Call loadNamesFiltered 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 metro on Jan 10, 2020 18:42:02 GMT -5
I have a great deal of trouble concentrating so when I develop a long program instead of trying to trouble shoot code I'm having difficulty with in the main program I open a second or third copy of the LB editor and try to solve the problem there. I then slot that code back into the main program. Now bear in mind I have never used Random Files I prefer SQLite. I tackled your problem using my method, others will have better ways but I got the result that works for me.
GLOBAL NumRecs , AllGrandTotal st$="All;Complete;Incomplete;Neutral"
call NumRecs
for a = 1 to 4 Filter$ = word$(st$,a, ";") call AddNums Filter$ next
print "Total for all " ; AllGrandTotal
print:print:print print "YAHoo Finished" WAIT
SUB NumRecs open "contact4.dat"for input as #1 qtyBytes = lof(#1) NumRecs= qtyBytes/110 close #1 END SUB
SUB AddNums Filter$ GrandTotal=0 : AllGrandTotal=0 Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ For index = 1 To NumRecs Gettrim #contacts, index
SELECT CASE stage$ case "Complete","Incomplete","Neutral" if Filter$= stage$ then GrandTotal=GrandTotal+VAL(number$) end if case else end select
AllGrandTotal=AllGrandTotal+VAL(number$)
next If Filter$ <> "All" then print "grand Total for "; Filter$ ;" is : ";GrandTotal end if close #contacts END SUB
|
|
|
Post by wexhammer on Jan 11, 2020 5:43:30 GMT -5
A big thanks to Metro for the help! Got it working now and understand. However using the same method i am trying to just get the total of all numeric values in the contacts within the month March, yet its not printing anything to my textbox or calculating properly. The modified code is below:
[Initialize] Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount Global filterCount, oldStage$, AllGrandTotal Nomainwin Dim name$(1000), nameSearch$(1000), stage$(20), type$(20) Dim builder$(1000, 13), existInfo$(10,10), hContents$(20)
If Not(exists("filter.lst")) Then Open "filter.lst" For Output As #filter Print #filter, 4 Print #filter, "All" Print #filter, "JAN" Print #filter, "FEB" Print #filter, "MARCH"
Close #filter End If
Open "filter.lst" For Input As #filter Input #filter, filterCount For filterIndex=0 to filterCount-1 Input #filter, filterName$ stage$(filterIndex)=filterName$ Next filterIndex Close #filter
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, "Names", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 160, 120 Statictext #main, "Filter stage", 10, 170, 160, 20 Combobox #main.filterstage, stage$(, loadNamesFiltered, 10, 190, 160, 120 'Statictext #main, "Filter type", 10, 220, 160, 20 'Combobox #main.filtertype, type$(, loadNamesFiltered, 10, 240, 160, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 225, 25 Statictext #main, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 225, 25
Statictext #main, "Stage", 195, 70, 50, 20 Combobox #main.stage, stage$(, [inputLoop], 250, 70, 225, 110 'Statictext #main, "Type", 195, 100, 50, 20 ' Combobox #main.type, type$(, [inputLoop], 250, 100, 225, 110 statictext #main, "Total of numbers:", 10, 215,90, 15 statictext #main, "JAN", 10, 235,90, 15 statictext #main, "FEB", 10, 265,90, 15 statictext #main, "MARCH", 10, 305,90, 15 Textbox #main.jantotal, 100, 235, 170, 25 Textbox #main.febtotal, 100, 265, 170, 25 Textbox #main.marchtotal, 100, 305, 170, 25 Button #main.new, "Calc", [calculate], UL, 270, 235, 40, 20
Button #main.new, "&New", addRecord, UL, 365, 120
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save", acceptEntry, UL, 420, 120 Open "Test" For Window As #main Print #main, "Trapclose endProgram" 'Print #main.filtertype, "Select All"; Print #main.filterstage, "Select All"; Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop] Wait
[acceptEntry] Call acceptEntry handle$ Wait
[addRecord] Call addRecord handle$ Wait
[calculate] 'Print #main.filterstage, "selection? filterName$" GrandTotal=0 : AllGrandTotal=0 Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ 'gettrim #contacts, number
For index = 2 To contactCount + 1 Gettrim #contacts, index
if stage$= "MARCH" then GrandTotal=GrandTotal+VAL(number$) end if
AllGrandTotal=AllGrandTotal+VAL(number$)
next If stage$ <> "MARCH" then print #main.marchtotal, "grand Total for "; stage$ ;" is : ";GrandTotal
close #contacts
end if
wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ close #main end End Sub
Sub loadNames If exists("contact4old.bak") Then Kill "contact4old.bak" End If If exists("contact4.bak") Then Name "contact4.bak" As "contact4old.bak" End If Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
Open "contact4.bak" For Random As #contactsCopy Len = 110 Field #contactsCopy, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
If Eof(#contacts) <> 0 Then Close #contacts Close #contactsCopy Call initializeNames Goto [skipIt] End If
Get #contacts, 1 Put #contactsCopy, 1
contactCount = Val(name$) If contactCount = 0 Then Close #contacts Close #contactsCopy Goto [skipIt] End If For index = 2 To contactCount + 1 Gettrim #contacts, index Put #contactsCopy, index name$(index - 1) = str$(index-1)+") "+name$
Next index Close #contacts Close #contactsCopy [skipIt] End Sub
Sub initializeNames
Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #contacts, 1 Close #contacts End Sub
Sub loadNamesFiltered handle$ redim name$(1000) 'show records matching filter Call addRecord handle$ Print #main.filterstage, "selection? filter$"
Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ Get #contacts, 1 contactCount = Val(name$) If contactCount = 0 Then Close #contacts Goto [moveOn] End If 'compare stage to filter
For index = 2 To contactCount + 1 Gettrim #contacts, index If filter$ = stage$ or filter$ = "All" Then 'If filter2$ = type$ or filter2$ = "All" Then name$(index - 1) = str$(index-1)+") "+name$ Else name$(index - 1) = ""
end if
Next index
Close #contacts
Print #main.contacts, "Reload"
[moveOn]
End Sub
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 "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ Gettrim #contacts, getIndex Close #contacts Print #main.name, name$ Print #main.number, number$
Print #main.stage, "SelectIndex 20" 'Print #main.type, "SelectIndex 20" For stageIndex = 0 To filterCount-1 If stage$(stageIndex) = stage$ Then
Print #main.stage, "SelectIndex "; stageIndex + 1 end if
Next stageIndex
oldStage$=stage$ [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 "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ Put #contacts, recordIndex + 1 Close #contacts If addName = 0 Then [goBack] Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As count$, 75 As fill$ count$ = Str$(contactCount) Put #contacts, 1 Close #contacts addName = 0 Call loadNamesFiltered " " [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 "contact4.dat" For random As #contacts3 Len = 110 Field #contacts3, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
Open "contact.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
Get #contacts3, 1 contactCount = Val(name$) Put #contacts, 1
For index2 = 2 To contactCount + 1 Gettrim #contacts3, 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 #contacts, index2 Next index2
Close #contacts3 Close #contacts If exists("contact4recoverold.bak") Then Kill "contact4recoverold.bak" End If If exists("contact4recover.bak") Then Name "contact4recover.bak" As "contact4recoverold.bak" End If Name "contact4.dat" As "contact4recover.bak" Name "contact.dat" As "contact4.dat" End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry ' 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 "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #contacts, moveRecords+1 Put #contacts, moveRecords Next moveRecords
Get #contacts, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #contacts, 1
Close #contacts Close #patience Call loadNames Call loadNamesFiltered 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 metro on Jan 11, 2020 6:12:15 GMT -5
Give this a try double click on the second listbox choice
st$="All;Complete;Incomplete;Neutral"
for a = 1 to 4 stage1$(a)= word$(st$,a, ";")
next
[Initialize] Global hMain, hFind, dupNum, dupo, addName, recordIndex, contactCount,NumRecs Global filterCount, oldStage$ ' 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, "Names", 10, 10, 60, 20 Listbox #main.contacts, name$(, modifyRecord, 10, 35, 160, 120 Listbox #main.Filter ,stage1$(),[calculate], 10, 165, 160, 60 ' Statictext #main, "Filter stage", 10, 170, 160, 20 'Combobox #main.filterstage, stage$(, loadNamesFiltered, 10, 190, 160, 120 ' Statictext #main, "Filter type", 10, 220, 160, 20 ' Combobox #main.filtertype, type$(, loadNamesFiltered, 10, 240, 160, 120
Statictext #main, "Name", 195, 10, 50, 20 Textbox #main.name, 250, 10, 225, 25 Statictext #main, "Number", 195, 40, 50, 20 Textbox #main.number, 250, 40, 225, 25
'Statictext #main, "Stage", 195, 70, 50, 20 'Combobox #main.stage, stage$(, [inputLoop], 250, 70, 225, 110 ' Statictext #main, "Type", 195, 100, 50, 20 'Combobox #main.type, type$(, [inputLoop], 250, 100, 225, 110 'statictext #main.txt, "Total of numbers:", 10, 225,90, 15 Textbox #main.totalofall, 10, 225, 150, 25 Button #main.new, "Calc", [calculate], UL, 180, 225, 40, 20
Button #main.new, "&New", addRecord, UL, 365, 80
Listbox #main.namel, dup$(, pick, 490, 10, 190, 395 Button #main.OK, "Save", acceptEntry, UL, 420, 80 Open "Test" For Window As #main
Print #main, "Trapclose endProgram" ' Print #main.filtertype, "Select All"; ' Print #main.filterstage, "Select All"; Print #main.contacts, "SingleClickSelect" Print #main.namel, "SingleClickSelect" ' #main.totalofall "!disable"
[Code]
Print #main.contacts, "Setfocus" #main.Filter , "reload" [inputLoop] Wait
[acceptEntry] Call acceptEntry handle$ Wait
[addRecord] Call addRecord handle$ Wait
[calculate] #main.Filter , "selection? stage$" call NumRecs call AddNums stage$ print "here"
wait
[endProgram] Call endProgram handle$ Wait
Sub endProgram handle$ close #main end End Sub
Sub loadNames If exists("contact4old.bak") Then Kill "contact4old.bak" End If If exists("contact4.bak") Then Name "contact4.bak" As "contact4old.bak" End If Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
Open "contact4.bak" For Random As #contactsCopy Len = 110 Field #contactsCopy, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
If Eof(#contacts) <> 0 Then Close #contacts Close #contactsCopy Call initializeNames Goto [skipIt] End If
Get #contacts, 1 Put #contactsCopy, 1
contactCount = Val(name$) If contactCount = 0 Then Close #contacts Close #contactsCopy Goto [skipIt] End If For index = 2 To contactCount + 1 Gettrim #contacts, index Put #contactsCopy, index name$(index - 1) = str$(index-1)+") "+name$
Next index Close #contacts Close #contactsCopy [skipIt] End Sub
Sub initializeNames
Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ name$ = "0" Put #contacts, 1 Close #contacts End Sub
Sub loadNamesFiltered handle$ redim name$(1000) 'show records matching filter Call addRecord handle$ 'Print #main.filterstage, "selection? filter$" 'Print #main.filtertype, "selection? filter2$" Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ Get #contacts, 1 contactCount = Val(name$) If contactCount = 0 Then Close #contacts Goto [moveOn] End If 'compare stage to filter
For index = 2 To contactCount + 1 Gettrim #contacts, index If filter$ = stage$ or filter$ = "All" Then If filter2$ = type$ or filter2$ = "All" Then name$(index - 1) = str$(index-1)+") "+name$ Else name$(index - 1) = "" End If end if
Next index
Close #contacts
Print #main.contacts, "Reload"
[moveOn]
End Sub
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 "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ Gettrim #contacts, getIndex Close #contacts Print #main.name, name$ Print #main.number, number$
' Print #main.stage, "SelectIndex 20" ' Print #main.type, "SelectIndex 20" 'For stageIndex = 0 To filterCount-1 '
' Print #main.stage, "SelectIndex "; stageIndex + 1
oldStage$=stage$ [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 "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ Put #contacts, recordIndex + 1 Close #contacts If addName = 0 Then [goBack] Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As count$, 75 As fill$ count$ = Str$(contactCount) Put #contacts, 1 Close #contacts addName = 0 Call loadNamesFiltered " " [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 "contact4.dat" For random As #contacts3 Len = 110 Field #contacts3, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
Open "contact.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
Get #contacts3, 1 contactCount = Val(name$) Put #contacts, 1
For index2 = 2 To contactCount + 1 Gettrim #contacts3, 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 #contacts, index2 Next index2
Close #contacts3 Close #contacts If exists("contact4recoverold.bak") Then Kill "contact4recoverold.bak" End If If exists("contact4recover.bak") Then Name "contact4recover.bak" As "contact4recoverold.bak" End If Name "contact4.dat" As "contact4recover.bak" Name "contact.dat" As "contact4.dat" End Sub
Function exists(a$) Files DefaultDir$, a$, existInfo$() exists=val(existInfo$(0,0)) End Function
Sub removeEntry '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 "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$
For moveRecords=recordIndex+1 To contactCount Get #contacts, moveRecords+1 Put #contacts, moveRecords Next moveRecords
Get #contacts, 1 name$(Val(name$))="" name$=Str$(Val(name$)-1) Put #contacts, 1
Close #contacts Close #patience Call loadNames Call loadNamesFiltered 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
SUB NumRecs open "contact4.dat"for input as #1 qtyBytes = lof(#1) NumRecs= qtyBytes/110 close #1 END SUB
SUB AddNums Filter$ GrandTotal=0 : AllGrandTotal=0 Open "contact4.dat" For Random As #contacts Len = 110 Field #contacts, 35 As name$, 35 As number$, 20 As stage$, 20 As type$ For index = 1 To NumRecs Gettrim #contacts, index
SELECT CASE stage$ ' print stage$;" "; number$ case "Complete","Incomplete","Neutral" if Filter$= stage$ then GrandTotal=GrandTotal+VAL(number$) end if case else end select
AllGrandTotal=AllGrandTotal+VAL(number$) #main.totalofall, Filter$;" ";AllGrandTotal ' #main.totalofall, 50 next If Filter$ <> "All" then #main.totalofall,Filter$;" ";GrandTotal ' print "grand Total for "; Filter$ ;" is : ";GrandTotal end if
close #contacts END SUB
|
|
|
Post by wexhammer on Jan 11, 2020 7:31:03 GMT -5
Legend! Cheers Metro, makes much sense now!
|
|