Results 1 to 10 of 10

Thread: brackets fail

  1. #1

    Exclamation brackets fail

    Hi,
    do you know why it fails ?

    dim myVar as string = "a word"
    Dim myStr as string
    Dim myStr2 as String
    myStr = "*" & myVar & "*" & $crlf & "*" & $DQ & "a word" & $DQ & "*"
    
    Msgbox (null, myStr)
    msgbox (NULL, ("*" & myVar & "*" & $crlf & "*" & $DQ & "a word" & $DQ & "*")) 'Fail
    
    myStr2 = "*" & myVar & "*" & $crlf & "*" & ($DQ & "a word" & $DQ) & "*" 'Fail
    
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,779
    Rep Power
    10
    Sorry but thinBasic does not allows parentheses in string expressions.
    In string expressions there are no precedences to follow, just left to right evaluation.

    But if you can explain the meaning of a possible usage ... maybe I can consider the idea.

    Ciao
    Eros
    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

  3. #3
    Thanks for your answer,

    this test comes from line 7
    msgbox (NULL, ("*" & myVar & "*" & $crlf & "*" & $DQ & "a word" & $DQ & "*"))
    remark : no bracket in the string, just around.

    Just thought a priori it has no importance; now I understand the logic.



    select case foo
    case (var1 & var2)

    Note: with select case, brackets are not ignored and case is unnoticeably never triggered.
    Last edited by DirectuX; 10-01-2020 at 10:31.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

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

    these are all valid cases of using SELECT CASE:
    int32  fooNumeric = 2
    string fooText = "foo"
    
    
    select case fooNumeric
      case 1, 2 ' Will match when fooNumeric is 1 or 2
        msgbox 0, "1/ Matched for " + SelectExpression
        
      case else ' All other cases
        msgbox 0, "1/ Dunno " + SelectExpression
        
    end select
    
    
    select case fooText
      case "foo" ' Will match "foo"
        msgbox 0, "2/ Matched for " + SelectExpression
        
      case else ' All other cases
        msgbox 0, "2/ Dunno " + SelectExpression
        
    end select
    
    
    select case fooText
      case "fo" & "o" ' Will match "foo", because & is equivalent of + for strings
        msgbox 0, "3/ Matched for " + SelectExpression
        
      case else ' All other cases
        msgbox 0, "3/ Dunno " + SelectExpression
        
    end select
    
    
    select case fooText
      case "foo", "bar" ' Will match both "foo" and "bar"
        msgbox 0, "4/ Matched for " + SelectExpression
        
      case else ' All other cases
        msgbox 0, "4/ Dunno " + SelectExpression
        
    end select
    
    I agree finding ( in case of string expression case should trigger RunTimeError.


    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

  5. #5

    Thumbs up

    Hi Petr,

    that's how i understood it !



    Quote Originally Posted by Petr Schreiber View Post

    I agree finding ( in case of string expression case should trigger RunTimeError.

    Petr
    That's it, though, at first, I was thinking thinBasic would compute what's in the bracket before doing the conditional test. (or basically ignore brackets if precedence is not relevant.) Anyway, Eros already explained his point of view.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  6. #6

    Question

    Quote Originally Posted by ErosOlmi View Post
    Sorry but thinBasic does not allows parentheses in string expressions.
    In string expressions there are no precedences to follow, just left to right evaluation.

    But if you can explain the meaning of a possible usage ... maybe I can consider the idea.

    Ciao
    Eros
    Not a string expression, but maybe related.

    uses "console"
    
    dim x1, x2 as DWord
    
    x1 = 1001
    x2 = 1002
    
    printl (x1) ' OK
    Printl x1 ' OK - Parenthesis are optional.
    
    ' Invalid delimiter - You can use parentheses to override the order of precedence and 
    ' force some parts of an expression to be evaluated before others. Operations within 
    ' parentheses are always performed before those outside.
    
    printl x2 - x1 ' Invalid delimiter
    printl (x2 - x1) ' Missing Close Parens
    
    printl Str$(x2 - x1) ' OK - The text to print ; Type = String
    
    WaitKey
    
    Here my expectation is that expression is evaluated first, then applied on printl.
    Note that the example shows a long being displayed although the syntax specifies a string.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    I must say I would also like to see this improved, thumbs up.

    Especially as PrintL x, where x is numeric variable, works.


    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

  8. #8
    Quote Originally Posted by Petr Schreiber View Post
    I must say I would also like to see this improved, thumbs up.

    Especially as PrintL x, where x is numeric variable, works.


    Petr
    The same issue is happens to msgbox and msgboxw.

    Or/And... we can improve the logger with
    by example a logger.inspect() function ?

    Your thoughts ?
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

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

    sounds interesting, but could you please explain more how is it related to logger? What would inspect do?


    Thanks a lot,
    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

  10. #10
    something like that :

    dim x1, x2 as DWord

    x1 = 1001
    x2 = 1002

    logger.inspect(x1)

    'Output :

    DWORD x1 = 1001

    logger.inspect(x2 - x1)

    'Output :

    x2 - x1 = 1
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

Similar Threads

  1. Replies: 3
    Last Post: 31-03-2009, 23:16

Members who have read this thread: 1

Posting Permissions

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