Results 1 to 16 of 16

Thread: Simple question

  1. #1

    Thread Starter
    Junior Member SphinCorp's Avatar
    Join Date
    Apr 2008
    Posts
    19

    Lightbulb 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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: Simple question

    Documentation should always be first. Have a look here and come back with any specific questions you may have.

  4. #4

    Thread Starter
    Junior Member SphinCorp's Avatar
    Join Date
    Apr 2008
    Posts
    19

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

  5. #5

    Thread Starter
    Junior Member SphinCorp's Avatar
    Join Date
    Apr 2008
    Posts
    19

    Re: Simple question

    or can I have an array like :

    variable | Value
    variable | value

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  8. #8

    Thread Starter
    Junior Member SphinCorp's Avatar
    Join Date
    Apr 2008
    Posts
    19

    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\"

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Simple question

    How many elements are in your name and value array? This is meant to be an instructive question.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10

    Thread Starter
    Junior Member SphinCorp's Avatar
    Join Date
    Apr 2008
    Posts
    19

    Re: Simple question

    Would this idea work though if I limited count to 10 and below?

  11. #11
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: Simple question

    Quote 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

  12. #12

    Thread Starter
    Junior Member SphinCorp's Avatar
    Join Date
    Apr 2008
    Posts
    19

    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.

  13. #13

    Thread Starter
    Junior Member SphinCorp's Avatar
    Join Date
    Apr 2008
    Posts
    19

    Re: Simple question

    Dim instance As Dictionary(Of TKey, TValue)
    gives error "type tkey, tvalue not declared"

    (btw, this IS a console app)

  14. #14
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: Simple question

    Quote 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.

  15. #15

    Thread Starter
    Junior Member SphinCorp's Avatar
    Join Date
    Apr 2008
    Posts
    19

    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

  16. #16

    Thread Starter
    Junior Member SphinCorp's Avatar
    Join Date
    Apr 2008
    Posts
    19

    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
  •  



Click Here to Expand Forum to Full Width