+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Junior 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.

  2. #2
    Caveat Emptor Rootstonian's Avatar
    Join Date
    Mar 2005
    Location
    Out of my mind
    Posts
    3,348
    Did you declare the array? Is vb.net case sensitive (e.g. MyArray <> myArrary).

  3. #3
    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.

  4. #4
    Caveat Emptor Rootstonian's Avatar
    Join Date
    Mar 2005
    Location
    Out of my mind
    Posts
    3,348
    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 07:37 AM.

  5. #5
    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.

  6. #6
    Caveat Emptor Rootstonian's Avatar
    Join Date
    Mar 2005
    Location
    Out of my mind
    Posts
    3,348
    Please explaing "module" for me?

    A sample of your code wouldn't hurt or try to explain just what you're trying to accomplish

  7. #7
    Member
    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:

    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.

  8. #8
    Member
    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.

  9. #9
    Junior 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

  1. RAID arrays
    By CowboyHacker in forum Storage Related
    Replies: 4
    Last Post: July 18th, 2007, 01:08 AM
  2. C++ String Arrays
    By Vyx in forum Webmastering and Programming
    Replies: 7
    Last Post: February 19th, 2007, 09:41 AM
  3. can arrays count for you?
    By ShuckyD in forum Webmastering and Programming
    Replies: 9
    Last Post: December 5th, 2006, 06:51 AM
  4. overclocking and raid arrays
    By mrniceguy in forum Processors, Memory, and Overclocking
    Replies: 2
    Last Post: October 3rd, 2006, 11:56 AM
  5. Fast RAID arrays
    By andylister in forum Storage Related
    Replies: 5
    Last Post: April 2nd, 2004, 05:41 AM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews