Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Ive made a mess of dislpaying informtaion from 2 files simultaneously


Reply
 
Thread Tools Display Modes
  #1  
Old 04-23-2004, 04:02 AM
zoec zoec is offline
Newcomer
 
Join Date: Mar 2004
Posts: 11
Default 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
Reply With Quote
  #2  
Old 04-23-2004, 01:51 PM
Gruff's Avatar
Gruff Gruff is offline
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,882
Default

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
Reply With Quote
  #3  
Old 04-23-2004, 02:09 PM
Gruff's Avatar
Gruff Gruff is offline
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,882
Default

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
Reply With Quote
  #4  
Old 04-28-2004, 08:41 AM
zoec zoec is offline
Newcomer
 
Join Date: Mar 2004
Posts: 11
Default

thank you!!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The next step ... imbedding files Juanita General 5 06-26-2002 04:39 PM
Required files burningodzilla General 11 09-12-2001 04:51 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->