Results 1 to 11 of 11

Thread: A function to get the specific part of a text

  1. #1

    Thread Starter
    Addicted Member kill_bill_gates's Avatar
    Join Date
    Oct 2004
    Posts
    222

    Post 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:
    1. 'In a module type the following:
    2.  
    3. Function Between(Begining As String, Ending As String, TextToLookIn As String)
    4. Dim Be As String, En As String, TTLI As String
    5. Be = Begining
    6. En = Ending
    7. TTLI = TextToLookIn
    8. TTLI = Right(TTLI, Len(TTLI) - (InStr(1, TTLI, Be) + Len(Be) - 1))
    9. TTLI = Left(TTLI, InStr(1, TTLI, En) - 1)
    10. Between = TTLI
    11. End Function

    Hope it will be useful. If u think its not useful plz pm me.
    Last edited by kill_bill_gates; Dec 21st, 2004 at 02:39 PM.
    "Quis custodiet ipsos custodes?"
    Juvenal
    Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
    I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
    -=Joey Jordison R0CKS!! =-

  2. #2
    New Member
    Join Date
    Dec 2004
    Posts
    9

    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!!!!!
    aRCHITEKTON of Programming Thought and LITERATURe

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

  5. #5

    Thread Starter
    Addicted Member kill_bill_gates's Avatar
    Join Date
    Oct 2004
    Posts
    222

    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....
    "Quis custodiet ipsos custodes?"
    Juvenal
    Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
    I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
    -=Joey Jordison R0CKS!! =-

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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

  7. #7

    Thread Starter
    Addicted Member kill_bill_gates's Avatar
    Join Date
    Oct 2004
    Posts
    222

    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.
    "Quis custodiet ipsos custodes?"
    Juvenal
    Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
    I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
    -=Joey Jordison R0CKS!! =-

  8. #8
    Junior Member Cipher's Avatar
    Join Date
    Dec 2004
    Location
    In your closet!
    Posts
    23

    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?
    "It is a hard thing to fall, it is even harder to admit to that fall."

    -Darth Treya

    Star Wars: Knights of the Old Republic II

  9. #9

    Thread Starter
    Addicted Member kill_bill_gates's Avatar
    Join Date
    Oct 2004
    Posts
    222

    Re: A function to get the specific part of a text

    Hey, I've made it better(i guess);
    VB Code:
    1. Function Between(TextToLookIn As String, Begining As String, Ending As String)
    2. 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))
    3. End Function
    "Quis custodiet ipsos custodes?"
    Juvenal
    Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
    I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
    -=Joey Jordison R0CKS!! =-

  10. #10
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    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...

  11. #11
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width