Thread: arrays in vb.net
-
August 7th, 2008, 06:28 PM #1Junior Member
- Join Date
- Aug 2008
- Posts
- 6
arrays in vb.net
Ok so Im starting school soon with plans of a Comp Sci major so I've started dabbling in vb.net and I'm having trouble with arrays in that when I try to use a specific array in a search argument it tells me that the array name hasn't yet been declared.
-
August 7th, 2008, 11:04 PM #2
Did you declare the array? Is vb.net case sensitive (e.g. MyArray <> myArrary).
-
August 7th, 2008, 11:50 PM #3Junior Member
- Join Date
- Aug 2008
- Posts
- 6
Well I have two Arrays housed in a module and when I call the module Im kinda stuck from there on what I should do about accessing my arrays to search their entries based on the specified criteria.
-
August 8th, 2008, 07:27 AM #4
I don't know VB.net, but in general programming, one would declare an array. Then it's loaded from a file or inside the program. Then, depending on some criteria, the array is searched and data is returned.
Arrays are searched either one element at a time, or if it's sorted (works best on numeric data), you can do a binary search. For or While loops handle this nicely.
For example:
Code:Procedure Find-State(state_to_find) index = 0 while index <= sizeof(array) if array(index) = state_to_find state = array(index) break end-if add 1 to index end-while return state End ProcedureLast edited by Rootstonian; August 8th, 2008 at 07:37 AM.
-
August 8th, 2008, 04:49 PM #5Junior Member
- Join Date
- Aug 2008
- Posts
- 6
Right, I understand the principal of searching through the elements, I think I actually asked the wrong question maybe.
What I'm having an issue with is that I have these arrays in a module because I thought it would be easier to do it like that for organizational purposes but I'm not entirely sure how to access the module to get the information held in the arrays inside.
-
August 8th, 2008, 09:39 PM #6
Please explaing "module" for me?
A sample of your code wouldn't hurt or try to explain just what you're trying to accomplish
-
August 11th, 2008, 10:25 PM #7Member
- Join Date
- Oct 2003
- Posts
- 267
let me try to help
i am a vb.net / asp.net programmer so i should be able to answer a few questions.
FYI: vb.net is a caseless language...myVariable does = MYVARIABLE
a module is just a generic page of code that you can call. All the functions or subs should be public on the page...
Sooo depending if your array is a public variable or in a function or sub within that module:
if you send back your code I would be able to fix you up and put you on the right path.Code:Module Module1 'My Array Of Strings Public myArray() As String = {"Item1", "Item2", "Item3"} End Module To call this array from a form or what not you would : MessageBox.Show(myArray(0)) -->msgbox showing "Item1" MessageBox.Show(myArray(1)) -->msgbox showing "Item2" if you have an array in a function you would do something like this: Public Function SendBackMyArray() As Int32() Dim returnArray() As Int32 = {24, 25, 26} Return returnArray End Function To call that function from a form or what not you would use: Dim myArray() As Int32 myArray = SendBackMyArray() MessageBox.Show(myArray(0).ToString)
-
August 11th, 2008, 10:35 PM #8Member
- Join Date
- Oct 2003
- Posts
- 267
FYI:
I really don't use arrays in .net. Maybe 5 % of the time. In Vb 6.0 you just redim preserve your array as you make it bigger. In .net this causes very very bad performance. In .net 1.1 you used arraylist. It dynamically resize as you add items to it. Only problem is all the items in the array list are of objects. In .net 2.0 + generic lists came about they are strongly typed.
dim myList as new list(of int32)
Generics are a form of collections which is a form of an array...so its the best way to use array types when you have to add / remove / resize arrays.
-
April 7th, 2009, 11:50 PM #9Junior Member
- Join Date
- Apr 2009
- Posts
- 1
Arrays
find some help about arrays
How to use VB.NET Arrays
How to use Array in CSharp
thaks.
savio
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
RAID arrays
By CowboyHacker in forum Storage RelatedReplies: 4Last Post: July 18th, 2007, 01:08 AM -
C++ String Arrays
By Vyx in forum Webmastering and ProgrammingReplies: 7Last Post: February 19th, 2007, 09:41 AM -
can arrays count for you?
By ShuckyD in forum Webmastering and ProgrammingReplies: 9Last Post: December 5th, 2006, 06:51 AM -
overclocking and raid arrays
By mrniceguy in forum Processors, Memory, and OverclockingReplies: 2Last Post: October 3rd, 2006, 11:56 AM -
Fast RAID arrays
By andylister in forum Storage RelatedReplies: 5Last Post: April 2nd, 2004, 05:41 AM



LinkBack URL
About LinkBacks



Reply With Quote

Slow news day? Trying to keep the public from actually looking at the troubles we have with our Government today? Someone cares?
Have They Found Jimmy Hoffa?