PDA

View Full Version : array question multiple assignment

Lionheart008
17-03-2012, 10:17
it's possible to convert this array example from oxygen module to thinbasic?

Uses "console" 'multiple assignment
Dim a(10) As Long
'Dim a(10) As Long => (2,4,6,8,10,12,42,99) ' that's possible to convert to thinbasic?
Dim s As String
s = a(2) + a(5) 'result: 14
Print "answer is: " + s + a(6) 'result: 14 12
WaitKey

thanks for help in advance, good week-end, frank

Petr Schreiber
17-03-2012, 11:12
Hi,

it is basically the same, instead of <= you would use just = and ommit the parenthesis.

Way #1

Dim a(10) As Long = 2, 4, 6, 8, 10, 12, 42, 99

Way #2

Long a(10) = 2, 4, 6, 8, 10, 12, 42, 99

Way #3 - after array is declared

a(1) = 2, 4, 6, 8, 10, 12, 42, 99

There is problem in your code at line:

Dim s As String
s = a(2) + a(5) ' result: 14

... this will not result in 14, because you assign to string. That means the array values will be converted to string first, behaving as "4" + "10", resulting in "410".

To do what you need, you should use:

Dim s As String
s = Format\$(a(2) + a(5)) 'result: 14

Petr

Lionheart008
19-03-2012, 10:21
thank you petr for answer and explanationes :) that's working fine. my mistake don't using format\$ for adding strings, I've forgot that.. I have tried making some exercises with combobox/listbox for my fundialox module and wanted to work with alternative way don't using "array assign" but that's nearly impossible after first experiments. but I will see. have a nice day and good luck for your studying time with your pretties robots.

regards, frank