Loading ...
Sorry, an error occurred while loading the content.

Re: Text Box

Expand Messages
  • green8819
    open text.txt for input as #w txt$ = input$(#w, lof(#w)) close #w prompt Enter text to search for: ; srch$ srch$=lower$(srch$) :sLen=len(srch$)
    Message 1 of 5 , Jan 14, 2013
    • 0 Attachment
      open "text.txt" for input as #w
      txt$ = input$(#w, lof(#w))
      close #w

      prompt "Enter text to search for:"; srch$
      srch$=lower$(srch$) :sLen=len(srch$)
      txt$=lower$(txt$)

      'startPos=from where to start search
      'foundPos=where found
      while startPos < len(txt$)
      foundPos = instr(txt$, srch$, startPos)
      if foundPos then 'if found
      count=count+1
      startPos=foundPos+(sLen+1)
      else
      startPos=startPos+1 'next character position
      end if
      wend

      print count; " found"
      wait
      END


      --- In libertybasic@yahoogroups.com, "henriknilson" wrote:
      >
      > Hi
      > The following code is working OK, but I would like to remove the "textbox #w.tbx1, 10, 10, 250, 100", so the search will be directly within the text file.
      > Indeed, with using text file, tbx1 became useless, and the prompt is enough.
      > You may use any "text.txt" file within the same folder of the code to run it.
      > The origin code was written by Mike, but without separated text file.
      >
      > Any help please
      > Thank you
      >
      > 'The code
      >
      > 'nomainwin
      >
      > open "text.txt" for input as #w
      > txt$ = input$(#w, lof(#w))
      > close #w
      > print txt$
      >
      > textbox #w.tbx1, 10, 10, 250, 100
      > button #w.srch,"Search",[srch], UL, 10, 150
      > button #w.srch,"Continue Search",[contSrch], UL, 100, 150
      >
      > open "Text" for window as #w
      > #w "trapclose [quit]"
      > #w.tbx1, txt$
      >
      > [srch]
      > prompt "Enter text to search for:"; srch$ :sLen=len(srch$)
      > #w.tbx1 "!contents? content$"
      > [contSrch]
      > StartPos = instr(lower$(content$), lower$(srch$), fPos)
      > if StartPos = 0 then [quit]
      > #w.tbx1 "!setfocus"
      > dummy=SendMessage(hwnd(#w.tbx1),_EM_SETSEL,StartPos-1,StartPos+sLen-1)
      > fPos=StartPos+sLen
      >
      > counter=counter+1
      > print counter
      >
      > goto [contSrch]
      > wait
      >
      > [quit]
      > close #w
      > END
      > '----------------------------------------------------------
      > function SendMessage(handle, message, wParam, lParam)
      > calldll #user32, "SendMessageA", handle as ulong, _
      > message as ulong, wParam as ulong, lParam as ulong, SendMessage as ulong
      > end function
      >
    • Henrik
      Thank you Rod  I couldn t modify the code by your snippet, because when using it give’s, BASIC Compile Halted END IF without IF.  
      Message 2 of 5 , Jan 14, 2013
      • 0 Attachment
        Thank you Rod
         I couldn't modify the
        code by your snippet, because when using it give’s, BASIC Compile Halted END IF
        without IF.
         


        ________________________________
        From: Rod <rodbird@...>
        To: libertybasic@yahoogroups.com
        Sent: Sunday, January 13, 2013 2:04 PM
        Subject: [libertybasic] Re: Text Box


         
        This is as simple as it can get.

        open "text.txt" for input as #w
        txt$ = input$(#w, lof(#w))
        close #w
        prompt "Enter text to search for:"; srch$
        if instr(txt$,srch$) then
        notice "Text found"
        else
        notice "Text not found"
        end if
        end




        [Non-text portions of this message have been removed]
      • Henrik
        Thank you so much Mike it works OK. ________________________________ From: green8819 To: libertybasic@yahoogroups.com Sent: Monday,
        Message 3 of 5 , Jan 14, 2013
        • 0 Attachment
          Thank you so much Mike it works OK.


          ________________________________
          From: green8819 <mike4612@...>
          To: libertybasic@yahoogroups.com
          Sent: Monday, January 14, 2013 11:16 AM
          Subject: [libertybasic] Re: Text Box


           
          open "text.txt" for input as #w
          txt$ = input$(#w, lof(#w))
          close #w

          prompt "Enter text to search for:"; srch$
          srch$=lower$(srch$) :sLen=len(srch$)
          txt$=lower$(txt$)

          'startPos=from where to start search
          'foundPos=where found
          while startPos < len(txt$)
          foundPos = instr(txt$, srch$, startPos)
          if foundPos then 'if found
          count=count+1
          startPos=foundPos+(sLen+1)
          else
          startPos=startPos+1 'next character position
          end if
          wend

          print count; " found"
          wait
          END

          --- In libertybasic@yahoogroups.com, "henriknilson" wrote:
          >
          > Hi
          > The following code is working OK, but I would like to remove the "textbox #w.tbx1, 10, 10, 250, 100", so the search will be directly within the text file.
          > Indeed, with using text file, tbx1 became useless, and the prompt is enough.
          > You may use any "text.txt" file within the same folder of the code to run it.
          > The origin code was written by Mike, but without separated text file.
          >
          > Any help please
          > Thank you
          >
          > 'The code
          >
          > 'nomainwin
          >
          > open "text.txt" for input as #w
          > txt$ = input$(#w, lof(#w))
          > close #w
          > print txt$
          >
          > textbox #w.tbx1, 10, 10, 250, 100
          > button #w.srch,"Search",[srch], UL, 10, 150
          > button #w.srch,"Continue Search",[contSrch], UL, 100, 150
          >
          > open "Text" for window as #w
          > #w "trapclose [quit]"
          > #w.tbx1, txt$
          >
          > [srch]
          > prompt "Enter text to search for:"; srch$ :sLen=len(srch$)
          > #w.tbx1 "!contents? content$"
          > [contSrch]
          > StartPos = instr(lower$(content$), lower$(srch$), fPos)
          > if StartPos = 0 then [quit]
          > #w.tbx1 "!setfocus"
          > dummy=SendMessage(hwnd(#w.tbx1),_EM_SETSEL,StartPos-1,StartPos+sLen-1)
          > fPos=StartPos+sLen
          >
          > counter=counter+1
          > print counter
          >
          > goto [contSrch]
          > wait
          >
          > [quit]
          > close #w
          > END
          > '----------------------------------------------------------
          > function SendMessage(handle, message, wParam, lParam)
          > calldll #user32, "SendMessageA", handle as ulong, _
          > message as ulong, wParam as ulong, lParam as ulong, SendMessage as ulong
          > end function
          >




          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.