Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

😎 Array functions that are similar JavaScript functions. Example: Push, Pop, Shift, Unshift, Sort, length, toString.

License

NotificationsYou must be signed in to change notification settings

todar/VBA-Arrays

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A whole bunch of Array functions to make it easier and faster coding. Many functions are to try and mimic JavaScript. Example: Push, Pop, Shift, Unshift, Splice, Sort, Reverse, length, toString.

Buy Me A Coffee


Other Helpful Resources

  • www.roberttodar.com About me and my background and some of my other projects.
  • Style Guide A guide for writing clean VBA code. Notes on how to take notes =)
  • Boilerplate Boilerplate that contains a bunch of helper libraries such as JSON tools, Code Analytics, LocalStorage, Unit Testing, version control and local network distribution, userform events, and more!
  • Strings String function library.ToString,Inject,StringSimilarity, and more.
  • Analytics Way of tracking code analytics and metrics. Useful when multiple users are running code within a shared network.
  • Userform EventListener Listen to events such asmouseover,mouseout,focus,blur, and more.

List of Available Functions

Function NameDescription
ArrayAverageReturns the average of all the numbers inside an array.
ArrayContainsEmptiesReturnsTrue if the array contains any empties.
ArrayDimensionLengthReturns the dimensionlenght of the array.
ArrayExtractColumnExtracts a column from a 2 dim array and returns it as a 1 dim array
ArrayExtractRowExtracts a row from a 2 dim array and returns it as a 1 dim array
ArrayFilterUses regex to filter items in a single dim array
ArrayFilterTwoUses regex to filter items in a two dim array.
ArrayFromRecordsetConverts a recordset into a 2 dim array including it's headers
ArrayGetColumnIndexReturn the column index based on the header name
ArrayGetIndexesReturns a single dim array of the indexes of column headers
ArrayIncludesChecks to see if a value is in single dim array
ArrayIndexOfReturns the index of an item in a single dim array
ArrayLengthReturns the number of items in an array
ArrayPluckExtracts a list of a given property. Must be array of dictionries
ArrayPopRemoves the last element in array, returns the popped element
ArrayPushAdds a new element(s) to an array (at the end), returns the new array length
ArrayPushTwoDimAdds a new element(s) to an array (at the end). Must be full row of data
ArrayQuerySaves array in CSV file and allows the ability to run ADODB queries on it.
ArrayRemoveDuplicatesRemoved duplicates from single dim array
ArrayReverseReverse array (can be used after sort to get the descending order)
ArrayShiftRemoves element from array - returns removed element
ArraySortSort an array
ArraySpliceChanges the contents of an array by removing or replacing existing elements and/or adding new elements.
ArraySpreadSpreads out an array into a single array. example: jagged arrays, dictionaries, collections.
ArraySumReturns the Sum of a single dim array containing numbers
ArrayToCSVFileSaves a two dim array to a CSV file
ArrayToStringReturns a string from a 1 or 2 dim array, separated by optional delimiter and vbnewline for each row
ArrayTransposeApplication.Transpose has a limit on the size of the array and is limited to the 1st dim. This fixes those issues.
ArrayUnShiftAdds a new element to the begining of the array
AssignQuick tool to either set or let depending on if element is an object
ConvertToArrayConvert other list type objects to an array
IsArrayEmptyThis function tests whether the array is empty (unallocated). Returns TRUE or FALSE.

How to use

  1. Import ArrayFunctions.bas file.
  2. Set a reference toMicrosoft Scripting Runtime as this uses dictionaries for removing duplicates.

Examples

Below are some of the examples you can do with single dim arrays. Note, there are several functions for two dim arrays as well.

'EXAMPLES OF VARIOUS FUNCTIONSPrivateSubarrayFunctionExamples()' For simplicity using `a` as the variable. Otherwise, don't do that in your real code! =)DimaAsVariant' Single dim functions that manipulate the array.ArrayPusha,"Banana","Apple","Carrot"'--> Banana,Apple,CarrotArrayPopa'--> Banana,Apple --> returns CarrotArrayUnShifta,"Mango","Orange"'--> Mango,Orange,Banana,AppleArrayShifta'--> Orange,Banana,AppleArraySplicea,2,0,"Coffee"'--> Orange,Banana,Coffee,AppleArraySplicea,0,1,"Mango","Coffee"'--> Mango,Coffee,Banana,Coffee,AppleArrayRemoveDuplicatesa'--> Mango,Coffee,Banana,AppleArraySorta'--> Apple,Banana,Coffee,MangoArrayReversea'--> Mango,Coffee,Banana,Apple' Array properties functions.' These get details of the array: index of items, lenght, ect.ArrayLengtha'--> 4ArrayIndexOfa,"Coffee"'--> 1ArrayIncludesa,"Banana"'--> TruearrayContainsa,Array("Test","Banana")'--> TrueArrayContainsEmptiesa'--> FalseArrayDimensionLengtha'--> 1 (single dim array)IsArrayEmptya'--> False' Here is an example of a jagged array.a=Array(1,2,3,Array(4,5,6,Array(7,8,9)))' Can flatten jagged array with the spread formula. Note this is a deep spread.' This formula also spreads dictionaires and collections as well!a=ArraySpread(a)'--> 1,2,3,4,5,6,7,8,9' Math function examplesArraySuma'--> 45ArrayAveragea'--> 5' Filter use's regex patterna=Array("Banana","Coffee","Apple","Carrot","Canolope")a=ArrayFilter(a,"^Ca|^Ap")' Array to string works with both single and double dim arrays!Debug.PrintArrayToString(a)EndSub

About

😎 Array functions that are similar JavaScript functions. Example: Push, Pop, Shift, Unshift, Sort, length, toString.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

    Packages

    No packages published

    Languages


    [8]ページ先頭

    ©2009-2025 Movatter.jp