How can i send arrays to a function?
example i have an array with 400 elements containing random numbers how can i send those to a function, say to add 1 to each them?
How can i send arrays to a function?
example i have an array with 400 elements containing random numbers how can i send those to a function, say to add 1 to each them?
You define your sub or function to take an array of the given type as a parameter then you pass your array as a parameter.
You could optionally use a sub and ByRef to work directly with your existing array depending on your needs.Code:Private Function DoSomething(ByVal MyArray as Integer()) as Integer() 'dosomething with the array return MyArray end function
you can use a lambda function for that:
vb Code:
Dim numbers() As Integer = Enumerable.Range(1, 400).ToArray numbers = Array.ConvertAll(numbers, Function(x) x + 1)
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
There is no need to use ByRef. All arrays are instances of the Array class. Just like all class instances, they are reference type objects. As such, there is no copy made and any changes you make to the one and only Array object are reflected in the caller. Just like all classes, the only reason you would need to use ByRef was if you actually wanted to assign a new object to the parameter inside the method.
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Match Two Game, *NEW* More Random Random Numbers) | C# (*NEW* Match Two Game, *NEW* More Random Random Numbers)
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces