Small Text Parser for VB6

007bond
Me again. I'm looking for a very very basic Text Parser for VB6, which basically looks through a file for a certain character. I guess you couldn't really call it a parser, but anyway, it's close enough. Any help or ideas?

Anonymous

Me again. I'm looking for a very very basic Text Parser for VB6, which basically looks through a file for a certain character. I guess you couldn't really call it a parser, but anyway, it's close enough. Any help or ideas?



Explain what you are trying to do in more detail? If you are just looking to find a single occurrence - remove a sucession of LF chars or whatever?

This sort of thing is dead easy - once you specify what you want to actually do!

Al <MaDbRiT)

007bond
OK: I'm trying to write my own Cataloguing (sp?) program in VB6, especially for books (so you have all the usual fields: ISBN, Author, Illustrator, eg). What I need is some small code that will look through a text file (file format not important here) a special character, or a series of characters, like &*% for example. So you could call it a small text parser.

Alf
VB6 has very good string parsing built in. It should be easy enough to:

Hardcode a string to look for, then do something with it

Allow the user (or you) to enter a string to look for, then do something with it

Or just about any other string search/manipulation you would normally want to do with VB6.

Hope this helps.

Alf

007bond
It probably does, but if I'd known how to do that then I wouldn't have asked. Can you please tell me how to do it?

paul_one
here's a simple puesedo code thing below, use various other places to turn it into code (shouldn't be that hard considering it's just a "search and use" technique).

function text (file as string, search as string)

dim a, b, c, f as integer
dim d, e as string (and yes, you can use the ,'s in real VB coding to do this!)

c = freefile
a = 0

open file for input as #c

do while (EOF(#c) <> True)
a = a + 1
(this bit isn't going to be exactly coded)
input line (#c, d) (something like "line input" puts a line from channel #c into variable d)
f = instr (d, search) (or something like that - look for string manipulation in the object browser or whatever returns where the string is)
e = mid$ (d, f, len(search)) (seperates search from d)
or you can probably add words/change/whatever.
loop

close #c

return "line ="; a; "... text ="; d;"..."

end function

as I said, very rough...

Or you could load it all into a richtext box, find it (so it selects the word) and then change it that way....

007bond
thanks. Do I have to convert that into normal VB Code, or will puesuedo code work just fine anyway?

paul_one
puesedo code isn't real code... It's just a simple way for programmers to write down code in a way they will understand better.

It's kind of a middle ground. You need to turn that into VB code, which isn't hard as it's just a find and fill-in-the-gaps process.

Alf
You can probably use CW's sample pretty much like it is. Now, to get more specific on how to use it will depend upon what *exactly* you want to do with it.

Do you want to replace a substring within a string with another substring?

Do you want to replace the entire string with a string?

Do you want to return the location of a substring within a string?

Do you want to merely test for the existence of a substring?

As you can see, there are a LOT of different things you can do. But, all string manipulation follows this same general idea.

You can either experiment with some of these based upon CW's sample. Or, if you'd like to give a specific goal, maybe we can help.

Alf

007bond
Yes, I'm gonna need all 4 things that you said there, and probably more.
Turns out I'm gonna have to be using similar code for another program that I'm writing currently. It's called MPlayer, and you can get it by searching Winsite for MPlayer. It stands for Media Player, but it only plays music right now. Anyway, more to the point, I need code that will scan a file for a certain file path, then load text out of the line(s) below it (basically it's for the ID3 tags, but I'm not using them, I'm just using a whole series of .dat files)

This topic is now closed. Topics are closed after 14 days of inactivity.

Support

Forums