? Array Resize ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Array Resize

A function to resize any type of 1 dimensional array:DEF RESIZE ARRAY,SIZE WHILE LEN(ARRAY)>SIZE && ""*POP(ARRAY):WEND COPY ARRAY,SIZE,ARRAY,0 END Example usage: DIM A[10] ?LEN(A) RESIZE A,3 ?LEN(A) RESIZE A,27 ?LEN(A)
Author
12Me21
Updated
Rating
2 votes
Categories
Keywords
  • resize
  • redim
3 Comment(s) DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength EVEN BETTER: DEF RESIZE A, S DIM NEW[S] COPY A,NEW A = NEW OR SOMETHING SIMILIAR auceps auceps can you downsize 12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Yes, but the point is to do it without having to create a new array. For your solution to work, you'd need to do: DEF RESIZE(A,S) DIM NEW[S] COPY NEW,A,S RETURN A END DIM TEST[10] TEST=RESIZE(TEST,3) (Plus you'd need separate functions for int/float/string arrays) Which works fine (and is probably faster) in many situations, but, for example, in a function that modifies arrays in-place, it won't work.