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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I parse a variable in VBA

Status
Not open for further replies.

FrankFrankel

Technical User
Nov 6, 2010
5
CA
Hi

I have a big bunch of text that I need to parse for product codes. There are multiple codes in the text and I want to save them in a table. I've managed to get the text into a variable, and successfully find the first product code. I don't know how to loop through the rest of the text variable until the end.

I was considering FreeFile, but since I managed to insert the text into a variable already I decided to skip it. Can someone shed some light on a possible solution?

Here is the section I want to loop

----------------LOOP UNTIL END OF VARIABLE---------
'parse for END OF PRODUCT CODE
endcode = InStr(1, Productfile, Search)

'LOOP UNTIL START OF PRODUCT CODE
A = 1
Do Until startcode = "/"
startcode = Mid(Productfile, (endcode - A), 1)
A = A + 1
Loop
'FIND THE PRODUCT CODE USING START AND END VARIABLES
PRODUCTCODE(ARR) = Mid(Productfile, (endcode - (A - 2)), (A - 4))

'SAVE THE PRODUCTCODE IN THE ARRAY
ARR = ARR + 1
ReDim Preserve PRODUCTCODE(ARR)
----------------LOOP UNTIL END OF VARIABLE---------
 
Can you provide a few sample of "big bunch of text", what the products are that should be extracted, and where these will eventually end up (table or other)?

Duane
Hook'D on Access
MS Access MVP
 
Duane,

After I wrote the post I figured something out that worked.
 



Frank,

It is both customary and courteous to share your solution, in order for other Tek-Tip members to benefit from your newly discovered knowledge.


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top