Results 1 to 5 of 5

Thread: [RESOLVED] help to chang my code....please

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Resolved [RESOLVED] help to chang my code....please

    I have this code to search a text file and get some information which are between two plus signs and it need some changes to get the exact information that I need

    VB Code:
    1. If UCase(Left(tmp(x + 1), 12)) = "     (GLOSS)" Then
    2.                 gloss = Split(tmp(x + 1), "+")
    3.                 sLine = sLine & " (" & Trim(gloss(1)) & ");"   ' here we add () for the traslation
    4.   Else
    5.                 sLine = sLine & Left(Words(1), InStr(Words(1), ")") - 1) & ";"
    6.  End If

    If this was a part of the text file

    (GLOSS): with/by + the + cooperation +
    .
    .

    (GLOSS): + with +
    .
    .
    (GLOSS): the + collective + [fem.sg.]
    .
    .
    (GLOSS): you [masc.sg.] + be taken/be adopted +


    What I need is to get is the info between the last two + signs
    It means I need the word red color
    Cooperation
    with
    collective
    be taken/be adopted

    and this code gives me the first words between + signs which is wrong n the first line
    the
    with
    collective
    be taken/be adopted
    Last edited by om-yousif; Oct 12th, 2006 at 03:56 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: help to chang my code....please

    maybe this will work for you
    VB Code:
    1. sLine = sLine & " (" & Trim(gloss(UBound(gloss) - 1)) & ");"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Hyperactive Member BrendanDavis's Avatar
    Join Date
    Oct 2006
    Location
    Florida
    Posts
    492

    Re: help to chang my code....please

    If all you need is the info from between the last two plus signs, make it search for it in reverse(if that is the end if the text you are searching, I mean) using InStrRev. But what you could do Kind of like this:

    VB Code:
    1. Dim theText as String
    2.  
    3. theText = iString 'Set the string to whatever you plan to search
    4.  
    5. If InStrB(LCase$(theText), "gloss:") then 'Check to make sure it is there
    6.     line1Case1 = Mid$(theText, 10, InStr(theText, "+")) 'Gets the first item in the first line
    7.     theText = Mid$(theText, Len(Line1Case1) + 1)
    8.     line1Case2 = Mid$(theText, 1, InStr(theText, "+")) 'Gets the second item in the first line
    9.  
    10.     'Repeat for the rest of the items
    11.  
    12. End If

    Something like that would work. However, if all you need is to get the items between the last two plus signs, it would be much more simple to use something like InStrRev.

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: help to chang my code....please

    You did this; gloss = Split(tmp(x + 1), "+")
    So check If Ubound(gloss) >=2, this indicates a line with more than two +
    If there are more than two +, then simply access element gloss(Ubound(gloss) - 1)). This element is the one nested between last two plus signs.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: help to chang my code....please

    i tried whAt westconn1 wrote

    it was what i'm looking for
    thanks everyone for your help

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