Qbasicnews.com

Full Version: Macro
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi!

In RapidQ there are ( from C) next syntax
a$="1234"
c$=a$[3]
print c$ ' printed 3

In FreeBasic [..] is used for pointers

I Try
Code:
#DEFINE char(a$,i) (mid$(a$, i, 1))
dim aaa as string
aaa="1234"
z$=char(aaa,3)
print z$

It works
but when I try this
Code:
#DEFINE a{i} mid$(a, i, 1)
print aaa{2}
- there are error

Well, I know it's not correct syntax - but how can I do it?

And with this code compiler seems freeze
Code:
#DEFINE a${i} mid$(a$, i, 1)
#DEFINE char(a$,i) (mid$(a$, i, 1))

dim aaa as string
aaa="1234"
Try to use strptr:

dim sptr as ubyte ptr

sptr = strptr(a$)

then you can do the old sptr[index] thingy.
Thanks!
{} is not valid with macros, the arguments are defined as in C, using ().

You shouldn't use suffix either, macro arguments are typeless, they can be anything.

Compiler freezes because the a$ macro enters in an infinite loop, as "a$" is being used in the macro body itself.
Quote:{} is not valid with macros, the arguments are defined as in C, using ().

You shouldn't use suffix either, macro arguments are typeless, they can be anything.

Compiler freezes because the a$ macro enters in an infinite loop, as "a$" is being used in the macro body itself.

Yeh.. my mistake
Thanks
Here is another Qmacros in FB... Wink

[syntax="free Basic"]
' 32Bits Basic macros for FB simulations

#define checktypes :option explicit
#define sizeof len
#define a.size len(a)
#define s.length len(s)
#define pause print:print("Any key to exit...")Confusedleep

#CheckTypes!

dim a as integer
dim s as string
dim c as double 'try remark this line to wake-up #checktypes!

s = "Attention! OOP robot is invading FB!"

print "a.size = ";a.size;" bytes"
print "s.length = ";s.length;" bytes"
print "sizeof© = ";sizeof©;" bytes"
pause
[/syntax]

Here is the print-out:
Code:
a.size =  4 bytes
s.length =  36 bytes
sizeof(c) =  8 bytes

Any key to exit...
Quote:Here is another Qmacros in FB... Wink

[syntax="free Basic"]
' 32Bits Basic macros for FB simulations

#define checktypes :option explicit
#define sizeof len
#define a.size len(a)
[...]
print "a.size = ";a.size;" bytes"
[/syntax]

More interesting Tongue

#define *.size len(*)

dim a as integer
dim b1 as byte
dim qwerty as short

print "a.size = ";a.size;" bytes"
print "b1.size = ";b1.size;" bytes"
print "qwerty.size = ";qwerty.size;" bytes"
Are you sure?

Quote:
Code:
#define *.size len(*)

Your code is rejected by FB version 0.12b...
you misspelled 'length'
thanks DrV.
Pages: 1 2