Qbasicnews.com
June 21, 2021, 04:36:40 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Macro  (Read 6737 times)
diakin
Member
*
Posts: 72



WWW
« on: March 12, 2005, 08:07:12 AM »

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"

Logged

ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #1 on: March 12, 2005, 08:13:40 AM »

Try to use strptr:

dim sptr as ubyte ptr

sptr = strptr(a$)

then you can do the old sptr[index] thingy.
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
diakin
Member
*
Posts: 72



WWW
« Reply #2 on: March 12, 2005, 08:40:44 AM »

Thanks!
Logged

ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #3 on: March 12, 2005, 12:44:13 PM »

{} 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.
Logged

diakin
Member
*
Posts: 72



WWW
« Reply #4 on: March 13, 2005, 05:05:54 AM »

Quote from: "v3cz0r"
{} 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
Logged

ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
zydon
Member
*
Posts: 69



« Reply #5 on: March 13, 2005, 06:34:32 AM »

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..."):sleep

#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(c) = ";sizeof(c);" 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...
Logged

 = inc() Cheesy
diakin
Member
*
Posts: 72



WWW
« Reply #6 on: March 13, 2005, 10:21:26 AM »

Quote from: "zydon"
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"
Logged

ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
zydon
Member
*
Posts: 69



« Reply #7 on: March 13, 2005, 01:37:42 PM »

Are you sure?

Quote from: "diakin"

Code:
#define *.size len(*)



Your code is rejected by FB version 0.12b...
Logged

 = inc() Cheesy
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #8 on: March 13, 2005, 01:43:55 PM »

you misspelled 'length'
Logged
zydon
Member
*
Posts: 69



« Reply #9 on: March 13, 2005, 02:06:43 PM »

thanks DrV.
Logged

 = inc() Cheesy
diakin
Member
*
Posts: 72



WWW
« Reply #10 on: March 13, 2005, 02:31:24 PM »

Quote from: "zydon"
Are you sure?

Code:
#define *.size len(*)


Your code is rejected by FB version 0.12b...


It's my wishes only  Smiley
Logged

ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
VonGodric
Ancient Guru
****
Posts: 674



WWW
« Reply #11 on: March 14, 2005, 03:28:19 AM »

this would make possible to do a very Fake oop programming, but hey that would be kwel Cheesy
Logged

url]http://fbide.sourceforge.net/[/url]
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!