Text Box Parsing

mr_e_landis

Registered User.
Local time
Today, 12:06
Joined
Feb 16, 2005
Messages
28
I'm having trouble parsing a text box correctly/at all. I just sent my PC into a while loop that resulted in a killing of the access.exe so I need some help.
I have a text box containing the following text.
X:\Data\file1.txt
X:\Data\file2.txt
X:\Data\file3.txt
X:\Data\file4.txt​
I need to look at this text box and as a whole value "VAR1" and parse through and return a value "VAR2" for each line until the end of the string. For example if I wanted to click a button and have a Msgbox pop up and tell me individually what each line in the text box was how would I do that? I can't seam to figure out the proper combination of while loops, and left, right, or mid statements... If anyone is a parsing expert or know of a good example somewhere its much appreciated.
 
That description is awfully confusing. You want to loop through each string until you find the end of it? Do you really have

X:\Data\file1.txt
X:\Data\file2.txt
X:\Data\file3.txt
X:\Data\file4.txt

in one textbox? Or is that a combobox? If you have a list of filenames like that all in one textbox, are all the filenames ending in ".txt"? If so, the loop is:

Code:
Dim mover1 As Integer
Dim mover2 as Integer
Dim filename As String

mover1 = 1
mover2 = 1
While mover2 <> 0
    mover2 = InStr(mover1,[txtString],".txt") + 3
    filename = mid([txtString],mover1, mover2-mover1)
    MsgBox filename
    mover1 = mover2 + 1
Wend

Edit:
Corrected the code a little. Sorry about the little screw-up there.

HTH
~Moniker
 
Last edited:
Sorry if I was unclear. As I said before it's a text box and it does contain the text shown as a string so if you were to run this code
Code:
msgbox me.mytextbox
it would return exactly as shown above.
The problem with your solution I'm trying to pick apart and understand is that I can have a variety of extensions ".txt, .x_t, .sldprt, .model, .catia, .prt, etc." Would I be able to use the code you provided and tweak it so that it would find the first line feed and then return that line?

My apologies for coming off a bit dense I've really never done parsing before.
 
Last edited:
It sounds like you have a carriage return at the end of each filename. You would have to to get output like:

File1.txt
File2.xls
File3.x_t

You can find each linebreak like this:

Instr(1,[txtString],chr(13))

---OR---

Instr(1,[txtString],vbCrLf)

Using me fake file list above, both of these would return a 10. That is the position of the first carriage return since "File1.txt" contains nine characters, and the tenth character is the carriage return.

If that's still not right, post a small DB example and I'll get it parsing correctly.

~Moniker
 
Thanks that helped... I think I have it figured out.
This code works... I just think it could be a little bit cleaner...
Code:
    Dim MyString, MyLine As String
    Dim Point1, Point2 As Integer
    Dim StrLen1, StrLen2
    
    MyString = [Me.MyTextBox]
    Point1 = 1
    Point2 = 1
    While Point2 <> 0
        Point2 = InStr(Point1, MyString, Chr(13))
        MyLine = Left(MyString, Point2)
        If Point2 = 0 Then MyLine = MyString
        StrLen1 = Len(MyString)
        StrLen2 = Len(MyLine)
        MsgBox MyLine
        On Error Resume Next
        MyString = Right(MyString, (StrLen1 - StrLen2) - 1)
    Wend
 
Code:
Dim strArray() As String
Dim j
strArray = Split([Me.MyTextBox], Chr(13))
For j = 0 To UBound(strArray)
    msgbox strArray(j)
Next j

should work A2K and above

Peter
 
Ah, the split function. I should've pointed that out. Good catch Bat... :)

~Moniker
 

Users who are viewing this thread

Back
Top Bottom