Click to See Complete Forum and Search --> : Reading all Dim's from a text box and putting them in a list box


February 24th, 2000, 05:58 PM
I'm working on a MDI project (the MDINote notepad sample which comes with MSVB6). When i open up a form i want it to load all the Dim's and const's that are in the textbox of the current form (frmMDI.ActiveForm.Text1.Text) into a listbox.

At the moment i'm using the following code:

private Sub Form_Load()

Dim txt as string
Dim tag_open as Integer
Dim tag_close as Integer
txt = frmMDI.ActiveForm.Text1.Text
tag_close = 1

Do
tag_open = InStr(tag_close, txt, "Dim ")
If tag_open = 0 then Exit Sub

tag_close = InStr(tag_open, txt, vbCrLf)
If tag_open = 0 then tag_close = len(txt)

frmMDI.ActiveForm.Text1.SelStart = tag_open + 3
frmMDI.ActiveForm.Text1.SelLength = tag_close - tag_open - 3
List1.AddItem frmMDI.ActiveForm.Text1.SelText

Loop

tag_close = 1
tag_open = 0

Do

tag_open = InStr(tag_close, txt, "Const")
If tag_open = 0 then Exit Sub

tag_close = InStr(tag_open, txt, vbCrLf)
If tag_open = 0 then tag_close = len(txt)

frmMDI.ActiveForm.Text1.SelStart = tag_open + 4
frmMDI.ActiveForm.Text1.SelLength = tag_close - tag_open - 4
List1.AddItem frmMDI.ActiveForm.Text1.SelText

Loop

End Sub




1.The above code lists the Dim's properly, but does not list any consts.. Why??
2.The code only lists what is in between 'Dim ' and vbcrlf. That's what i want. But what do I do if there is a sentence like 'Dim myVar As Whatever' . It will also include ' As Whatever'. How do I avoid that?

Pleeeeeaaaaaseeeee help! I need this BADLY !

Nick A.
February 25th, 2000, 02:29 AM
The problem might be in the first Do..Loop

>> If tag_open = 0 then Exit Sub

Try

If tag_open = 0 then Exit Do