Solved

Manipulating Strings

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 70
VBA filters 2 81
Excel Web Add-in Where is Visual Basic used 9 85
Create a list of Worksheets based on Cell Value 14 33
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

710 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