-
Mar 17th, 2018, 06:24 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to make Array list in vb net
Hello VBForums
Hello evey one
Please ..
I tried a lot with this code but not results
It works very well in vb6 but in vb net I did not succeed
Please how to make ..
When i choose 1 in ComboBox 1 will automatically appears 50 in TextBox1
When i choose 2 in ComboBox 1 will automatically appears 100 in TextBox1
When i choose 3 in ComboBox 1 will automatically appears 150 in TextBox1
And so on
Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For AAA = 1 To 10
ComboBox1.Items.Add(AAA)
Next AAA
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim Array(9) As Integer
TextBox1.Text = Array("50 , 100 , 150 , 200, 250, 300, 350, 400, 450, 500)(ComboBox1.SelectedIndex)
End Sub
End Class
Cordially
MADA
-
Mar 17th, 2018, 07:14 PM
#2
Re: How to make Array list in vb net
You were close. You wanted something more like this:
Dim myArray() As Integer = {50,100,150,200,250,300,350,400,450,500}
Then:
Textbox1.Text= myArray(Combobox1.SelectedIndex).ToString
However, this is far from ideal in several different ways. For one thing, the array is re-created every time the selected index changes. It would be far better to have the array declared at form scope rather than inside the event handler as you have it.
Another point is that the array isn't actually necessary, because you could just do this:
TextBox1.Text = (50 * (ComboBox1.SelectedIndex+1)).ToString
Though, the array would actually be faster than that equation, so using the array isn't bad.
Another option would be to create a Dictionary(of Integer,Integer) rather than using an array. This could tie the selected index to a value more directly.
My usual boring signature: Nothing
-
Mar 18th, 2018, 06:17 AM
#3
Thread Starter
Hyperactive Member
Re: How to make Array list in vb net
Thank you very much Shaggy Hiker
Thank you for your lesson and for your impeccable solution
Very nice of you
Now it works very very well
I only have one last problem
I choose CATEGORY by ComboBox1
and the result will be displayed in TextBox1
it's done very well by your super intervention .. thank you master
Now ..
Always choose the CATEGORY at the beginning by ComboBox1 ..then
I choose TYPE by ComboBox2 ..
If ComboBox1 = 1 and ComboBox2 = 1 Then TextBox2 = 10
If ComboBox1 = 1 and ComboBox2 = 2 Then TextBox2 = 20
If ComboBox1 = 1 and ComboBox2 = 3 Then TextBox2 = 30
If ComboBox1 = 1 and ComboBox2 = 4 Then TextBox2 = 40
If ComboBox1 = 1 and ComboBox2 = 5 Then TextBox2 = 50
If ComboBox1 = 2 and ComboBox2 = 1 Then TextBox2 = 100
If ComboBox1 = 2 and ComboBox2 = 2 Then TextBox2 = 200
If ComboBox1 = 2 and ComboBox2 = 3 Then TextBox2 = 300
If ComboBox1 = 2 and ComboBox2 = 4 Then TextBox2 = 400
If ComboBox1 = 2 and ComboBox2 = 5 Then TextBox2 = 500
If ComboBox1 = 3 and ComboBox2 = 1 Then TextBox2 = 1000
If ComboBox1 = 3 and ComboBox2 = 2 Then TextBox2 = 2000
If ComboBox1 = 3 and ComboBox2 = 3 Then TextBox2 = 3000
If ComboBox1 = 3 and ComboBox2 = 4 Then TextBox2 = 4000
If ComboBox1 = 3 and ComboBox2 = 5 Then TextBox2 = 5000
If ComboBox1 = 4 and ComboBox2 = 1 Then TextBox2 = 10000
If ComboBox1 = 4 and ComboBox2 = 2 Then TextBox2 = 20000
If ComboBox1 = 4 and ComboBox2 = 3 Then TextBox2 = 30000
If ComboBox1 = 4 and ComboBox2 = 4 Then TextBox2 = 40000
If ComboBox1 = 4 and ComboBox2 = 5 Then TextBox2 = 50000
If ComboBox1 = 5 and ComboBox2 = 1 Then TextBox2 = 100000
If ComboBox1 = 5 and ComboBox2 = 2 Then TextBox2 = 200000
If ComboBox1 = 5 and ComboBox2 = 3 Then TextBox2 = 300000
If ComboBox1 = 5 and ComboBox2 = 4 Then TextBox2 = 400000
If ComboBox1 = 5 and ComboBox2 = 5 Then TextBox2 = 500000
If ComboBox1 = 6 and ComboBox2 = 1 Then TextBox2 = 1000000
If ComboBox1 = 6 and ComboBox2 = 2 Then TextBox2 = 2000000
If ComboBox1 = 6 and ComboBox2 = 3 Then TextBox2 = 3000000
If ComboBox1 = 6 and ComboBox2 = 4 Then TextBox2 = 4000000
If ComboBox1 = 6 and ComboBox2 = 5 Then TextBox2 = 5000000
If ComboBox1 = 7 and ComboBox2 = 1 Then TextBox2 = 10000000
If ComboBox1 = 7 and ComboBox2 = 2 Then TextBox2 = 20000000
If ComboBox1 = 7 and ComboBox2 = 3 Then TextBox2 = 30000000
If ComboBox1 = 7 and ComboBox2 = 4 Then TextBox2 = 40000000
If ComboBox1 = 7 and ComboBox2 = 5 Then TextBox2 = 50000000
If ComboBox1 = 8 and ComboBox2 = 1 Then TextBox2 = 100000000
If ComboBox1 = 8 and ComboBox2 = 2 Then TextBox2 = 200000000
If ComboBox1 = 8 and ComboBox2 = 3 Then TextBox2 = 300000000
If ComboBox1 = 8 and ComboBox2 = 4 Then TextBox2 = 400000000
If ComboBox1 = 8 and ComboBox2 = 5 Then TextBox2 = 500000000
If ComboBox1 = 9 and ComboBox2 = 1 Then TextBox2 = 1000000000
If ComboBox1 = 9 and ComboBox2 = 2 Then TextBox2 = 2000000000
If ComboBox1 = 9 and ComboBox2 = 3 Then TextBox2 = 3000000000
If ComboBox1 = 9 and ComboBox2 = 4 Then TextBox2 = 4000000000
If ComboBox1 = 9 and ComboBox2 = 5 Then TextBox2 = 5000000000
If ComboBox1 = 10 and ComboBox2 = 1 Then TextBox2 = 10000000000
If ComboBox1 = 10 and ComboBox2 = 2 Then TextBox2 = 20000000000
If ComboBox1 = 10 and ComboBox2 = 3 Then TextBox2 = 30000000000
If ComboBox1 = 10 and ComboBox2 = 4 Then TextBox2 = 40000000000
If ComboBox1 = 10 and ComboBox2 = 5 Then TextBox2 = 50000000000
I try like this but i have an error in all word " Array "
Code:
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim MADA(10)
If TextBox1.Text = "" Then
MsgBox("Choose First and Foremost the CATEGORY by ComboBox1", vbExclamation, "WARNING")
ComboBox2.Text = ""
ComboBox1.Focus()
Exit Sub
End If
MADA(0) = Array{10, 20, 30, 40, 50}
MADA(1) = Array{100, 200, 300, 400, 500}
MADA(2) = Array{1000, 2000, 3000, 4000, 5000}
MADA(3) = Array{10000, 20000, 30000, 40000, 50000}
MADA(4) = Array{100000, 200000, 300000, 400000, 500000}
MADA(5) = Array{1000000, 2000000, 3000000, 4000000, 5000000}
MADA(6) = Array{10000000, 20000000, 30000000, 40000000, 50000000}
MADA(7) = Array{100000000, 200000000, 300000000, 400000000, 500000000}
MADA(8) = Array{1000000000, 2000000000, 3000000000, 4000000000, 5000000000}
MADA(9) = Array{10000000000, 20000000000, 30000000000, 40000000000, 50000000000}
TextBox2.Text = MADA(ComboBox1.SelectedIndex)(ComboBox2.SelectedIndex).ToString
End Sub
Thank you for all
Cordially
MADA
Last edited by MADA BLACK; Mar 18th, 2018 at 06:26 AM.
-
Mar 18th, 2018, 06:39 AM
#4
Re: How to make Array list in vb net
It looks like you're trying to create an array of arrays of Long, perhaps?
Change your declaration to be an array of arrays MADA(9)(), then use the array literal format {,,} to set them.
Code:
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim MADA(9)() As Long
If TextBox1.Text = "" Then
MsgBox("Choose First and Foremost the CATEGORY by ComboBox1", vbExclamation, "WARNING")
ComboBox2.Text = ""
ComboBox1.Focus()
Exit Sub
End If
MADA(0) = {10, 20, 30, 40, 50}
MADA(1) = {100, 200, 300, 400, 500}
MADA(2) = {1000, 2000, 3000, 4000, 5000}
MADA(3) = {10000, 20000, 30000, 40000, 50000}
MADA(4) = {100000, 200000, 300000, 400000, 500000}
MADA(5) = {1000000, 2000000, 3000000, 4000000, 5000000}
MADA(6) = {10000000, 20000000, 30000000, 40000000, 50000000}
MADA(7) = {100000000, 200000000, 300000000, 400000000, 500000000}
MADA(8) = {1000000000, 2000000000, 3000000000, 4000000000, 5000000000}
MADA(9) = {10000000000, 20000000000, 30000000000, 40000000000, 50000000000}
TextBox2.Text = MADA(ComboBox1.SelectedIndex)(ComboBox2.SelectedIndex).ToString
End Sub
-
Mar 18th, 2018, 07:02 AM
#5
Thread Starter
Hyperactive Member
Re: How to make Array list in vb net
Thank you passel
Thank you very much Gentelman
It's really what I want to see and have
Very nice of you
Perfectly resolved
It works very very well
Cordially
MADA
-
Mar 18th, 2018, 07:03 AM
#6
Re: How to make Array list in vb net
If you happen to have numbers in the combo boxes, rather than some other meaningful text representing category and type, then you could calculate the resulting number based on two input numbers, and using a numeric up/down input for the numbers could be less code.
For example, add an updown control with a minimum property of 1 and a maximum property of 10, representing category, and a second going from 1 to 5 representing type, and you could use code like this.
Code:
Private Sub NumericUpDown1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles NumericUpDown1.ValueChanged,
NumericUpDown2.ValueChanged
TextBox2.Text = (10 ^ NumericUpDown1.Value * NumericUpDown2.Value).ToString
End Sub
-
Mar 18th, 2018, 07:18 AM
#7
Thread Starter
Hyperactive Member
Re: [RESOLVED] How to make Array list in vb net
A new and useful lesson
I will try it on my form
It seems that it will be more simple and practical
Another time thank you very much
Very nice of you
Cordially
MADA
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
|