Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27355

[RESOLVED] If statement out of range exception

$
0
0
I'm getting this weird issue that doesn't make sense to me. I'm trying to use a for value to cycle through different query statements and place these values into an array (tx1val). I have query statements defined for each n value, but when I run this code:

For n = 1 To 6 Step 1

query.Connection = conn
query.CommandText = queryString(n)
queryResults = query.ExecuteReader
queryResults.Read()
'every pass stores one value. pass order is :LO (tx1,tx2) MID (tx1,tx2) HI (tx1,tx2)
If n = 1 Then tx1Val(txdBm, 0) = queryResults.GetInt32(0)
If n = 2 Then tx2Val(txdBm, 0) = queryResults.GetInt32(0)
If n = 3 Then tx1Val(txdBm, 1) = queryResults.GetInt32(0)
If n = 4 Then tx2Val(txdBm, 1) = queryResults.GetInt32(0)
If n = 5 Then tx1Val(txdBm, 2) = queryResults.GetInt32(0)
If n = 6 Then tx2Val(txdBm, 2) = queryResults.GetInt32(0)

queryResults.Close()
query.Dispose()

Next

I get an error on the If n = 2 line, saying:

An unhandled exception of type 'System.IndexOutOfRangeException' occurred in dbConnection.exe

Additional information: Index was outside the bounds of the array

what do you think the problem is?

Viewing all articles
Browse latest Browse all 27355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>