 |
 |

04-23-2004, 04:02 AM
|
|
Newcomer
|
|
Join Date: Mar 2004
Posts: 11
|
|
Ive made a mess of dislpaying informtaion from 2 files simultaneously
|
Hello! I'm fairly rudimentary at the programming could someone please help me with this!
I have two files "cars.txt" and "customers.txt" And upon pressing find car a loop will try to match a registration in "cars.txt" If a match is found then I want to display the information from the two files in labels.
I have had trouble combining the two files and the code doesnt work possibley due to bad ordering? Could someone please follow me through this.
Private Sub regfind()
'this is where i search thecustomers that came before. If the registration is not found then show a message box saying "add new customer" then set target to new registration. If the registration was found then display all details in a label. Also validate
foundcar = False
fn = FreeFile()
Open "N:\my pictures/cars.txt" For Input As #1
Open "N:\my pictures/customers.txt" For Input As #fn
Do While Not EOF(1) And Not foundcar
Input #1, registration, cartype, company, typecode, lsdate
Do While Not EOF(2)
Input #2, custname, address, town, postcode, telephone
If txtcustomercarreg = registration Then
foundcar = True
lbltyretype = "Tyre-type Code: " & typecode
lblcartype = "Car Manufacturer: " & cartype
lblcompname = "Customer Name: " & company
lblregs = "for registration " & registration
lblls = "LastService date: " & lsdate
End If
Loop
If company = custname Then
lbladdress = "Address: " & address & ", " & town
lblpostcode = postcode
lbltelephone = "Telephone: " & telephone
End If
Loop
Close #fn
If Not foundcar Then
MsgBox "REGISTRATION NOT FOUND" & Chr$(10) & "Please check or add new car to the database", vbExclamation + vbOK, "Registration not found"
End If
|
|

04-23-2004, 01:51 PM
|
 |
Bald Mountain Survivor
Super Moderator * Expert *
|
|
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,882
|
|
|
1) Are there a lot of entries for both files?
if the list is not too great then I would suggest pulling both files into datastructures and doing lookups there.
2) Looks like you are trying to use text files as a database.
Why not use a database file such as an MS Access (.mdb)
Lookups are what they do best.
'----
Meanwhile I'll look over your code.
~T
|
__________________
Burn the land and boil the sea
You can't take the sky from me
~T
|

04-23-2004, 02:09 PM
|
 |
Bald Mountain Survivor
Super Moderator * Expert *
|
|
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,882
|
|
Okay I formatted your code with indents so we can see the structures better.
1) I do not see you declaring 'foundcar' or 'fn' as variables. Are you using Option Explicit at the top of your form/module?
2) Even though you are getting a file handle number with fn = freefile you are not using it after the second Open statement. You use the number 2 instead.
This won't work.
3) You are not reopening your second file on the inner do loop.
(Even if you fix item 2) ) After the initial pass the opened file will just stay at the last entry and return true for eof(2) Neither are you closing it.
You need to move your second open statement and the missing close statement inside the first loop.
4) Your last close should be "Close #1"
Code:
Private Sub Command1_Click()
foundcar = False '<-- Where is this defined?
fn = FreeFile() '<-- Same here.
Open "N:\my pictures/cars.txt" For Input As #1
Open "N:\my pictures/customers.txt" For Input As #fn '<-- Move to PosA
Do While Not EOF(1) And Not foundcar
Input #1, registration, cartype, company, typecode, lsdate
'PosA <---
Do While Not EOF(2)
Input #2, custname, address, town, postcode, telephone
If txtcustomercarreg = registration Then
foundcar = True
lbltyretype = "Tyre-type Code: " & typecode
lblcartype = "Car Manufacturer: " & cartype
lblcompname = "Customer Name: " & company
lblregs = "for registration " & registration
lblls = "LastService date: " & lsdate
End If
Loop
'Missing Close #2 here.
If company = custname Then
lbladdress = "Address: " & address & ", " & town
lblpostcode = postcode
lbltelephone = "Telephone: " & telephone
End If
Loop
Close #fn ' <-- This should be close #1
If Not foundcar Then
MsgBox "REGISTRATION NOT FOUND" & Chr$(10) & _
"Please check or add new car to the database", _
vbExclamation + vbOK, "Registration not found"
End If
End Sub
Clean it all up and try again.
~T
|
__________________
Burn the land and boil the sea
You can't take the sky from me
~T
|

04-28-2004, 08:41 AM
|
|
Newcomer
|
|
Join Date: Mar 2004
Posts: 11
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|