|
-
Apr 14th, 2007, 01:34 AM
#1
Thread Starter
Fanatic Member
[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
-
Apr 14th, 2007, 03:17 AM
#2
Hyperactive Member
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)
-
Apr 14th, 2007, 04:11 AM
#3
Thread Starter
Fanatic Member
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 ?
-
Apr 14th, 2007, 04:24 AM
#4
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:
Dim type(0 To 9) As String
Also, I'd like to point out that this: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.
-
Apr 14th, 2007, 04:57 AM
#5
Thread Starter
Fanatic Member
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
|