Qbasicnews.com
May 23, 2019, 04:03:32 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Array mass assignment  (Read 3097 times)
Z!re
*/-\*
*****
Posts: 4599


« on: May 02, 2005, 07:17:21 AM »

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
Logged
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #1 on: May 03, 2005, 06:38:13 PM »

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?
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Z!re
*/-\*
*****
Posts: 4599


« Reply #2 on: May 03, 2005, 07:53:56 PM »

No, not at compile time.

I mean in "realtime"


Read my post again
Logged
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #3 on: May 03, 2005, 09:27:09 PM »

/me 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. Cheesy
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Z!re
*/-\*
*****
Posts: 4599


« Reply #4 on: May 03, 2005, 09:31:27 PM »

Quote from: "Z!re"
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.
Logged
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #5 on: May 03, 2005, 09:51:42 PM »

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
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!