Author Topic: select case question  (Read 101 times)

0 Members and 1 Guest are viewing this topic.

Offline Brian Alvarez

  • Full Member
  • ***
  • Posts: 133
    • PluriBASIC
select case question
« on: November 13, 2018, 02:09:12 PM »
 I am trying to implement the FORMAT$ function, and i have this code:

Code: [Select]
    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?


« Last Edit: November 13, 2018, 05:23:05 PM by Brian Alvarez »

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 665
    • Charles Pegge
Re: select case question
« Reply #1 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 ]

...

Offline Brian Alvarez

  • Full Member
  • ***
  • Posts: 133
    • PluriBASIC
Re: select case question
« Reply #2 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?

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 665
    • Charles Pegge
Re: select case question
« Reply #3 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 :
« Last Edit: November 13, 2018, 06:48:40 PM by Charles Pegge »

Offline Brian Alvarez

  • Full Member
  • ***
  • Posts: 133
    • PluriBASIC
Re: select case question
« Reply #4 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.
« Last Edit: November 14, 2018, 12:08:52 AM by Brian Alvarez »