Adding string AND numbers

Just starting out? Need help? Post your questions and find answers here.
normeus
Enthusiast
Enthusiast
Posts: 415
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Adding string AND numbers

Post by normeus »

PB5.60 x86 windows 7 pro
Is adding a number without using Str() to text a new thing?
or more than likely I screwed up and changed a setting somewhere.

Code: Select all

txt$="total:"
num=8
Debug "total:" + 8.23
Debug txt$ + num
Debug txt$ + Str(num)
I noticed this with SetGadgetText(3,"Total:" + num )
I forgot to wrap num with Str() but no complains from editor or compiler.

Thank you.
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Adding string AND numbers

Post by Josh »

Auto-casting was implemented with PB 5.10
Help wrote: 14th February 2013 : Version 5.10
- Added: autocast of numeric values when string are involved, allowing to concatenate string and numeric in constants
sorry for my bad english
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Adding string AND numbers

Post by Dude »

Just be aware it only works if the string is on the left side, otherwise you still need Str():

Code: Select all

txt$="total: "
num=8
Debug txt$+num ; OK!

num=8
txt$=" is the total"
Debug num+txt$ ; Error
User avatar
mk-soft
Always Here
Always Here
Posts: 5393
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Adding string AND numbers

Post by mk-soft »

I like simple VB-Script cast to string

Code: Select all

num=8
txt$=" is the total"
Debug ""+num+txt$ ; No Error
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
normeus
Enthusiast
Enthusiast
Posts: 415
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Adding string AND numbers

Post by normeus »

Thanks guys.

I knew it had to be my lack of reading. ( help file should be your friend, but I don't make friends easily)

It will be a game changer for debug. I will continue to use Str() for everything else:

I specially like @mk-soft empty string trick.

Code: Select all

 Debug ""+num+txt$ ; No Error
Thanks again.
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Post Reply