Qbasicnews.com

Full Version: Array mass assignment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, 20, 30 }
arr( 3 ) = { 40, 50, 60 }
print arr( 1 ) 'output should be 20
print arr( 4 ) 'output should be 50
It would be really nice to have, IMO

Preferably it should be able to take variables too:
Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, var1, 30 }
arr( 3 ) = { 40, 50, var2 }
print arr( 1 ) 'output should be 'var1'
print arr( 4 ) 'output should be 50
You mean like this?
Code:
Dim a(0 to 9) as ubyte => { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }
Which was implemented in .13?
No, not at compile time.

I mean in "realtime"


Read my post again
* 1000101 notes your original post said nothing about at compile-time or at run-time.

By the by, it will work at runtime if it can't be resolved at compile time.

I do this for error checking to keep track of which function is currently executed.

ie
Code:
#define _this_proc_ 1
#define _that_proc_ 2

declare sub this_proc ()
declare sub that_proc ()

dim shared CurrentProc as integer

CurrentProc = 0

this_proc
that_proc

End

Sub this_proc ()

   Dim LastProc as integer = CurrentProc
   CurrentProc = _this_proc_

   '' Do stuff

   CurrentProc = LastProc

End sub

Sub that_proc ()

   Dim LastProc as integer = CurrentProc
   CurrentProc = _that_proc_

   '' Do stuff

   CurrentProc = LastProc

End sub

Of cource, my program is a lot more complex which is why I do that, but you get the general idea.

While my example only shows a single variable being auto-assigned at allocation, it still bears proof-of-conciept. Big Grin
Quote:
Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, 20, 30 }
arr( 3 ) = { 40, 50, 60 }
print arr( 1 ) 'output should be 20
print arr( 4 ) 'output should be 50
It would be really nice to have, IMO

Preferably it should be able to take variables too:
Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, var1, 30 }
arr( 3 ) = { 40, 50, var2 }
print arr( 1 ) 'output should be 'var1'
print arr( 4 ) 'output should be 50

Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, var1, 30 }
arr( 3 ) = { 40, 50, var2 }
print arr( 1 ) 'output should be 'var1'
print arr( 4 ) 'output should be 50

arr ( 0 ) = { arr(3), 55, what+that+arr(5) }

print arr(0) 'should = arr(3) (which is 40)
print arr(1) 'should = 55
print arr(2) 'should = what+that+arr(5) (which is= var2)

Note that I DO NOT assign ALL the elements in the array, and that I specify a starting point where to start assigning from.
True enough, but your request wasn't specific enough to draw any conclusions from. I was operating on the assumption that you weren't aware of declaration assignments.

Still, in the example you gave, the compiler would end up optimizing that to be a compile time assignment with the unknowns filled with nulls.

But, assuming you were using vairables instead of litterals, then that would have some value. I see what you are getting at, however, you should be more specific in the future ;P