hi i am using vb.net multidimensional arrays and i am getting the nearest or closest number i just want to ask if my code was correct or not ? for example i have an input of 13000 and nearest number should be on col 6 can you please help me regarding this ? this is for our school activity.....thank you in advance

 Private Sub ComboBox5_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox5.SelectedIndexChanged

    If ComboBox5.Text = "Z" Then
        Dim zero(3, 8) As Double
        Dim row As Double
        Dim total As Double

        Dim col As Double

        'col 1
        zero(0, 0) = 0.0
        zero(1, 0) = 0
        zero(2, 0) = 1

        'col 2
        zero(0, 1) = 0.0
        zero(1, 1) = 0.05
        zero(2, 1) = 0

        'col 3
        zero(0, 2) = 41.67
        zero(1, 2) = 0.1
        zero(2, 2) = 833

        'col 4
        zero(0, 3) = 208.33
        zero(1, 3) = 0.15
        zero(2, 3) = 2500

        'col 5
        zero(0, 4) = 708.33
        zero(1, 4) = 0.2
        zero(2, 4) = 5833

        'col 6
        zero(0, 5) = 1875.0
        zero(1, 5) = 0.25
        zero(2, 5) = 11667

        'col 7
        zero(0, 6) = 4166.67
        zero(1, 6) = 0.3
        zero(2, 6) = 20833

        'col 8
        zero(0, 7) = 10416.67
        zero(1, 7) = 0.32
        zero(2, 7) = 41667

        For row = 0 To 3
            For col = 0 To 8

                If Val(TextBox18.Text) > Val(zero(row, col)) And Val(TextBox18.Text) < Val(zero(row, col)) Then
                    ListView1.Items.Add(total = (Val(TextBox18.Text) - Val(zero(row, col))))
                End If
            Next
        Next

    End If

End Sub

I would venture that your problem is here:

If Val(TextBox18.Text) > Val(zero(row, col)) And Val(TextBox18.Text) < Val(zero(row, col)) Then
    ListView1.Items.Add(total = (Val(TextBox18.Text) - Val(zero(row, col))))
End If

You're testing if one value is greater than and less than another value at the same time. This is impossible and will never be true.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.