Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search and display a file

Status
Not open for further replies.

TXH0207

Programmer
Jun 20, 2004
15
US
Hello, I am having a problem trying to write a procedure that will search for files that I have saved and display them. I save my files with a zip code and a customer number, so that they could be looked up by any of these two ways.

Here is the code that I used to save it. Any help with going in the right direction would be greatly appreciated.

Public Sub Save()
'This checks to make sure that there is text
'in the customer number and zip text box.
If txtCustomerNumber.Text = "" And txtZip.Text = "" Then
MsgBox "Customer Number or Zip Code" & vbCrLf _
& "must be filled in."
Exit Sub
End If
'This saves the file by customer number
If txtCustomerNumber.Text <> "" Then
Open "C:\STI\Customers\" & UCase$(txtCustomerNumber.Text) For Output As #1
Write #1, "Facility: " & UCase$(txtName.Text), "Date: " & UCase$(txtDate.Text)
Write #1, "Address: " & UCase$(txtAddress.Text), "City: " & UCase$(txtCity.Text), "State: " & UCase$(txtState.Text), _
"Zip: " & txtZip.Text
Write #1, "Phone: " & txtPhone.Text, "Fax: " & txtFax.Text, "Email: " & txtEmail.Text
Write #1, "Customer# " & UCase$(txtCustomerNumber.Text)
Write #1,
Write #1, "Comments:"
Write #1, UCase$(txtComments.Text)
Write #1,
Write #1,
Close #1
End If
'This saves the file by zip code
If txtZip.Text <> "" Then
Open "C:\STI\Customers\" & UCase$(txtZip.Text) For Output As #1
Write #1, "Facility: " & UCase$(txtName.Text), "Date: " & UCase$(txtDate.Text)
Write #1, "Address: " & UCase$(txtAddress.Text), "City: " & UCase$(txtCity.Text), "State: " & UCase$(txtState.Text), _
"Zip: " & txtZip.Text
Write #1, "Phone: " & txtPhone.Text, "Fax: " & txtFax.Text, "Email: " & txtEmail.Text
Write #1, "Customer# " & UCase$(txtCustomerNumber.Text)
Write #1,
Write #1, "Comments:"
Write #1, UCase$(txtComments.Text)
Write #1,
Write #1,
Close #1
End If
End Sub
 
Hi,

By using the API you can do all of this and more search the PDK documentation for File Management Functions and you'll get a list of Functions that will meet with your needs.

However, you may want to consider using a structure to store your data in, then writing the whole structure out to disk. This will allow you to store all your Customers in the same file. Of course this is of no use to you if the "structure" of the data being written isn't constant.

Assuming that the structure is static you can obtain the number of records in the file by dividing the size of the file with the size of the structure.

When you want to find a "Record" in the file you can seek to the byte position of the file, read the Customer Number (or Zip code, or any item in the structure) compare it with the value entered. If it's correct then display it, if it's not then move on to the next. etc.

This of course could get annoying (and slow) if you had many records in a file. But you can get round this by creating an index file (ideally btree) that stores the Zip code, Name and byte offset on the main data file.

HTH


William
Software Engineer
ICQ No. 56047340
 
William, thanks for the input. I am still new with vb , but starting to learn it pretty well. I really do not know how to use the API. I will have to do alot more learning on this. I am still in the basics of programming.

I thank you for the info that you gave me. Some day I hope to be at your knowledge of programming.

Happy programming!



Mike Haas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top