Problems doing a count from a file
Problems doing a count from a file
Problems doing a count from a file
Problems doing a count from a file
Problems doing a count from a file
Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file
Problems doing a count from a file Problems doing a count from a file
Problems doing a count from a file
Go Back  Xtreme Visual Basic Talk > > > Problems doing a count from a file


Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2004, 09:02 AM
NeilB NeilB is offline
Freshman
 
Join Date: Nov 2003
Location: England
Posts: 35
Default Problems doing a count from a file


I am trying to do a search inside a .dat that will look for a certain name that has been entred, and see how many times it has been entred. At the moment I am getting just a 0 in the count variable.

Code:
'============================================================= '== Sub: btnsearch_seat_Click(...) '== Descript: Searches to see how many seats a customer has '== Dim CustomerName As String Dim inputstream As StreamReader Dim dayName As String Dim line As String Dim words(3) As String Dim oneChar As Char Dim count As Integer = 0 'Inputbox for the day name CustomerName = InputBox("Please enter Customers name", "Please enter Customers name") dayName = InputBox("Enter day name (Monday, Tuesday, etc)") 'Loads file FileOpen(1, dayName & ".dat", OpenMode.Input) While Not EOF(1) words = Split(line, ",") oneChar = (InputString(1, 1)) If Trim(words(0)) = CustomerName Then count = Val(count + 1) End If End While MessageBox.Show("The person has" & count & "seats") FileClose(1) End Sub
Reply With Quote
  #2  
Old 01-16-2004, 01:47 PM
Iceplug's Avatar
IceplugProblems doing a count from a file Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You don't seem to be putting anything into the Line variable.

Also, why aren't you using the System.IO?
inputstream = New System.IO.StreamReader(dayname & ".dat")

Line = inputstream.ReadLine()
words = Line.Split(","c)
If words(0).Trim() = CustomerName Then

__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 01-17-2004, 03:02 AM
NeilB NeilB is offline
Freshman
 
Join Date: Nov 2003
Location: England
Posts: 35
Default

Do I have to get rid of -
Code:
While Not EOF(1)
?

I put this in to make sure it read the whole file before stopping the loop.

Coding now
Code:
'Creates the directory for the file name inputstream = New System.IO.StreamReader(dayName & ".dat") While Not EOF(1) line = inputstream.ReadLine() words = line.Split(","c) If words(0).Trim() = CustomerName Then count = Val(count + 1) Else line = inputstream.ReadLine() End If End While MessageBox.Show(count & "not found") FileClose(1)
Reply With Quote
  #4  
Old 01-17-2004, 06:09 AM
reboot's Avatar
rebootProblems doing a count from a file reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

Code:
Dim inputstream As StreamReader Dim linein As String 'open the textfile inputstream = File.OpenText(dayName & ".dat") 'read the first line linein = inputstream.ReadLine() 'loop through the file While Not linein Is Nothing 'whatever it is you're doing with linein words = linein.Split(","c) If words(0).Trim() = CustomerName Then count += 1 End If 'read another line linein = inputstream.ReadLine() End While MessageBox.Show(count.ToString & " not found") 'close the reader inputstream.Close()
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
File I/O GavinO Tutors' Corner 5 04-17-2013 01:18 PM
Installation Problem - PLs help urgenlty dpdsouza Installation / Documentation 4 12-02-2004 07:09 PM
File Problems: Files Not Closing etc. Templeton Peck General 5 03-29-2003 11:34 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
Problems doing a count from a file
Problems doing a count from a file
Problems doing a count from a file Problems doing a count from a file
Problems doing a count from a file
Problems doing a count from a file
Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file Problems doing a count from a file
Problems doing a count from a file
Problems doing a count from a file
 
Problems doing a count from a file
Problems doing a count from a file
 
-->