Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this snipit of code an error is halting the execution of the rest of the program, the error is as follows:
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

The code snipet:
VB
If Key1 = True & nMap(0, Count) = 0 Then
            nMap(0, Count) = 1
        ElseIf Key1 = True Then
            nMap(0, Count) = 0
        End If

I would like to know how to resolve this issue, any help would be appreciated, thank you

-Jordan
Posted
Updated 1-Jan-13 17:46pm
v2

VB
If Key1 AndAlso (nMap(0, Count) = 0) Then
    nMap(0, Count) = 1
ElseIf Key1 Then
    nMap(0, Count) = 0
End If
 
Share this answer
 
Comments
Kschuler 10-Jan-13 15:34pm    
You got my 5. You could have taken it a bit further to explain that in vb.net you use the keywords "AndAlso" and "OrElse" and that the & character is used to concat strings.
You don't tell us what nMap is, or what line has the error. You don't even tell us what Count IS. But, clearly you're using something that the system is trying to cast for you, as you're not doing any casting, and I'd say Count is the most likely contender. So, give us more info, or work out why the value of something in this code is being implicitly cast, and failing
 
Share this answer
 
Comments
Sicppy 2-Jan-13 2:27am    
nMap is an array, Count is a variable used in: for Count as Integer = 0 to 11
Christian Graus 2-Jan-13 2:28am    
Well, the error means in implicit cast is failing, you need to learn to use your debugger, and work out why. OR at least tell us the line that has the error, and what the variables are.
Sicppy 2-Jan-13 2:37am    
it throws the error when running and doesn't tell me what line its on
Sicppy 2-Jan-13 2:50am    
I did some creative debugging and figured out that its on that first line
Sicppy 2-Jan-13 2:51am    
Also I forgot to mention that Key1 is a boolean value getting the current state of the 'A' key

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900