Solved

Manipulating Strings

Posted on 2001-06-06
6
187 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 52

Expert Comment

by:Ryan Chong
ID: 6159597
Hi, you can also use the Replace function in VB 6.0
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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
Course of the Month6 days, 4 hours left to enroll

627 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