• Welcome to Jose's Read Only Forum 2023.
 

select case question

Started by Brian Alvarez, November 13, 2018, 02:09:12 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

 I am trying to implement the FORMAT$ function, and i have this code:

    for i = 1 to len(f)
      select case mid(f, i, 1)
          case ","
              commas  = 1
         
          case "."
              decimal = 1

          case "0"
              if decimal = 0 then
                  lzeroes += 1             
              else
                  tzeroes += 1
              end if
      end select
      print ">>>" & mid(f, i, 1) & "-" & str(decimal)
     
    next


But one of the message boxes displays: ">>>.-0"

This can only mean that either the "." is not being detected, or that i have no idea how select case works on Oxygen.
A little help?



Charles Pegge

Use asc instead:

select asc(f,i)

or better still:

byte bb at strptr(f)-1
for i = 1 to len(f)
select bb[ i ]

...

Brian Alvarez

 Ok, But if i am going to emulate it, i need to know why the other method doesnt work.
Not only that, i need to know how to make it work.

Can you show me an example of it with strings?

Charles Pegge

#3
Case blocks only work on numbers. They are very primitive, but as efficient as pure Assembler, more so than using 'if' statatements.

BTW:

case "0" :

is converted to:

case 48 :

Brian Alvarez

#4
 No problem, i will convert oxygen's SELECT CASE blocks to IF statements. Its a simple switch in pluribasic. :)
So, no need to edit them in your code, they will work as normal today.


Edit:
Done, oxygen now supports select case blocks with strings in PluriBASIC.
Numeric blocks will still have the SELECT CASE syntax, but string ones are now IF blocks.