r/visualbasic • u/Engagethedawn VB.Net Beginner • Dec 04 '16
[vb2015] Arrays
Good day everyone,
I am working a multidimensional array but for some reason I cannot get the array to display all 20 (4x5) of its items into a textbox.
So far I have this...which displays the first line respectively.
Dim Rate(,) As Double = {{1, 1.5, 1.65, 1.85}, {1.58, 2, 2.4, 3.05}, {1.71, 2.52, 3.1, 4},_
2.04, 3.12, 4, 5.01}, {2.52, 3.75, 5.1, 7.25}}
Dim weightindex, zoneindex, output As Double
weightindex = ListBox1.SelectedIndex & " "
zoneindex = ListBox2.SelectedIndex & " "
output = Rate(weightindex, zoneindex)
If output < 3 Then
NRLabel.Text = "$" & (output + output * 0.5).ToString("n2")
ElseIf output >= 3 Then
NRLabel.Text = "$" & (output - output * 0.2).ToString("n2")
End If
For counter = 0 To 3
TextBox2.Text &= "$" & Rate(counter, counter).ToString("n2") & " " & vbnewline
NextI know my loop should run from 0 to 19 but for some reason, this does not work out...I feel like I should make multiple loops but I believe that would defeat the purpose of using a loop to consolidate. Am I missing a nested loop?
The output should look like the pic on the right below (there is also sorting involved...but I'm trying to grasp that concept as well)...thank you for your time.
6
Upvotes
4
u/CtrlShiftAppoint Dec 05 '16 edited Dec 05 '16
You're gonna need 2 loops, this really shouldn't cost that much since the values are so small: