Donate Now Goal amount for this month: 100 USD, Received: 200 USD (200%)
Donate to support this site and ThinBASIC project development

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
    47
    Posts
    7,584
    Blog Entries
    2
    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/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,429
    Rep Power
    653

    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 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Clearwater, Florida, USA
    Posts
    3,802
    Rep Power
    388

    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!

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,584
    Blog Entries
    2
    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/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

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

Bookmarks

Posting Permissions

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