Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Text Files


Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2003, 03:14 PM
spiro spiro is offline
Regular
 
Join Date: Jan 2003
Posts: 68
Question Text Files


Why hello

another question from me. Ive written a program which allows a user to create a profile (with username and passwords stored in a txt file). now i wanted to be able to read both files and if the user name and password are on the same line, it is available to login...
if you don't understand i can try and explain more
Reply With Quote
  #2  
Old 03-30-2003, 04:35 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

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

Why didn't you try and explain more instead of 'anybody?...please?'

Have you tried writing the code yet?
All you need to do is open both files and read each line one by one.
__________________

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 03-30-2003, 05:14 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
Default

Lookup the following functions. They could possibly help .

Open, Print, Output, Split, Input, Append
(the last two are for saving...)

~MikeJ
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #4  
Old 03-30-2003, 06:19 PM
excaliber's Avatar
excaliber excaliber is offline
Senior Contributor

* Expert *
 
Join Date: Nov 2002
Location: Ohio, USA
Posts: 1,828
Default

__________________
RandomIRC - Your neighborhood's friendly IRC channel (irc.randomirc.com - #code)

"Perl - The only language that looks the same before and after RSA encryption."
Reply With Quote
  #5  
Old 03-30-2003, 07:57 PM
spiro spiro is offline
Regular
 
Join Date: Jan 2003
Posts: 68
Default

thankx excaliber i've already used that tutorial and but i need one for reading files...so far my code consists of...


Open App.Path & "\UserName.txt" For InputAs #1

very good eh ya

well im going to go search for some answers if anyone can help please let me know
Reply With Quote
  #6  
Old 03-30-2003, 08:13 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
Default

Code:
Dim tempstring() As String Open App.Path & "\UserName.txt" For Input As #1 Do While Not EOF(1) Print #1, tempstring Loop Close #1

Now, tempstring() has all of your data. You can populate a listbox, textboxes, or whatever you want now.

~MikeJ
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #7  
Old 03-30-2003, 08:17 PM
wengwashere's Avatar
wengwashere wengwashere is offline
Contributor
 
Join Date: Apr 2002
Location: brgy Ginebra
Posts: 449
Default

ey dude,

im used to using file system objects, in this case filesystemobject.textstream...try using that...well, you could read and write from and to a text file

'-- Before you do that, you need to reference MS scripting runtime

'--------------- write to a file --------------------
Dim objFSO As Scripting.FileSystemObject, objWriteFile As Scripting.TextStream

'-- Initialize FSO --
Set objFSO = New Scripting.FileSystemObject

strFileName = "YourFileName.txt"

'-- Create New Text File --
Set objWriteFile = objFSO.CreateTextFile(strFileName, True)

'-- Insert Message to File --
objWriteFile.WriteLine "Your data here"

objWriteFile.Close

'-- Clean Up objects
Set objWriteFile = Nothing
Set objFSO = Nothing
'-----------------------------------------------

'--------------- read a file --------------------
Dim objFSO As Scripting.FileSystemObject, objReadFile As Scripting.TextStream

'-- Initialize FSO --
Set objFSO = New Scripting.FileSystemObject

strFileName = "YourFileName.txt"

'-- Open File --
Set objReadFile = objFSO.OpenTextFile(strFileName, ForReading)

'-- Read All Data --
str = objReadFile.ReadAll

'-- Read Per Line --
do while not objReadFIle.AtEndOfStream
str = objreadfile.readline
Loop

objReadFile.Close

'-- Clean Up objects
Set objReadFile = Nothing
Set objFSO = Nothing

'-----------------------------------------------
Reply With Quote
  #8  
Old 03-30-2003, 08:21 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
Default

Also, instead of two seperate files, why don't you have one with a delimiter and use the Split$() function?
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #9  
Old 04-01-2003, 03:26 PM
spiro spiro is offline
Regular
 
Join Date: Jan 2003
Posts: 68
Default

well i'm a very basic learner and well ya i got all that too work but ofcourse it has braughten me to anew problem

i am now consulting you guys on how to search a textfile...i want to seach it for the username(txtUserName.text)

thankx to everyone for their help and i also ask if anyone knows any books i could look up for some VB tutorials?
Reply With Quote
  #10  
Old 04-01-2003, 04:02 PM
starbitz's Avatar
starbitz starbitz is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Philippines
Posts: 336
Default

i am now consulting you guys on how to search a textfile...i want to seach it for the username(txtUserName.text)


How do you open/read your textfile? I suggest that read your textfile line by line and put it in an array. After reading the whole textfile and saving each line in an array, you can now loop on the array elements and search on it if it has an element equal to you txtUserName.text
Reply With Quote
  #11  
Old 04-01-2003, 07:37 PM
spiro spiro is offline
Regular
 
Join Date: Jan 2003
Posts: 68
Default

well right now all i've gotten to is opening the file...i haven't gotten farther then that so if you know a tutorial...
Reply With Quote
  #12  
Old 04-01-2003, 08:30 PM
starbitz's Avatar
starbitz starbitz is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Philippines
Posts: 336
Default

Quote:
Originally Posted by spiro
well right now all i've gotten to is opening the file...i haven't gotten farther then that so if you know a tutorial...



You can have codes like these...

Dim TempLine as string
Dim aString() as string
Dim i as integer
Dim foundMatch as boolean

foundMatch = false
Redim aString(0)
i = 0

Open sFilename For Input As #1
While Not EOF(1)
Line Input #1, sTestline
TempLine = Trim(sTestline)
Redim Preserve aString(Ubound(aString)+1)
aString(i) = Split(TempLine, ,1) 'I assume your text file has the Username as first entry. Get the first entry of the line and save to aString array
i = i +1
Wend
Close #1

'Search match for txtUserName.text on the elements of your array which holds the UserName data of your textfile
for i = Lbound(aString) to Ubound(aString)
if txtUserName.text = aString(i) then
foundMatch = true
exit for
endif
next i
Reply With Quote
  #13  
Old 04-02-2003, 05:13 AM
spiro spiro is offline
Regular
 
Join Date: Jan 2003
Posts: 68
Default

thank you i'll be sure to try that
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
Reading Text Files and Progress Bar Ashon General 13 05-05-2004 10:55 AM
output of 2 text files stored in list boxes Keeper General 14 11-11-2002 07:24 PM
Text files and Inner Workings GGKauten General 6 10-11-2002 03:46 AM
Wraping text around an image? Serevinus Web Programming 7 06-20-2002 01:46 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
 
 
-->