# Concatenating Variables as Text

• ### Question

• Apologies if this has been asked already - I've had a dig in the forum and couldn't find anything that covered this.

I'm porting a program from Python that converts a number of a certain base to a different base. I need to build the final result by concatenating the individual results of a for loop e.g. converting FF to denary:

1. I divide 255 by 100 to get a value of 2 for my first column

2. I then divide the remainder (55) by 10 to get 5, etc.

In Python I can use + to either add if the variable's data type is numeric (giving me 12), or concatenate if the data type is string (giving me 255). I can't for the life of me work out how to 'build a string' in Small Basic. I feel like I'm missing something fundamental - any pointers appreciated.

Many thanks.

Tuesday, May 12, 2015 9:31 AM

• Small Basic defines the type of data and converts them if necessary. Here's an example:

X_num = 10
Y_sim = "10"
rezult_num = X_num + Y_sim
rezult_sim = Text.Append(X_num, Y_sim)

TextWindow.WriteLine(rezult_num)
TextWindow.WriteLine(rezult_sim)

Tuesday, May 12, 2015 10:17 AM

### All replies

• You can use a "+" which will concatanate strings, except when both parts are nuimeric. To force concatanation use Text.Append(text1,text2)

Also realize then SmallBasic doesn't do integer division,  255/100 is not 2 but 2.55. You have to use Math.Floor(255/100) which is 2.

Jan [ WhTurner ] The Netherlands

Tuesday, May 12, 2015 10:11 AM
• Small Basic defines the type of data and converts them if necessary. Here's an example:

X_num = 10
Y_sim = "10"
rezult_num = X_num + Y_sim
rezult_sim = Text.Append(X_num, Y_sim)

TextWindow.WriteLine(rezult_num)
TextWindow.WriteLine(rezult_sim)

Tuesday, May 12, 2015 10:17 AM
• Text.Append() is exactly what I was looking for, thank you. Don't know how I missed it.

What I had done as a workaround was to populate an array with each column value, then at the end print each value from the array using TextWindow.Write() using a loop. Both methods work, one is more elegant that the other ;)

• Edited by Tuesday, May 12, 2015 10:53 AM typo
Tuesday, May 12, 2015 10:53 AM