Author Topic: SELECT stringVar problem  (Read 5758 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
SELECT stringVar problem
« on: May 03, 2013, 07:28:38 AM »
Hi Charles...
I just cach some time and continue to work on my little interpreter in oxygen
and again i see that SELECT stringVar not work.
I use latest oxygen dll.
this code not respond under SELECT statment:
Code: [Select]
print style
SELECT style
    'MinMaxSize -> overlapped window
Case "#MMS"
    print "STYLE is MINMAX"
     wStyle = WS_MINMAXSIZE
    Case "#SYS"
     wStyle = WS_SYSMENU

END SELECT

And when i use IF/ELSEIF/ENDIF then string variable is compared.
Code: [Select]
IF style = "#MMS"
wStyle = WS_MINMAXSIZE
END IF

So like you see something is wrong with SELECT when we select string variable name,right?
Do you can fix this?
I know that with IF works but is very strange that not work with ordinary SELECT..

Aurel
« Last Edit: May 04, 2013, 03:49:31 AM by Aurel »

Charles Pegge

  • Guest
Re: SELECT stringVar problem
« Reply #1 on: May 03, 2013, 07:42:05 AM »
Hi Aurel,

Select does not work with whole strings, only ascii characters, like this:

select asc s
case "A" to "Z" : ...
case "-" : ...
case 1 to 32 : ...
end select

Aurel

  • Guest
Re: SELECT stringVar problem
« Reply #2 on: May 03, 2013, 07:54:38 AM »
And why not work with whole string ?
In most of other basic-s this thing work without any problems.
Do you will add this possibility in some of the next versions ?
« Last Edit: May 04, 2013, 03:50:05 AM by Aurel »

Charles Pegge

  • Guest
Re: SELECT stringVar problem
« Reply #3 on: May 03, 2013, 08:11:49 AM »
I don't really want to change this behaviour. The case block is for making 'atomic' comparisons very fast. It can do so faster than if..elseif..endif, which is more suited to complex comparisons, like strings.

Peter

  • Guest
Re: SELECT stringVar problem
« Reply #4 on: May 03, 2013, 08:16:02 AM »
Yes, I like Select Case how it is.

A good consideration, Charles

Aurel

  • Guest
Re: SELECT stringVar problem
« Reply #5 on: May 03, 2013, 09:26:54 AM »
Ok..
So if i want compare strings i must use if/elseif/endif....
I use this method and it looks that work fast.
Hmmm ..maybe will be good to fill commands array with number which represent
command instead with strings and then use select...

like pseudo code:

LET a = 5

with

10 , a ,= ,5

I will see... ;)

Aurel

  • Guest
Re: SELECT stringVar problem
« Reply #6 on: May 03, 2013, 10:18:37 AM »
Charles ..
is there maybe another method which can fast compare strings ?

JRS

  • Guest
Re: SELECT stringVar problem
« Reply #7 on: May 03, 2013, 10:34:55 AM »
Quote
Yes, I like Select Case how it is.

I'm thankful Peter prefers IF {then} ELSE over CASE as converting his games would have made the port to ScriptBasic more time consuming and I probably wouldn't have bothered.


Charles Pegge

  • Guest
Re: SELECT stringVar problem
« Reply #8 on: May 04, 2013, 12:46:49 AM »
For short lists of strings, instr performs well.

function Lookup(string list,k) as sys
=====================================
sys p,v
lk=len k
do
  p=instr(p+1,list,k)
  if p=0 then exit do
  if p
    if asc(list,p-1)<33 and asc(list,p+lk)=44
      v=asc(list,p+lk+1)-48
      exit do
    end if
  end if
end do
return v
end function

list="
left,1
right,2
top,3
bottom,4
above,5
below,6
"

k="top"

print k "   " Lookup(list,k)



Charles

Aurel

  • Guest
Re: SELECT stringVar problem
« Reply #9 on: May 04, 2013, 03:49:04 AM »
Thanks Charles ...
This is a nice function...
I have one small question about string literal with quotes..
Quote
FUNCTION GetStrLiteral(byval quotedStr as string) as String
String strOut
print quotedStr + LEN(quotedStr)
strOut = Mid(quotedStr,2,LEN(quotedStr)-2)
print "StrOUT:" + strOut
Return strOut
END FUNCTION

As you can see ,if I need return quoted string without quotes i must use LEN(qs)-2
instead LEN(qs)-1
even if LEN return proper string len  ???
Is this normal or something is wrong ?

Charles Pegge

  • Guest
Re: SELECT stringVar problem
« Reply #10 on: May 04, 2013, 07:18:48 PM »
Yes -2 is correct

function NoQuotes(string s) as string
if asc(s)=34
  return mid s,2,len(s)-2
else
  return s
end if
end function

print NoQuotes `"Hello"`


Charles

JRS

  • Guest
Re: SELECT stringVar problem
« Reply #11 on: May 04, 2013, 08:01:32 PM »
Quote
I just don't get it. Can you help me find my hands?


Aurel

  • Guest
Re: SELECT stringVar problem
« Reply #12 on: May 04, 2013, 09:08:54 PM »
Charles..
Is this because null terminated string on the end ?

JRS

  • Guest
Re: SELECT stringVar problem
« Reply #13 on: May 04, 2013, 09:13:01 PM »
No. You -2 for the number of quotes (2) that surround the enclosed string.

Aurel

  • Guest
Re: SELECT stringVar problem
« Reply #14 on: May 04, 2013, 09:24:58 PM »
No ..
Is not...because when i use -1 i get as output string
string"
do you get it now expert

If you don't understand test this expert

Code: [Select]
'literal
FUNCTION GetStrLiteral(byval quotedStr as string) as String
String strOut
print quotedStr + LEN(quotedStr)
strOut = Mid(quotedStr,2,LEN(quotedStr)-1)
print "StrOUT:" + strOut
Return strOut
END FUNCTION

string s,sout
s = chr(34) + "qstring" + chr(34)
sout = GetStrLiteral(s)
« Last Edit: May 04, 2013, 09:31:32 PM by Aurel »