 |
 |

03-30-2003, 03:14 PM
|
|
Regular
|
|
Join Date: Jan 2003
Posts: 68
|
|
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
|
|

03-30-2003, 04:35 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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.
|
|

03-30-2003, 05:14 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
Lookup the following functions. They could possibly help  .
Open, Print, Output, Split, Input, Append
(the last two are for saving...)
~MikeJ
|
|

03-30-2003, 06:19 PM
|
 |
Senior Contributor
* Expert *
|
|
Join Date: Nov 2002
Location: Ohio, USA
Posts: 1,828
|
|
__________________
RandomIRC - Your neighborhood's friendly IRC channel (irc.randomirc.com - #code)
"Perl - The only language that looks the same before and after RSA encryption."
|

03-30-2003, 07:57 PM
|
|
Regular
|
|
Join Date: Jan 2003
Posts: 68
|
|
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
|
|

03-30-2003, 08:13 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
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
|
|

03-30-2003, 08:17 PM
|
 |
Contributor
|
|
Join Date: Apr 2002
Location: brgy Ginebra
Posts: 449
|
|
|
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
'-----------------------------------------------
|
|

03-30-2003, 08:21 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
|
Also, instead of two seperate files, why don't you have one with a delimiter and use the Split$() function?
|
|

04-01-2003, 03:26 PM
|
|
Regular
|
|
Join Date: Jan 2003
Posts: 68
|
|
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?
|
|

04-01-2003, 04:02 PM
|
 |
Junior Contributor
|
|
Join Date: Feb 2003
Location: Philippines
Posts: 336
|
|
|
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
|
|

04-01-2003, 07:37 PM
|
|
Regular
|
|
Join Date: Jan 2003
Posts: 68
|
|
|
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...
|
|

04-01-2003, 08:30 PM
|
 |
Junior Contributor
|
|
Join Date: Feb 2003
Location: Philippines
Posts: 336
|
|
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
|
|

04-02-2003, 05:13 AM
|
|
Regular
|
|
Join Date: Jan 2003
Posts: 68
|
|
thank you i'll be sure to try that 
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear 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
|
|
|
|
|
|
|
|
 |
|