Test if literal value is numeric or text

Just starting out? Need help? Post your questions and find answers here.
firace
Addict
Addict
Posts: 903
Joined: Wed Nov 09, 2011 8:58 am

Test if literal value is numeric or text

Post by firace »

I'm trying to make my own custom debug routine, to be used in compiled programs.
However I'm stuck at an early stage, trying to determine the type of the argument.

The builtin Debug statement accepts both strings and numeric values, and both variables and literals.
I'm trying to replicate that, but I'm not sure if that's possible...

Code: Select all


Macro rtdebug (x)

  Select TypeOf(x)
    Case #PB_String
      Debug "X"
    Case #PB_Integer
      Debug "Y"
EndSelect
  
EndMacro
  
  a.i  = 5
  b.s  = "hello"
  
RTDebug ( a)    ;; ok
RTDebug ( b)    ;; ok
RTDebug ( 3)     ;; error
RTDebug ( "ab")  ;; error

User avatar
NicTheQuick
Addict
Addict
Posts: 1227
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Test if literal value is numeric or text

Post by NicTheQuick »

Unfortunality you can not solve that problem. I did something similar here: viewtopic.php?f=3&t=53156 (from 2013 :shock:)

It is up to Fred to implement a better TypeOf functionality. I really would appreciate it.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
mestnyi
Addict
Addict
Posts: 1000
Joined: Mon Nov 25, 2013 6:41 am

Re: Test if literal value is numeric or text

Post by mestnyi »

Code: Select all

Macro rtdebug (x)
  CompilerIf Defined(x, #PB_Variable)
    Select TypeOf(x)
      Case #PB_String
        Debug "Variable String "+x
      Case #PB_Variable
        Debug "Variable "+x
      Case #PB_Integer
        Debug "Variable Integer "+x
    EndSelect
  CompilerElse
    Debug "Integer "+x
  CompilerEndIf
EndMacro

a.i  = 5
b.s  = "hello"

RTDebug ( a)    ;; ok
RTDebug ( b)    ;; ok
RTDebug ( 3)    ;; ok
            ;    RTDebug ( "ab")  ;; error
User avatar
NicTheQuick
Addict
Addict
Posts: 1227
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Test if literal value is numeric or text

Post by NicTheQuick »

That's exactly the same as I did. But literal strings don't work.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
mestnyi
Addict
Addict
Posts: 1000
Joined: Mon Nov 25, 2013 6:41 am

Re: Test if literal value is numeric or text

Post by mestnyi »

I did not follow the link. sorry :oops:
Post Reply