0

How to concatenate integer correctly with macro ? I must call it twice here because i can't add something after ","(error)

#define concat(a,b,c) a##b##c
dim as integer a=10,b=20,c=30,d
d = a concat(*100+,,)b
d = d concat(*100+,,)c
?d  'output = 102030
sleep
Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
nimday
  • 333
  • 3
  • 9

2 Answers2

1
#define concat(a,b,c) val(str(a)+str(b)+str(c))
Joe
  • 1,330
  • 13
  • 15
0

I found a solution from freebasic forum

#define concat(a,b,c)  (((a)*100+(b))*100+(c))
dim as integer a=10,b=20,c=30,d
d = concat(a,b,c)
?d  'output = 102030
sleep
nimday
  • 333
  • 3
  • 9
  • This won't work in all cases. If c is 300 then you'll get 1002300 instead of 10020300. See my answer if you need something more accurate. – Joe Oct 15 '17 at 16:15