Qbasicnews.com
February 28, 2020, 04:25:34 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: arrays  (Read 2881 times)
lfbflyer44
New Member

Posts: 4


« on: December 20, 2004, 07:39:06 PM »

is there a command that returns the dimensions of an array?  the reason i ask is because i want to redimension an array based on its previous length

thanks
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #1 on: December 20, 2004, 07:47:18 PM »

UBOUND()
LBOUND()

Upper boundary
Lower boundary


Used like this:
Code:
Dim array(5 To 100) As Integer
Print UBOUND(array)
Print LBOUND(array)
Logged
lfbflyer44
New Member

Posts: 4


« Reply #2 on: December 20, 2004, 07:59:17 PM »

ok thanks, it works perfectly Cheesy
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #3 on: December 21, 2004, 01:36:42 AM »

np, glad to help
Logged
Pyrokid
Wandering Guru
***
Posts: 355



WWW
« Reply #4 on: March 05, 2005, 02:09:03 AM »

I also have a question about arrays.  Say if i want to reset the limits of an array how would i do this. eg: DIM a(15) and then say i wanted it to be DIM a(20).
Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #5 on: March 05, 2005, 02:59:47 AM »

It's ok to start a new thread for a new question. Wink


All you have to do is use:

At the beginning of your program...
Code:
'$DYNAMIC


Then, whenever you want to modify the array...
Code:
REDIM Array(Length)


You might try FreeBASIC because you can use PRESERVE, which wont destroy the old data... as long as you dont write over it.  Smiley
Logged
Ralph
Ancient Guru
****
Posts: 544


« Reply #6 on: March 05, 2005, 08:20:31 PM »

Quote from: "Dr_Davenstein"
It's ok to start a new thread for a new question. Wink


All you have to do is use:

At the beginning of your program...
Code:
'$DYNAMIC


Then, whenever you want to modify the array...
Code:
REDIM Array(Length)


You might try FreeBASIC because you can use PRESERVE, which wont destroy the old data... as long as you dont write over it.  Smiley

In QuickBASIC, if you want to REDIM an array, as the Dr. explains above, you can...but the REDIMmed array will now be devoid of data.

 So, to reenter the data into the array, you must have access to the original data after the REDIM.

The data might be in a file, which you can now open and load into the array.

If not, before the REDIM, you should DIM an auxiliary array of the same size as the original, make each element contain the corresponding data of the original array with a FOR...NEXT loop, do your REDIM on the original array, make each element of the original array equal the corresponding element of the auxiliary array with a FOR...NEXT loop (or other similar strategy).  

Now, you can proceed to add new data to the enlarged array.
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
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!