How to print the FindString result? (Sytax error)

Just starting out? Need help? Post your questions and find answers here.
zer0c0de
New User
New User
Posts: 6
Joined: Sun Oct 04, 2015 8:51 am

How to print the FindString result? (Sytax error)

Post 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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

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

Post 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
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply