[BASIC language] Removing an array element -- how?

Click For Summary

Discussion Overview

The discussion revolves around the problem of removing an element from an array in BASIC programming. Participants explore various methods and considerations related to array manipulation, including the implications of different BASIC dialects and the potential need for alternative data structures.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant expresses confusion about how to remove an element from an array and resize it accordingly.
  • Several participants question which dialect of BASIC is being referenced, suggesting that the method may vary.
  • One participant suggests moving elements down in the array to fill the gap left by the removed element and then reducing the array size.
  • Another participant mentions the use of dynamic arrays and the ReDim Preserve command in some dialects of BASIC.
  • Concerns are raised about the overhead involved in resizing arrays and the suggestion that lists may be more suitable for dynamic data management.
  • A participant shares a method for removing an element, including a code snippet, but later acknowledges an error in the loop variable.
  • Another participant points out that changing the size variable does not actually change the number of elements in the array.
  • Some participants discuss the potential confusion between the size of the array and the count of active elements within it.
  • One participant suggests using a second array of booleans to track active records, allowing for logical deletion without physically resizing the array.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method for removing an array element, with multiple competing views and suggestions presented throughout the discussion.

Contextual Notes

Participants note that arrays in many dialects of BASIC are zero-based, which may affect indexing. There is also mention of the need to manage access to the array and the implications of using different dialects of BASIC.

Who May Find This Useful

This discussion may be useful for individuals learning BASIC programming, particularly those interested in array manipulation and data structure management.

  • #31
Liberty BASIC appears to be missing much of the structured data that is in VB and FB.
Being limited to a 2D array makes it more of a teaching language than a productive workhorse. $60 seems a high price to pay for restricted features, when it can be fully featured, open source, and free.

But BASIC is quite capable of the task. I would start with a record structure for the file storage, then write routines to read and write that to an array, with a validity flag to make deletion easy. Reading the file into the array, editing, then writing it back PRESERVEs data, and eliminates deleted data. REDIM the dynamic array to fit the size of the data file it must hold. For data entered by hand, cheap memory and disc storage are not a limit. The limit is your ability to structure the data record.
 
Technology news on Phys.org
  • #32
Baluncore said:
But BASIC is quite capable of the task. I would start with a record structure for the file storage, then write routines to read and write that to an array, with a validity flag to make deletion easy. Reading the file into the array, editing, then writing it back PRESERVEs data, and eliminates deleted data. REDIM the dynamic array to fit the size of the data file it must hold. For data entered by hand, cheap memory and disc storage are not a limit. The limit is your ability to structure the data record.
Much of what you characterize there is what I have spent the last two or three weeks relearning. (and I have not finished this relearning.)
 
  • #33
256bits said:
Not sure if one can delete unused memory in any Basic version? such as for an array that does not need its use anymore.
REDIM Array( 0 [,0] ) releases the memory.
Memory is released when an array or variable is lost from scope.
If you can do something in C, you can do it in FreeBASIC, because FB is now a frontend that translates to C, links to libraries, optimises and compiles to various platforms.
 
  • Like
Likes   Reactions: 256bits

Similar threads

Replies
20
Views
2K
Replies
235
Views
14K
  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
43
Views
5K
Replies
47
Views
5K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
22K
  • · Replies 397 ·
14
Replies
397
Views
20K