Results 1 to 10 of 10

Thread: find line #3 in each paragraph

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    find line #3 in each paragraph

    if i have a notpad file and want to search it from thired line in each paragraph

    and check if first word is 'SOLUTION' then extract some words and go to the next 'SOLUTION' and do the same thing

    if first word is 'COMMENT' then take the whole line



    (actually it's not a paragraph they are some groups of unrelated lines separated by empty line )

    can anyone help..... PLEASE

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: find line #3 in each paragraph

    VB Code:
    1. Private Sub GetData()
    2.     Dim tmp() As String
    3.    
    4.     Open "C:\path\to\filename.txt" For Input As #1
    5.         tmp = Split(Input(LOF(1), 1), vbCrLf)
    6.     Close #1
    7.    
    8.     For x = 0 To UBound(tmp)
    9.         If Left(tmp(x), 8) = "SOLUTION" Then
    10.             'Get words...from tmp(x)
    11.         ElseIf Left(tmp(x), 7) = "COMMENT" Then
    12.             'tmp(x) is the whole line
    13.             WholeLine = tmp(x)
    14.         End If
    15.     Next
    16.  
    17. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: find line #3 in each paragraph

    Thank you STATIC
    i will try it and replay
    thanks again

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: find line #3 in each paragraph

    it works thaks alot





    but i have a problem with copying the word i need from each line
    how can i these word

    i wrote a code to extract them and put them in a list using normal search for a text box not string

    how can i get them in case of strings?

    VB Code:
    1. Option Explicit
    2. Private Target2Position As Integer
    3. Private TargetPosition As Integer
    4.  
    5.  
    6. ' Find the text.
    7. Private Sub cmdFind_Click()
    8.     FindText 1
    9. End Sub
    10. Private Sub FindText(ByVal start_at As Integer)
    11. Dim target As String
    12. Dim pos As Integer
    13.  
    14. Dim target2 As String
    15. Dim pos2 As Integer
    16.  
    17.     target = "SOLUTION"
    18.     target2 = ")"
    19.    
    20.     pos = InStr(start_at, txtBody.Text, target)
    21.      
    22.     If pos > 0 Then
    23.         'We found it.
    24.         start_at = pos + 12
    25.        
    26.        pos2 = InStr(start_at, txtBody.Text, target2)
    27.        Target2Position = pos2
    28.        
    29.        
    30.         TargetPosition = pos
    31.         txtBody.SelStart = TargetPosition + 12
    32.         txtBody.SelLength = Target2Position - TargetPosition - 13
    33.         txtBody.SetFocus
    34.        
    35.     Else
    36.         'We did not find it.
    37.         MsgBox "Not found."
    38.         txtBody.SetFocus
    39.     End If
    40.         Text1.Text = txtBody.SelText
    41.         List1.AddItem (Text1.Text)
    42.    
    43.     cmdFind.Enabled = False
    44.     End Sub
    45.  
    46. ' Find the next occurrance of the text.
    47. Private Sub cmdFindNext_Click()
    48.     FindText Target2Position + 1
    49.    
    50.    
    51. End Sub





    sample of text
    INPUT STRING: البحرين
    LOOK-UP WORD: AlbHryn
    SOLUTION 1: (AlbaHorayoni) [baHorayoni_1] Al/DET+baHorayoni/NOUN_PROP
    (GLOSS): the + Bahrain +
    SOLUTION 2: (AlbaHorayoni) [baHor_1] Al/DET+baHor/NOUN+ayoni/NSUFF_MASC_DU_ACCGEN
    (GLOSS): the + sea + two

    INPUT STRING: هايسث
    LOOK-UP WORD: hAysv
    Comment: hAysv NOT FOUND

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: find line #3 in each paragraph

    in your sample text.. what are u trying to get in the solution lines...?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: find line #3 in each paragraph

    sorry for being late there was a problem with my unternet connection
    anyway



    this is the original text
    Hello ( هايسث شمس البحرين تنكسف



    1.for the first word(هايسث ) this should be extracted----
    hAysv NOT FOUND

    2.شمس words are---
    $amasa
    $amisa
    $am~asa
    $amos

    3.البحرين
    AlbaHorayoni
    AlbaHorayoni

    4. تنكسف
    tanokasif
    tanokasif


    8. Hello:
    Non-Alphabetic Data


    9. ( :
    Non-Alphabetic Data




    these words should be shown in a popup menu for each word in the original text


    there is lots of details that i should include in the popup menu but i want to finish this part first
    Last edited by om-yousif; Jul 28th, 2006 at 03:45 AM.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: find line #3 in each paragraph

    COLOR=Blue]sample of text that should be processed

    INPUT STRING: هايسث
    LOOK-UP WORD: hAysv
    Comment: hAysv NOT FOUND

    INPUT STRING: شمس
    LOOK-UP WORD: $ms
    SOLUTION 1: ($amasa) [$amas-u_1] $amas/VERB_PERFECT+a/PVSUFF_SUBJ:3MS
    (GLOSS): + be headstrong + he/it <verb>
    SOLUTION 2: ($amisa) [$amis-a_1] $amis/VERB_PERFECT+a/PVSUFF_SUBJ:3MS
    (GLOSS): + be sunny + he/it <verb>
    SOLUTION 3: ($am~asa) [$am~as_1] $am~as/VERB_PERFECT+a/PVSUFF_SUBJ:3MS
    (GLOSS): + expose to the sun + he/it <verb>
    SOLUTION 4: ($amos) [$amos_1] $amos/NOUN
    (GLOSS): + sun +
    SOLUTION 5: ($amos) [$amos_2] $amos/NOUN_PROP
    (GLOSS): + Shams +

    INPUT STRING: البحرين
    LOOK-UP WORD: AlbHryn
    SOLUTION 1: (AlbaHorayoni) [baHorayoni_1] Al/DET+baHorayoni/NOUN_PROP
    (GLOSS): the + Bahrain +
    SOLUTION 2: (AlbaHorayoni) [baHor_1] Al/DET+baHor/NOUN+ayoni/NSUFF_MASC_DU_ACCGEN
    (GLOSS): the + sea + two

    INPUT STRING: تنكسف
    LOOK-UP WORD: tnksf
    SOLUTION 1: (tanokasif) [{inokasaf_1] ta/IV3FS+nokasif/VERB_IMPERFECT
    (GLOSS): it/they/she + be eclipsed/be ashamed/blush +
    SOLUTION 2: (tanokasif) [{inokasaf_1] ta/IV2MS+nokasif/VERB_IMPERFECT
    (GLOSS): you [masc.sg.] + be eclipsed/be ashamed/blush +


    INPUT STRING: Hello
    Comment: Non-Alphabetic Data

    INPUT STRING: (
    Comment: Non-Alphabetic Data
    Last edited by om-yousif; Jul 28th, 2006 at 03:42 AM.

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

    Re: find line #3 in each paragraph

    using the code posted by static, this will return the value you are looking for
    VB Code:
    1. If Left(tmp(x), 8) = "SOLUTION" Then
    2.             MsgBox Mid(tmp(x), InStr(1, tmp(x), "(") + 1, InStr(1, tmp(x), ")") - InStr(1, tmp(x), "(") - 1)
    3.            
    4.         ElseIf Left(tmp(x), 7) = "COMMENT" Then

    pete

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: find line #3 in each paragraph

    you want to display these in a popup menu???

    what would you be clicking on to trigger this?? (Im confused as to how u want to display these)

    the sample below would add them to a listbox

    VB Code:
    1. Private Sub GetData()
    2.     Dim tmp() As String
    3.     Dim Words() As String
    4.     Open "C:\path\to\filename.txt" For Input As #1
    5.         tmp = Split(Input(LOF(1), 1), vbCrLf)
    6.     Close #1
    7.    
    8.     For x = 0 To UBound(tmp)
    9.         If Left(tmp(x), 8) = "SOLUTION" Then
    10.             Words = Split(tmp(x), "(")
    11.             List1.AddItem Left(Words(0), InStr(Words(0), ")"))
    12.         ElseIf Left(tmp(x), 7) = "COMMENT" Then
    13.             Words = Split(tmp(x), ":")
    14.             List1.AddItem Words(1)
    15.         ElseIf Left(tmp(x), 5) = "INPUT" Then
    16.             Words = Split(tmp(x), ":")
    17.             List1.AddItem Words(1)
    18.         End If
    19.     Next
    20.  
    21. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: find line #3 in each paragraph

    Yes WESTCONN!
    STATIC
    thats it

    i combined the two scripts and got what i want thanks


    now how can i put them in a popup menu not all in on popup
    but for each word different popup menu contains its solutions in case of arabic word
    - a popup with (NOT FOUND) in case of arabic word with no meaning
    - a popup with (Non-Alphabetic Data)or(not arabic word) in case of english words

    etc.


    as shown in the text file
    Last edited by om-yousif; Jul 28th, 2006 at 03:12 PM.

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