A function to get the specific part of a text
I hope it will be useful to someone somehow(i found it practical). It gets the specific part in a text between the begining and the ending strings;
VB Code:
'In a module type the following:
Function Between(Begining As String, Ending As String, TextToLookIn As String)
Dim Be As String, En As String, TTLI As String
Be = Begining
En = Ending
TTLI = TextToLookIn
TTLI = Right(TTLI, Len(TTLI) - (InStr(1, TTLI, Be) + Len(Be) - 1))
TTLI = Left(TTLI, InStr(1, TTLI, En) - 1)
Between = TTLI
End Function
Hope it will be useful. If u think its not useful plz pm me. :afrog:
Re: A function to get the specific part of a text
Be = Begining
En = Ending
TTLI = TextToLookIn
you could use the parameter vars directly
makes your routine more tight!!!!!
Re: A function to get the specific part of a text
If you used Option Explicit you wouldn't have any spelling mistakes. Also when you define things like this
Dim Be, En, TTLI As String
only TTLI gets defines as a string. The others default to Variants which are slower and larger than any other variables.
Re: A function to get the specific part of a text
The GLOBAL variable has to go away.
The function should return a string variable.
Having a GLOBAL variable breaks the black-box rules - doesn't fit ACID concept.
No reason to move BEGINING and END into other variables - that is a huge waste of time.
Also, find the start and end position of the string with INSTR and do the math to store those positions - in longword variables.
Cut the string up only once.
Moving and cutting the string three times would not be acceptable in our shop.
We develop programs that process sometimes thousand and thousands of records from a database - being tight and clean is important in the long run.
Re: A function to get the specific part of a text
And this code is to use in a "module "... If u dont use GLOBAL the thing wont work in the rest of the program....
Re: A function to get the specific part of a text
Why must you use a GLOBAL variable instead of having the FUNCTION return the string?
Standard function practice would be:
Code:
Function Between(Begining As String, Ending As String, TextToLookIn As String) As String
.
.
.
Between=TTLI
End Function
Re: A function to get the specific part of a text
ok, thats good but the program i was working on when i wrote this had to be like that... But the one u said is better for general purposes.
Re: A function to get the specific part of a text
Ok i am making a money tree grabber. Refer to this post for more info:http://www.vbforums.com/showthread.p...62#post1879362
If I want to grab the ID of items in a page source...how would i do that?
Re: A function to get the specific part of a text
Hey, I've made it better(i guess);
VB Code:
Function Between(TextToLookIn As String, Begining As String, Ending As String)
Between = Left(Right(TextToLookIn, Len(TextToLookIn) - InStr(1, TextToLookIn, Begining) - Len(Begining) + 1), InStr(1, Right(TextToLookIn, Len(TextToLookIn) - InStr(1, TextToLookIn, Begining) - Len(Begining)), Ending))
End Function
Re: A function to get the specific part of a text
The functions I posted in this thread are just as usefull, the function LeftRange does the same thing as what yours does...
VB - Some functions that makes string parsing easier
You have to copy and paste the code into a module...
Re: A function to get the specific part of a text
kill_bill_gates, if you want to kill Bill Gates whytf do you use his software?