Jose's Read Only Forum 2023

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Brian Alvarez on November 13, 2018, 02:09:12 PM

Title: select case question
Post by: Brian Alvarez on November 13, 2018, 02:09:12 PM
 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?


Title: Re: select case question
Post by: Charles Pegge on November 13, 2018, 05:12:25 PM
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 ]

...
Title: Re: select case question
Post by: Brian Alvarez on November 13, 2018, 05:22:27 PM
 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?
Title: Re: select case question
Post by: Charles Pegge on November 13, 2018, 06:45:28 PM
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 :
Title: Re: select case question
Post by: Brian Alvarez on November 13, 2018, 10:26:35 PM
 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.