Ooops
April 02, 2020, 11:03:10 AM

Author Topic: Working with Array  (Read 185 times)

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
Working with Array
« on: February 25, 2020, 11:41:56 PM »
Hi, I have some questions about Arrays...

Im trying to work with Arrays and its a bit frustrating.. compared to TList.

For Example.. How can I clear Array?
How Can I tell Array Size?

Any Info about Arrays will be Nice

Thanks H.C
Happy New Year

Online ImJustAnotherCoder

  • Jr. Member
  • **
  • Posts: 14
Re: Working with Array
« Reply #1 on: February 26, 2020, 04:04:51 AM »
Quote
How can I clear Array?
Code: [Select]
Strict

' Declare an array
Local a:int[]

' Assign data to an array
a = Int[1,2]

' Declare and assign an array
Local array:Int[] = [1,2,3,4]

' reassign the array data completely
array = [7,6,5,4,3,2,1]

' Clear and empty the array - puts it up for garbage collection
array = Null
' or assign to a new array with 5 entries initialized to default of 0
array = New Int[5]

' Just clear the array contents keeping its size the same
For Local i:Int = 0 Until array.length
    array[i] = 0
Next
The above fundamentals work the same for arrays of objects too.

Quote
How Can I tell Array Size?
Code: [Select]
Local Length:int = array.length

Quote
Any Info about Arrays will be Nice
In the standard MaxIde editor menu go to Help-Home-Language[near the bottom of the page]-Arrays

Offline Derron

  • Hero Member
  • *****
  • Posts: 2818
Re: Working with Array
« Reply #2 on: February 26, 2020, 06:10:03 AM »
https://blitzmax.org/docs/en/language/arrays

It misses an emphasized hint for ".length" and prefers to use "Len(arr)" in an example (the procedural interface way of requesting that information).


"Clearing out" - without assigning a NEW array requires iterating over it:

Code: [Select]
For local i:int = 0 until arr.length
  arr[i] = 0 'or Null for objects
Next


bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
Re: Working with Array
« Reply #3 on: February 26, 2020, 07:10:12 PM »
I was Trying to Redefine an Array Size.. im not sure its possible..

Ive Got an Image Say.. 600 on 400 pixels and I make an array of that Size..  Pixel[600,400]
then when I load a new image , i want to redefine this Pixel Array Size Again. Say.. 800 on 600 pixels.
Is it possible?
Happy New Year

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 409
Re: Working with Array
« Reply #4 on: February 26, 2020, 11:01:13 PM »
Ok, I Think i sorted it all out.. Thanks for the Help Guys
Happy New Year

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal