Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[VB6] Reading Certain Parts of Text Files

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Blader
I post too much
Reputation: 2

Joined: 19 Jan 2007
Posts: 2049

PostPosted: Thu Jan 03, 2008 4:45 pm    Post subject: [VB6] Reading Certain Parts of Text Files Reply with quote

I already know how to read text files and save them, but how would you read a certain part of it and put that somewhere like a list?
If I had a file with this format:
Name-Homepage

Such as
Blader-cheatengine.org
Blader2-cheatengine2.org

How would I read the Blader, write it to a list, then read the cheatengine.org and save it to another list?

How would you save it like that too?

Thanks Razz

_________________
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Thu Jan 03, 2008 5:28 pm    Post subject: Reply with quote

input #1, temp
asd=instr("Blader")
list1.additem asd
asd=instr("www.cheatengine.org")
list2.additem asd
Back to top
View user's profile Send private message
Blader
I post too much
Reputation: 2

Joined: 19 Jan 2007
Posts: 2049

PostPosted: Thu Jan 03, 2008 5:44 pm    Post subject: Reply with quote

That was just an example, I want to read all lines and seperate it like that
I wouldn't know if it was Blader, since people are going to edit the file...

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jan 04, 2008 5:57 am    Post subject: Reply with quote

You can read each line and add it to a list like this:

Code:
Private Sub Command1_Click()
   
    Dim strFilePath     As String
    Dim strLineText     As String
    Dim dwFile          As Long
   
    strFilePath = App.Path & "/stuff.txt"

    dwFile = FreeFile()
    Open strFilePath For Input As #dwFile
        Do While Not EOF(dwFile)
            Input #dwFile, strLineText
            List1.AddItem strLineText
        Loop
    Close #dwFile
   
End Sub


If you want to search the file for a certain name and only add that you can do something like:

Code:
Private Sub Command1_Click()
    LocateName "Name1"
End Sub

Private Function LocateName(strName As String)
   
    Dim strFilePath     As String
    Dim strLineText     As String
    Dim dwFile          As Long
   
    strFilePath = App.Path & "/stuff.txt"

    dwFile = FreeFile()
    Open strFilePath For Input As #dwFile
        Do While Not EOF(dwFile)
            Input #dwFile, strLineText
            If Split(strLineText, "-")(0) = strName Then
                List1.AddItem strLineText
            End If
        Loop
    Close #dwFile
   
End Function


My test file "stuff.txt" was this:

Code:
Name0-www.site.com/0
Name1-www.site.com/1
Name2-www.site.com/2
Name3-www.site.com/3
Name4-www.site.com/4
Name5-www.site.com/5
Name6-www.site.com/6
Name7-www.site.com/7
Name8-www.site.com/8
Name9-www.site.com/9p


The line of code:
Code:
If Split(strLineText, "-")(0) = strName Then


Will split the read line at the first instance of - and only keep the text before it. Mind you this will not be a secure method if a user uses the hyphen in their name. It will cause the function to mess up. I suggest looking for a better method to do this, such as storing your data in a different method instead of a flat text file. Perhaps XML. You can do this a lot more secure in XML.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Trow
Grandmaster Cheater
Reputation: 2

Joined: 17 Aug 2006
Posts: 957

PostPosted: Fri Jan 04, 2008 6:46 am    Post subject: Reply with quote

how do you go about using XML in VB6? MSXML wrapper?
_________________
Get kidnapped often.
Back to top
View user's profile Send private message
Blader
I post too much
Reputation: 2

Joined: 19 Jan 2007
Posts: 2049

PostPosted: Fri Jan 04, 2008 9:42 am    Post subject: Reply with quote

@Wiccaan - Where would the split go?
I tried this:
Code:
    Dim strFilePath     As String
    Dim strLineText     As String
    Dim dwFile          As Long
    Dim strName         As String
   
    strFilePath = App.Path & "\Test.txt"

    dwFile = FreeFile()
    Open strFilePath For Input As #dwFile
        Do While Not EOF(dwFile)
            Input #dwFile, strLineText
            If Split(strLineText, "-")(0) = strName Then
                List1.AddItem strName
            End If
        Loop
    Close #dwFile


But it doesn't work.
Also, how would I split both?
I need to have the name on one list, and the website on another one

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jan 04, 2008 6:33 pm    Post subject: Reply with quote

blland wrote:
how do you go about using XML in VB6? MSXML wrapper?


The UFH engine I wrote uses XML parsing for the "plugins" which you can find the source of here:

http://home.comcast.net/~wiccaan/UFH/UFH_1_0_61.rar


@Blader: The code I posted should work, I tested it before posting it and it worked fine for me. As for getting the website also, just use something like this:

Code:
If Split(strLineText, "-")(0) = strName Then
   List1.AddItem Split(strLineText, "-")(0) '// Adds Name To List 1
   List2.AddItem Split(strLineText, "-")(1) '// Adds Site To List 2
End If

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Blader
I post too much
Reputation: 2

Joined: 19 Jan 2007
Posts: 2049

PostPosted: Fri Jan 04, 2008 7:36 pm    Post subject: Reply with quote

For yours, you said it only works when you want to look for something specific, I'm not, I'm just adding all of them. The first one doesn't have a split, so that's why I don't know what to do to make it work (Not good at parsing stuff)
_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jan 04, 2008 10:32 pm    Post subject: Reply with quote

Blader wrote:
For yours, you said it only works when you want to look for something specific, I'm not, I'm just adding all of them. The first one doesn't have a split, so that's why I don't know what to do to make it work (Not good at parsing stuff)


Possibly a case issue? Try this in the if-then instead:

Code:
If LCase(Split(strLineText, "-")(0)) = LCase(strName) Then


Again, I don't suggest you use this method to store data, I highly suggest moving into XML or another form of data storage that can prevent parsing issues such as what you are having now. Having a set base skeleton via XML keeps things easy to manage and parse. For example:

Code:
<Entry>
    <Name>Site Name</Name>
    <Site>Site URL</Site>
</Entry>


This way you could have any character you want in the name and such and as long as the XML parser is written well and correctly, it should work fine. VB comes with an XML parser extension (msxml6.dll) which works great for this. See the above link to the UFH engine I wrote which makes use of XML files. It should push you in the right direction on using them instead of a normal text file.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Blader
I post too much
Reputation: 2

Joined: 19 Jan 2007
Posts: 2049

PostPosted: Sat Jan 05, 2008 10:05 am    Post subject: Reply with quote

Hmm, I might consider changing into XML parsing...
But, will users be able to edit it?
I might go into .ini instead, is that a little easier than text files, or is it pretty much the same

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Jan 05, 2008 1:00 pm    Post subject: Reply with quote

Blader wrote:
Hmm, I might consider changing into XML parsing...
But, will users be able to edit it?
I might go into .ini instead, is that a little easier than text files, or is it pretty much the same


A user can edit any file you give them. No matter the format. Ini files could be another method. Theres plenty of different file types you could use, I just suggest XML as it's more of a standard to holding information now-adays.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites