Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
August 7th, 2008, 07:28 PM
|
#1 (permalink)
| | Junior Member
Join Date: Aug 2008
Posts: 6
|
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 8th, 2008, 12:04 AM
|
#2 (permalink)
| | Ultimate Member
Join Date: Mar 2005 Location: Out of my mind
Posts: 2,742
|
Did you declare the array? Is vb.net case sensitive (e.g. MyArray <> myArrary). |
| |
August 8th, 2008, 12:50 AM
|
#3 (permalink)
| | Junior 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, 08:27 AM
|
#4 (permalink)
| | Ultimate Member
Join Date: Mar 2005 Location: Out of my mind
Posts: 2,742
|
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 Procedure
Last edited by Rootstonian : August 8th, 2008 at 08:37 AM.
|
| |
August 8th, 2008, 05:49 PM
|
#5 (permalink)
| | Junior 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, 10:39 PM
|
#6 (permalink)
| | Ultimate Member
Join Date: Mar 2005 Location: Out of my mind
Posts: 2,742
|
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, 11:25 PM
|
#7 (permalink)
| | Member
Join Date: Oct 2003
Posts: 247
|
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: 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) if you send back your code I would be able to fix you up and put you on the right path. |
| |
August 11th, 2008, 11:35 PM
|
#8 (permalink)
| | Member
Join Date: Oct 2003
Posts: 247
|
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. |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |