Special retrieval of a string from file <part 2>

Hello Tim and all others!
Thanks for the code but there is a slight problem:
- I am trying to read a "user_id" from a certain cookie text file
- I try to read a new line using your code - but it reads the whole file content into the string! (although if I open the cookie with Word - I see that there are new lines, so there must be new line characters in the cookie file, no?)
- As a result: I crash when trying to execute the command: Input #1, strLine2
(according to your code -see above)
- If I can find out how to advance the file pointer, that would help as well.
- To sum up: I need to skip the newline character(that I saw with Word) which appears after the string "user_id" that I am looking for and then skip a newline character, then read a string (representing the numeric id) which ends in the next newline character(this, again, I saw with Word)
- Please tell me what to do - 10'x
P.S. I miss C/C++ - this would have been over a long time ago...
although VB has its features...
itailevitanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

damienmCommented:
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("c:\folderName\fileName.txt")
Set ts = f.OpenAsTextStream(1, TristateUseDefault)
While Not ts.atendofstream
    stemptext = ts.readline

    msgbox stemptext

wend


This should read 1 line at a time.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
damienmCommented:
Dim StempText as String
0
mcriderCommented:
When you read cookie files, there is no VbCrLf separating the end of lines.  Cookies only use VbLf at the end of each line.

To read a cookie file, you need to read the whole file, then use instr() to find each line...

For example:

    Dim fNum As Long
    Dim Cookie As String
    Dim CookieLine As String
    Dim iVal As Long
    Dim jVal As Long
     
    fNum = FreeFile
    Open "C:\windows\cookies\mcrider@experts-exchange[1].txt" _
        For Input Access Read As fNum
    Input #fNum, Cookie
    Close fNum
    jVal = 0
    Do
        jVal = jVal + 1
        iVal = InStr(1, Cookie, vbLf)
        If iVal = 0 Then Exit Do
        CookieLine = Left$(Cookie, iVal - 1)
        Cookie = Mid$(Cookie, iVal + 1)
        Debug.Print "Line #" + CStr(jVal) + ": " + CookieLine
    Loop


Cheers!
0
itailevitanAuthor Commented:
Thanks a lot Damien - you helped a lot!
I did something a bit different but it's you that made it happen!
itailevitan@hotmail.com
(24 yr old computer science student from Israel learning VB)
0
MoondancerCommented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed.  Also a question is posted there specific to these changes that apply to the experts here.  Also, I am including the link to our All Topics, since many new ones have recently been added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.