Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to chose just a respective string from a file

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
(e.g)

Private Sub (XXXXXXXXXXXX)
code
code
code
code
code
End sub

I want only the headline (Private Sub (XXXXXXXXX))
 
Open "C:\file.bob" for Input as #1
Line Input #1, FirstLineStr
Close #1
 
Open "C:\file.txt" for Input as #1
Line Input #1, FirstLineStr
Close #1


 
The problem is if there are many functions in one module...
i need to get all the declaration functions that there are inside of one module!
(e.g.

Private sub test1(xxx) <------ This one
code
code
end sub

Public Sub test2 (xxx) <------ And this one
code
code
End Sub
 

Tiagão, is sound like you've misunderstood something (or I just don't understand what you mean).
You don't HAVE to have something in the parenthesis after the sub declaretion (only if you want to transfer a local variable)

e.g.
-----------------------------------------------------

Private sub SubOne
dim msg as string
msg=&quot;Hello!&quot;
SubTwo(msg)
end sub

private sub SubTwo(MyMessage as string)
msgbox(Mymessage)
end sub

-------------------------------------------------------

Sunaj
 
Open &quot;file.bas&quot; For Input As #1
Do While Not EOF(1)
Line Input #1, LineStr
if len(instr(linestr, &quot;Private&quot;)) > 0 then
Headingstr = headingstr & &quot;,&quot; & linestr
elseif len(instr(linestr, &quot;Public&quot;)) > 0 then
headingstr = Headingstr & &quot;,&quot; & linestr
end if
Loop
Close InFile
 
That isn't a problem... was just a eg!
What i need is to get the line of the declarations... both of them!
The declaration are in a cls file and i need to open it a save the declarations to a txt file!
Tkx sunaj, and if you know this point, please help me!
 
I'm assuming that this is just an additional requiremnt of your ongoing .cls project. And as a result you've already been given a method for reading in a file line by line by sunaj as follows (my preference when dealing with text files is to use the FileSystemObject, but let's not confuse the issue):

[tt]dim infile as byte, inline as string
infile=freefile
Open &quot;c:\myfile.cls&quot; for ijput as #infile
while not eof(infile)
line input #infile, inline
wend
close infile[/tt]

You can then modify this as follows:

[tt]dim infile as byte, inline as string
infile=freefile
Open &quot;c:\myfile.cls&quot; for ijput as #infile
while not eof(infile)
line input #infile, inline
if instr(inline, &quot;Private Sub&quot;) or instr(inline, &quot;Public Sub&quot;) then
'if we get here then inline contains required header
' you could add a check for Private Function and Public Function as well
end if
wend
close infile[/tt]
 
99mel,
i think you misunderstood what i need!
i need to get the line and save only that line to a file.
If you do a &quot;if&quot; you doesn't choose anything, i think i need to do a &quot;case&quot;. Because if you say:

if len(instr(linestr, &quot;Private&quot;)) > 0 then
Headingstr = headingstr & &quot;,&quot; & linestr
elseif len(instr(linestr, &quot;Public&quot;)) > 0 then
headingstr = Headingstr & &quot;,&quot; & linestr
end if

you choosing between private or public and this isn't correct.
i need to check the line and if it is &quot;private...&quot; save to txt file, if it's &quot;public...&quot; save it to the same txt file and if it isn't any of this give a msgbox!
;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top