Copy word to NotePade

vb6 Bahrain
  • 14 years ago

    Hi...
    I have this code to do search for a word that are between 2 bracket and this text (word) in a notepade file.
    then i want to take only the word to save (copy) in another notepade file
    (the word in the last statement)....




                        pos1 = InStr(1, line, "(")
                        pos2 = InStr(1, line, ")")
                            If pos1 > 0 And pos2 > 0 Then
                                word = Mid(line, pos1 + 1, pos2 - pos1 - 1)



    Please, How can i do that?
    Thanks

  • 14 years ago
    Your code can be simplified into 1 line:

    strWord = Mid(strLine, InStr(1, strLine, "(") + 1, (Val(InStr(strLine, ")")) - Val(InStr(strLine, "(") + 1)))

    To copy this word to another file - firstly, open the source file loop through it until you find brackets, read the word between the brackets and output the word to another file:

    Option Explicit

    Dim strLine As String
    Dim strWord As String

    Private Sub Form_Load()
    Open "C:\source.txt" For Input As #1
    While Not EOF(1)
       Line Input #1, strLine
       If ((InStr(1, strLine, "(")) And (InStr(1, strLine, ")"))) Then
          strWord = Mid(strLine, InStr(1, strLine, "(") + 1, (Val(InStr(strLine, ")")) - Val(InStr(strLine, "(") + 1)))
       End If
       strLine = ""
    Wend
    Close #1
    Open "C:\destination.txt" For Output As #1
    Print #1, strWord
    Close #1
    End Sub























  • 14 years ago

    Hi Rob..

    Thanks about the code, that code is work and print the word but only 1 word (GLOSS) and in my notePade i have many word between bracket and i want to choose some of them and print it in new notepade for Example: (in my notepade i have this text)

    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>






    And i want to print the word between bracket after all the word SOLUTION and the word (GLOSS) i do not want to print it..

    please, can You help me to do that work? 

    Thanks a lot

    Regards 

    Bodoora                                                                                                                                                                              

  • 14 years ago

    Bodoora,

    I'm really sorry, you will have to explain the problem in more detail, I don't fully understand what it is you want to print out!!

    The code I gave you should loop through the file and print out every occurence of a word in brackets if you put all of the words into an array.

    If what you want is not to print out the word GLOSS then just do an If .. Then statement to check for the word:

    Option Explicit

    Dim strLine As String

    'Array to hold all the words
    Dim strWord() As String

    Private Sub Form_Load()
    ReDim strWord(1)
    Dim a As Integer

    'A counter to record UBound of strWord Array
    a = 0
    Open "C:\source.txt" For Input As #1

    'Loop through File
    While Not EOF(1)
       Line Input #1, strLine
       If ((InStr(1, strLine, "(")) And (InStr(1, strLine, ")"))) Then
               
               'Make strWord array bigger and store word in last position of array 
               ReDim Preserve strWord(UBound(strWord) + 1)
               strWord(a) = Mid(strLine, InStr(1, strLine, "(") + 1, (Val(InStr(strLine, ")")) - Val(InStr(strLine, "(") + 1)))

                'Increament counter
                a = a + 1
       End If
       strLine = ""
    Wend
    Close #1
    Open "C:\destination.txt" For Output As #1
    'Loop through array
    For a = 0 To UBound(strWord)
       
       'If word at position a is not GLOSS then print out the word
       If Trim(UCase(strWord(a))) <> "GLOSS" Then Print #1, strWord(a)
    Next
    Close #1
    End Sub













































  • 14 years ago

    Hi Rob...

    Thanks very very much about the code..

    And that what i want to do...

    Smiley Face [:)]

    Regards

    Bodoora

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”