PDA

View Full Version : brackets fail



DirectuX
09-01-2020, 18:46
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

ErosOlmi
09-01-2020, 21:53
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

DirectuX
09-01-2020, 22:49
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.:suicide:

Petr Schreiber
11-01-2020, 20:57
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

DirectuX
11-01-2020, 21:22
Hi Petr,

that's how i understood it !






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.

DirectuX
06-05-2020, 21:49
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 (https://www.thinbasic.com/public/products/thinBasic/help/html/console_writeline.htm) shows a long being displayed although the syntax specifies a string.

Petr Schreiber
15-05-2020, 07:22
I must say I would also like to see this improved, thumbs up.

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


Petr

DirectuX
15-05-2020, 09:06
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 ?

Petr Schreiber
16-05-2020, 10:36
DirectuX,

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


Thanks a lot,
Petr

DirectuX
16-05-2020, 15:44
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