Results 1 to 5 of 5

Thread: [RESOLVED] Array Help

  1. #1

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Resolved [RESOLVED] Array Help

    i just want to assign all value that i inputed in "Inputbox" to my labels ....
    i have 10 labels

    Code:
    Dim type(10) As Array
    Dim sum, ctr As Integer
    
    sum = 0
    
    For ctr = 0 To 9
    type(ctr) = InputBox ((ctr + 1) & " : " &"Enter a digit!")
    sum = sum + type(ctr)
    next ctr
    
    
    lblAnswer.Text = sum
    lbl1.Text = type(ctr)
    lbl2.Text = type(ctr)
    lbl3.Text = type(ctr)
    lbl4.Text = type(ctr)
    lbl5.Text = type(ctr)
    lbl6.Text = type(ctr)
    lbl7.Text = type(ctr)
    lbl8.Text = type(ctr)
    lbl9.Text = type(ctr)
    lbl10.Text = type(ctr)
    i want to display all 10 numbers i inputed in my "InputBox" to all my labels help pls

  2. #2
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461

    Re: Array Help

    There are many ways to obtain what you need.
    A very simple one and similar to yours could be:

    Dim type(9) As String 'Array index start from 0 and you should use a string type
    Dim sum, ctr As Integer

    sum = 0

    For ctr = 0 To 9
    type(ctr) = InputBox ((ctr + 1).tostring & " : " &"Enter a digit!")
    sum = sum + convert.toint32(type(ctr))
    next ctr


    lblAnswer.Text = sum.tostring
    lbl1.Text = type(0)
    lbl2.Text = type(1)
    lbl3.Text = type(2)
    lbl4.Text = type(3)
    lbl5.Text = type(4)
    lbl6.Text = type(5)
    lbl7.Text = type(6)
    lbl8.Text = type(7)
    lbl9.Text = type(8)
    lbl10.Text = type(9)


    Anyway this is only a rough example. There are many other better ways to reach similar result.
    You should have a better view of vb.net's type (integer, string, etc...) and not confuse them.
    Good job!
    Live long and prosper (Mr. Spock)

  3. #3

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Re: Array Help

    Ah well what a mess for me i forgot this again .... thank you for your reply and remembering this method .... type(0) ... type(9) .... ^^ .... thank you

    [P.S]
    what do you mean about "toInt32" ? and i also saw "toInt16" ? what about that ?

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

    Re: Array Help

    ToInt32 converts to an Int32, which is a 32-bit integer, which is an Integer in VB.NET terms.

    ToInt16 converts to an Int16, which is a 16-bit integer, which is a Short in VB.NET terms.

    There is also ToInt64, Int64 and Long.

    If you have a tendency to forget that you are supposed to specify the upper bound of an array rather than the length then you should use the long-hand syntax:
    vb Code:
    1. Dim type(0 To 9) As String
    Also, I'd like to point out that this:
    vb Code:
    1. Dim type(10) As Array
    is not just creating an Array object. It is creating an array of Array object. It's creating an array that can store 11 Array objects to be precise.
    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

  5. #5

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Re: Array Help

    thank you sir ....

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