Results 1 to 4 of 4

Thread: Simple script inside Eval strings

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Simple script inside Eval strings

    Maybe not all of you know about the possibility of Eval module to evaluate little scripts more complex than a math or string expressions.
    Here a little dummy script just to give you an idea.

    The script check if a string variable has a "0" inside it. If yes reports it and parse 3rd token.
     uses "EVAL"
     uses "CONSOLE"
     
     '---Some timing variable
     dim t0, t1 as double = timer
     
     '---This string containing the script to be executed
     dim MyString as string = "
           '---DIM AUTO will automatically dimension new variables when found
           dim AUTO
           '---No need to DIM the variable if DIM AUTO is in place
           '---If variable ends with a $ it is string, otherwise numeric (EXT)
           Info_GotIt$ = "" <--- Got it.""
    
           '---Add a "GOT IT" message every time "0" is found inside the main string
           IF instr(InternalScriptStringVariable, ""0"") then
            InternalScriptStringVariable = InternalScriptStringVariable & Info_GotIt$
            InternalScriptStringVariable = InternalScriptStringVariable & "" Number is: "" & parse$(InternalScriptStringVariable, chr$(32), 3)
           END IF
           "
     '---Used to get back results from Eval
     dim sResult as string
    
     '---Define a looper and its max
     dim Count   as long
     dim MaxCount as long value 500
    
     for Count = 1 to MaxCount
    
      '---Set InternalScriptStringVariable variable and value
      Eval_SetString("InternalScriptStringVariable", "Looper is " & Count)
    
      '---Eval_String will evaluate MyString and will return result
      Eval(MyString)
    
      '---Get back the value of the internal variable after script has modified it.
      sResult = Eval_GetString("InternalScriptStringVariable")
    
      '---Write some info output
      printl format$(Count, "0000") & " - Eval_String returned: " & sResult
    
     next 
    
     '---Measure the ending time
     t1 = timer
    
     '---Final results  
     printl "------------------------------------------------------"
     printl "Total execution time for " & MaxCount & " loops: " & format$(t1-t0, "#0.00000")
    
     '---Stop execution
     waitkey
    
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Simple script inside Eval strings

    And you say this "by the way"

    That is pretty cool!
    I presume "little script" is defined as script using just CORE keywords and no functions?


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Simple script inside Eval strings

    Thanks for the demo Eros. There are lots of gems like this that are unknown I know to me. Posts like this and articles in the new journal will hope to bring these to light!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Simple script inside Eval strings

    I presume "little script" is defined as script using just CORE keywords and no functions?
    Not exacly but very close.
    EVAL is an interpreter inside the main thinBasic interpreter but supported functionalities in EVAL are not the same as in Core in the sense that even if keywords in EVAL use the same syntax as the Core, it is not the same engine.

    EVAL supports very few set of keywords but anyhow quite sufficient to write little scripts.
    I will update EVAL help file. I need time >
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Execution of script with space inside name
    By ErosOlmi in forum thinAir General
    Replies: 1
    Last Post: 26-10-2005, 13:17

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •