home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2734
Discussions: 186,607, Posts: 2,227,058, Members: 230,242
Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
Old August 7th, 2008, 07:28 PM   Digg it!   #1 (permalink)
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.

Xcalibvr is offline   Reply With Quote
TechIMO.com Ads - Login or register for less ads.
How many errors does your computer have?

You no longer need to guess! This free stability scan and registry cleaner download will give you a complete diagnosis of your Windows registry, identifying errors and conflicts.

FREE instant scan


Guest, Register Free! to remove this ad and get your tech support questions answered in minutes!
Old August 8th, 2008, 12:04 AM     #2 (permalink)
Ultimate Member
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 2,742
Send a message via AIM to Rootstonian
Did you declare the array? Is vb.net case sensitive (e.g. MyArray <> myArrary).

Rootstonian is online now   Reply With Quote
Old 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.

Xcalibvr is offline   Reply With Quote
Old August 8th, 2008, 08:27 AM     #4 (permalink)
Ultimate Member
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 2,742
Send a message via AIM to Rootstonian
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.
Rootstonian is online now   Reply With Quote
Old 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.
Xcalibvr is offline   Reply With Quote
Old August 8th, 2008, 10:39 PM     #6 (permalink)
Ultimate Member
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 2,742
Send a message via AIM to Rootstonian
Please explaing "module" for me?

A sample of your code wouldn't hurt or try to explain just what you're trying to accomplish
Rootstonian is online now   Reply With Quote
Old August 11th, 2008, 11:25 PM     #7 (permalink)
Member
 
Join Date: Oct 2003
Posts: 247
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.
amtrac24 is offline   Reply With Quote
Old 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.
amtrac24 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
RAID arrays CowboyHacker Storage Related 4 July 18th, 2007 02:08 AM
C++ String Arrays Vyx Webmastering and Programming 7 February 19th, 2007 09:41 AM
can arrays count for you? ShuckyD Webmastering and Programming 9 December 5th, 2006 06:51 AM
overclocking and raid arrays mrniceguy Processors, Memory, and Overclocking 2 October 3rd, 2006 12:56 PM
Fast RAID arrays andylister Storage Related 5 April 2nd, 2004 05:41 AM

Most Active Discussions
Is It Just Me? (531)
Misery Loves Company... (1849)
Why Does the MOON Grow Bigger as It.. (18)
heatsink issue (10)
New Mobo (18)
UPGRADING C/D DRIVE TO 250GB & .. (14)
1 internet. 1 house. 3 computer. ho.. (13)
SSD's, RAID, and External Backup (7)
Is This A Compatible Gaming PC? (18)
Recent Discussions
32 or 64 bit vista (4)
Big problem with my PC (2)
system restore 'next' button wo.. (2)
Building my first PC and need s.. (1)
firewall (1)
C++ compiler suggestions (4)
Official World of Warcraft Thre.. (4529)
Programming question (2)
UPGRADING C/D DRIVE TO 250GB &a.. (14)
FS: Dell 6000 laptop, modded 36.. (2)
Apple iPod touch 16 GB $200 (4)
Six 28-Disc Cross Design Black .. (4)


All times are GMT -4. The time now is 12:24 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28