Page 1 of 1

How to print the FindString result? (Sytax error)

Posted: Sun Dec 27, 2015 4:14 pm
by zer0c0de

Code: Select all

If OpenFile(0,dir$+"/1.html")
  Repeat 
    r$ = ReadString(0)
    res = FindString(r$,"Tel: ")
    Print(res) ; This is the syntax error, how to fix it?
  Until Eof(0)
__________________________________________________
Code tags added
28.12.2015
RSBasic

Re: How to print the FindString result? (Sytax error)

Posted: Sun Dec 27, 2015 4:34 pm
by IdeasVacuum

Code: Select all

If OpenFile(0,dir$+"/1.html")
Repeat
r$ = ReadString(0)
res = FindString(r$,"Tel: ")
PrintN(Str(res)) ; Print and PrintN want a string, res is a number
Until Eof(0)

Re: How to print the FindString result? (Sytax error)

Posted: Sun Dec 27, 2015 5:34 pm
by TI-994A
zer0c0de wrote:Print(res) ; This is the syntax error, how to fix it?
There are many output options, depending on your requirements. Here are some of them:

* these examples work on the following text file (PhoneNumbers.txt):

Code: Select all

Albert Einstein, Tel: 5551234
Isaac Newton, Tel: 5552345 
Charles Darwin, Tel: 5554567
Guglielmo Marconi, Tel: 5555678
Galileo Galilei, Tel: 5556789
Leonardo da Vinci, Tel: 5557890 
René Descartes, Tel: 5558901 
Thomas Edison, Tel: 5559012
Output to the debug window:

Code: Select all

If OpenFile(0, "PhoneNumbers.txt")
  Repeat
    r$ = ReadString(0)
    res = FindString(r$, "Tel:")
    Debug Mid(r$, res + 5, 7)
  Until Eof(0)
  CloseFile(0)
EndIf
Output to the console window:

Code: Select all

If OpenFile(0, "PhoneNumbers.txt")
  If OpenConsole("Phone Numbers")
    Repeat
      r$ = ReadString(0)
      res = FindString(r$, "Tel:")
      PrintN(Mid(r$, res + 5, 7))
    Until Eof(0)
    CloseFile(0)
    Input()
  EndIf
EndIf
Output to a program window:

Code: Select all

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 
OpenWindow(0, #PB_Any, #PB_Any, 200, 300, "Phone Numbers", wFlags)
ButtonGadget(0, 10, 10, 180, 30, "READ FILE")
ListViewGadget(1, 10, 50, 180, 240)
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          If OpenFile(0, "PhoneNumbers.txt")
            Repeat
              r$ = ReadString(0)
              res = FindString(r$, "Tel:")
              AddGadgetItem(1, -1, Mid(r$, res + 5, 7))
            Until Eof(0)
            CloseFile(0)
          EndIf
      EndSelect
  EndSelect
Until appQuit = 1
Just some suggestions. :D