Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does SubStr() exist in VBA?

Status
Not open for further replies.

robinsdale

Programmer
Jun 5, 2001
31
0
0
AU
Hi all,
Another mild moment of frustration - perhaps you can help. I'm writing a UDF that extracts data from a text file. The text file data is always in the same format, right down to how many spaces within specific data it lies.
Suchly:


LName: Flintstone, Fred


In VFP, I would open the file using FOpen() - VBA provides a similar function - Open(). I would then step through the file line by line, and process each line based on the data string. One very powerful tool seems to be lacking, something analgous to SUBSTR(), for which the syntax is:


SUBSTR (
string_to_extract_from, start_point, end_point )

An example of that function is:


cLine = "LName: Flintstone, Fred"
cLine = SUBSTR ( cLine, 8 ,10 )

* ...yields 'Flintstone'

Know of anything like it for VBA? Anything been cobbled that would work similarly? I've been fiddling with Left() and Right() and InStr() but can't find anything like the FoxPro AT() or RAT() functions, either, to recreate a SUBSTR() type function.

Thanks in advance...

Regards,
Robin
 
Thanks, Justin, for your quick reply. That was it! Works!
Regards,
Robin
 
Hi Robin,
If I've understood your need, you can use mid() that does exactly what you want.

 
Hi Bonina,
You understood the need correctly - figured out that Mid() actually does the job very, very similarly to the FoxPro function SubStr(). Thanks so much for responding...
Regards,
Robin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top