|
-
Apr 13th, 2008, 08:28 AM
#1
Thread Starter
Junior Member
Simple question
Hi, i'm making a replacement command prompt for windows xp, and for the prompts' variable system, I am using an array. I have never used arrays before, having always avoided it. I would appreciate a quick tutorial on using arrays.
Thanks in advance,
Sphincorp
-
Apr 13th, 2008, 08:39 AM
#2
Re: Simple question
http://www.startvbdotnet.com/language/arrays.aspx
Think of an array as an egg carton and each element as an egg. If you keep that analogy in your mind you should be OK. Remember that you cannot create an egg carton if you don't know how many eggs it needs to hold. The same goes for arrays. You cannot create an array object unless you specify how many elements it has. If you haven't specified a size then you haven't created an array. If you have specified a size then you have created an array. Also, you cannot actually change the size of an array. The way arrays are "resized" is to create a new array of the desired size and copy the elements from the old array. That is an expensive operation and should be avoided as much as possible.
Also, remember that just because an egg carton can hold a dozen eggs doesn't mean it DOES hold a dozen eggs. An array is the same. Just because you specify the size of an array doesn't mean that each element refers to an object. Just like any variable, an array element starts life being equal to Nothing.
Last edited by jmcilhinney; Apr 13th, 2008 at 08:44 AM.
-
Apr 13th, 2008, 08:41 AM
#3
Re: Simple question
Documentation should always be first. Have a look here and come back with any specific questions you may have.
-
Apr 13th, 2008, 08:52 AM
#4
Thread Starter
Junior Member
Re: Simple question
I need to created a pseudo variable system though.
Could I use something like :
dim variables(10) as array
0 = "main"
1 = "sub"
(more stuff)
select case variables
select case 0
(stuff)
etc...
-
Apr 13th, 2008, 08:53 AM
#5
Thread Starter
Junior Member
Re: Simple question
or can I have an array like :
variable | Value
variable | value
-
Apr 13th, 2008, 08:55 AM
#6
Re: Simple question
1. Neither of those posts make any sense to me.
2. You can't possibly have read the pages that I and nmadd linked to, so I suggest that you do that before asking more questions, given that those pages may well answer those questions without your having to ask them.
-
Apr 13th, 2008, 09:19 AM
#7
Re: Simple question
I am going to help just a little. Then, if you want more help it better be clear that you read the links provided, OK?
Code:
Dim anArray() As String = {"Read ", "the ", "links ", "provided. "}
For ctr As Integer = 0 To anArray.Length - 1
Debug.Write(anArray(ctr))
Next
Debug.WriteLine("Click on the Immediate Window when this stops")
Stop
-
Apr 13th, 2008, 10:23 AM
#8
Thread Starter
Junior Member
Re: Simple question
ok. I read both links, and Neither totally answered my question, but, I took snippets from each and think I got an Idea :
dim name(10) as string <--- name of variable with number
dim value(10) as string <--- Value of variables with matching numbers
dim count as integer <--- Current variable number
ex :
count = 0
name(count) = "main"
value(count) = "c:\windows\system32\"
-
Apr 13th, 2008, 10:27 AM
#9
Re: Simple question
How many elements are in your name and value array? This is meant to be an instructive question.
-
Apr 13th, 2008, 10:33 AM
#10
Thread Starter
Junior Member
Re: Simple question
Would this idea work though if I limited count to 10 and below?
-
Apr 13th, 2008, 10:34 AM
#11
Re: Simple question
 Originally Posted by SphinCorp
ok. I read both links, and Neither totally answered my question, but, I took snippets from each and think I got an Idea :
dim name(10) as string <--- name of variable with number
dim value(10) as string <--- Value of variables with matching numbers
dim count as integer <--- Current variable number
ex :
count = 0
name(count) = "main"
value(count) = "c:\windows\system32\"
Based upon my interpretation of this post, you are looking for a Collection representing a key, value pair - i.e. key->"main", value->"c:\windows\system32\" and not two Arrays and an Integer.
I believe this is what you are actually looking for: http://msdn2.microsoft.com/en-us/library/xfhwa508.aspx
-
Apr 13th, 2008, 10:41 AM
#12
Thread Starter
Junior Member
Re: Simple question
Thank you soooo much!
It was a dictionary I wanted after all. I won't mark resolved yet though in case I have trouble with the dictionary.
-
Apr 13th, 2008, 10:54 AM
#13
Thread Starter
Junior Member
Re: Simple question
Dim instance As Dictionary(Of TKey, TValue)
gives error "type tkey, tvalue not declared"
(btw, this IS a console app)
-
Apr 13th, 2008, 11:44 AM
#14
Re: Simple question
 Originally Posted by SphinCorp
Dim instance As Dictionary(Of TKey, TValue)
gives error "type tkey, tvalue not declared"
(btw, this IS a console app)
Of course it gives an error. TKey and TValue only refer to the type of key and type of value. Directly from the link above:
Code:
Type Parameters
TKey
The type of the keys in the dictionary.
TValue
The type of the values in the dictionary.
So, you want Strings for your keys and values. Look at the example on MSDN. It shows exactly how to do this.
-
Apr 13th, 2008, 12:17 PM
#15
Thread Starter
Junior Member
Re: Simple question
O.o I admit... I am the world's biggest array/dictionary noob. I cannot unstand anything in the link. Please simplify...
sorry for my noobiness,
SphinCorp
-
Apr 13th, 2008, 12:21 PM
#16
Thread Starter
Junior Member
Re: Simple question
fixed. 
Dim instance As New SortedDictionary(Of String, String)
' Add items to the dictionary
instance.Add("Main", "C:\windows\system32")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|