Post by wexhammer on Nov 26, 2019 5:45:36 GMT -5
I have made a small program were i can save and edit contacts, which works pretty well.
Recently i have attempted to add a search function, so when my button search is pressed based on what was entered in my search textbox, my contact list shows the name searched only. My code for the search does not seem to work, nor do i think it is correct.
Please help me out i would appreciate it very much!
Recently i have attempted to add a search function, so when my button search is pressed based on what was entered in my search textbox, my contact list shows the name searched only. My code for the search does not seem to work, nor do i think it is correct.
Please help me out i would appreciate it very much!
[Initialize]
Global hMain, hFind, addName, recordIndex, contactCount
Nomainwin
Dim name$(1000), nameSearch$(1000)
Dim builder$(1000, 2), existInfo$(10,10), hContents$(20)
addName=1
Call loadNames
[GUI]
Stylebits #main.memo, _WS_VSCROLL, _ES_AUTOHSCROLL, _ES_MULTILINE, 0 '
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0
WindowWidth = 605
WindowHeight = 600
UpperLeftX=Int((DisplayWidth-WindowWidth)/2)
UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
Textbox #main.searchbox, 340, 11, 140, 25
Button #main.search, "&Search",[searchcontact], UL, 495, 10
Statictext #main, "Contacts:", 10, 50, 60, 20
Listbox #main.contacts, name$(, editContact, 10, 80, 170, 235
Statictext #main, "Name:", 195, 80, 50, 20
Textbox #main.name, 250, 80, 285, 25
Statictext #main, "Address:", 195, 110, 50, 20
Textbox #main.contact, 250, 110, 285, 25
graphicbox #main.ss1, 10, 70, 525, 2
graphicbox #main.ss2, 195, 140, 340, 2
Button #main.new, "&New Record", addContact, UL, 195, 280
Button #main.OK, "S&ave Record", saveEntry, UL, 340, 280
Open "Search Program" For Window As #main
Print #main, "Trapclose endProgram"
Print #main.contacts, "SingleClickSelect"
#main.ss1 "down; fill darkGray; flush"
#main.ss2 "down; fill darkGray; flush"
hMain=hwnd(#main)
[Code]
Print #main.contacts, "Setfocus"
[inputLoop]
wait
[saveEntry]
Call saveEntry handle$
Wait
[addContact]
Call addContact handle$
Wait
[endProgram]
Call endProgram handle$
Wait
Sub endProgram handle$
close #main
end
End Sub
Sub loadNames
If exists("old.bak") Then
Kill "old.bak"
End If
If exists("contact.bak") Then
Name "contact.bak" As "old.bak"
End If
Open "contact.dat" For Random As #contacts Len = 70
Field #contacts, 35 As name$, 35 As contact$
Open "contact.bak" For Random As #contactsCopy Len = 70
Field #contactsCopy, 35 As name$, 35 As contact$
'create contact if the file doesnt exist:
If Eof(#contacts) <> 0 Then
Close #contacts
Close #contactsCopy
Call initializeNames
Goto [skipIt]
End If
'backup
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 "contact.dat" For Random As #contacts Len = 70
Field #contacts, 35 As name$, 35 As contact$
name$ = "0"
Put #contacts, 1
Close #contacts
End Sub
Function GetMenuItemID(hmenu,index)
Calldll #user, "GetMenuItemID", hmenu As Ulong, index As Ulong, GetMenuItemID As Ulong
End Function
Sub editContact handle$
addName = 0
Print #main.contacts, "Selection? selection$"
If selection$ = "" Then [noName]
Print #main.contacts, "SelectionIndex? index"
If index = 0 Then [noName]
recordIndex=val(selection$)
[getContactRecord]
getIndex=recordIndex+1
Open "contact.dat" For Random As #contacts Len = 70
Field #contacts, 35 As name$, 35 As contact$
Gettrim #contacts, getIndex
Close #contacts
Print #main.name, name$
Print #main.contact, contact$
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 addContact handle$
addName = 1
Print #main.contacts, "SelectIndex 0"
Print #main.name, ""
Print #main.contact, ""
Print #main.name, "!SetFocus"
End Sub
Sub saveEntry handle$
Print #main.name, "!contents? name$";
If name$<>"" Then
Print #main.contact, "!contents? contact$";
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 "contact.dat" For Random As #contacts Len = 70
Field #contacts, 35 As name$, 35 As contact$
Put #contacts, recordIndex + 1
Close #contacts
If addName = 0 Then [goBack]
Open "contact.dat" For Random As #contacts Len = 70
Field #contacts, 35 As count$, 35 As fill$
count$ = Str$(contactCount)
Put #contacts, 1
Close #contacts
addName = 0
[goBack]
Print #main.contacts, "SelectIndex ";recordIndex
Call addContact handle$
Else
Notice "There is no name!"+Chr$(13)+"You must enter a contact name "_
+Chr$(13)+"before a contact can be saved. "
End If
End Sub
Sub populateList
Open "contact4.dat" For random As #contacts3 Len = 70
Field #contacts3, 35 As name$, 35 As contact$
Open "contact.dat" For Random As #contacts Len = 70
Field #contacts, 35 As name$, 35 As contact$
Get #contacts3, 1
contactCount = Val(name$)
Put #contacts, 1
For index2 = 2 To contactCount + 1
Gettrim #contacts3, index2
For column=1 To 2
Select Case column
Case 1
builder$(index2, column)=name$
Case 2
builder$(index2, column)=contact$
End Select
Next column
Next index2
End Sub
Sub saveList
For index2 = 2 To contactCount + 1
For column=1 To 2
Select Case column
Case 1
name$=builder$(index2, column)
Case 2
contact$=builder$(index2, column)
End Select
Next column
Put #contacts, index2
Next index2
Close #contacts3
Close #contacts
If exists("contactrecoverold.bak") Then
Kill "contactrecoverold.bak"
End If
If exists("contactrecover.bak") Then
Name "contactrecover.bak" As "contactrecoverold.bak"
End If
Name "contact.dat" As "contactrecover.bak"
Name "contact.dat" As "contact.dat"
End Sub
Function exists(a$)
Files DefaultDir$, a$, existInfo$()
exists=val(existInfo$(0,0))
End Function
[searchcontact]
#main.searchbox "!contents? searchnow$"
if name$ = searchnow) then
Print #main.contacts, "searchnow$"
else
wait
end if