Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Manipulating Strings

Posted on 2001-06-06
6
Medium Priority
?
189 Views
Last Modified: 2010-05-02
I have a string that is rather large (4 printed pages). In it, there are methods that I need to extract. They all start with either "procedure" or "function", followed by a name, and then the body.

What I need to do, is search the entire string for the types (function/procedure) and copy that to a variable, then take the name and copy that to a variable, and then take the body and copy that as well.

There is usually more then one method in this string.

How would be the best way to do this?
Thanks!
0
Comment
Question by:bbaisley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 6159503
You need to use the instr function

set the start parameter to the end of the section you last found, or 1 if you are searching for the first time
0
 
LVL 1

Expert Comment

by:vbWayne
ID: 6159504
split function

an example of the string would help in giving a better answer...even a condensed version
ie.
function myname bla bla
bla bla
bla
procedure myname bla bla
etc...
One would need to see the string.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6159597
Hi, you can also use the Replace function in VB 6.0
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 150 total points
ID: 6159611
dim strTEXT as string
dim strLines() as string

dim strMethodName as string
dim strMethodBody as string

dim lngLoop as Long

'i assume that strText is the variable that holds the whole text...

strLines = split(strText, vbCrLf)
for lngLoop = lbound(strLines) to ubound(strLines)
  select case true
  case strLines(lngLoop) like 'PROCEDURE *', strLines(lngLoop) like 'FUNCTION *'
    'the last procedure/function has ended:
    Debug.Print strMethodName, strMethodBody

    'here begins a new procedure/function
    strMethodName = Mid(strLines(lngLoop), Instr(1,strLines," "))
    strMedthodBody = ""

  case else
    strMethodBody = strMethodBody & strLines(lngLoop) & cvcrlf
  end select

next

'the last procedure/function has ended:
Debug.Print strMethodName, strMethodBody


Now instead of the DEBUG.PRINT, you can do something else with the strMethodName and Body...

Cheers


0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6159714
We need how the procedure finishes..., i.e., with end sub or end procedure or whatever.
Well, you could try with instr function.
1).- Save the contents of complete file to a string variable.
2).- Create a procedure like this:

Option Explicit
Dim vars() As String
Sub SearchText(sTargetStr As String, sStartText2Search As String, sEndText2Search)
Erase vars
Dim i As Long ' just for sure
Dim sStartPos As Long, sEndPos As Long

sStartPos = 1
Do
    sStartPos = InStr(1, sTargetStr, sStartText2Search, vbTextCompare)
'    Debug.Print sTargetStr
    If sStartPos = 0 Then Exit Sub
    sEndPos = InStr(sStartPos, sTargetStr, sEndText2Search, vbTextCompare)
    ReDim Preserve vars(i)
    vars(i) = Mid$(sTargetStr, sStartPos, (sEndPos - sStartPos) + Len(sEndText2Search))
    i = i + 1
    ' compress sTargetStr
    sTargetStr = Mid$(sTargetStr, sEndPos + Len(sEndText2Search))
Loop Until sStartPos = 0


End Sub

Private Sub Form_Click()
Dim i As Long
Dim str As String

Open "D:\Backup\API Examples\get_dsktop_win.frm" For Input As #1
    str = Input(LOF(1), 1)
Close #1
SearchText str, "function", "long"
For i = 0 To UBound(vars)
    Me.Print vars(i)
Next i

End Sub



NOTE: there is not a complete example but i think you could figure out
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6159727
Ups!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question