Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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:
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 1-Jan-13 18:44pm
Sicppy1.5K
Edited 1-Jan-13 18:46pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If Key1 AndAlso (nMap(0, Count) = 0) Then
    nMap(0, Count) = 1
ElseIf Key1 Then
    nMap(0, Count) = 0
End If
  Permalink  
Comments
Kschuler at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Sicppy at 2-Jan-13 2:27am
   
nMap is an array, Count is a variable used in: for Count as Integer = 0 to 11
Christian Graus at 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 at 2-Jan-13 2:37am
   
it throws the error when running and doesn't tell me what line its on
Sicppy at 2-Jan-13 2:50am
   
I did some creative debugging and figured out that its on that first line
Sicppy at 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)

  Print Answers RSS
0 OriginalGriff 165
1 Sergey Alexandrovich Kryukov 134
2 Sebastiaan Meijerink 131
3 Rana Waqas 110
4 Maciej Los 84
0 Sergey Alexandrovich Kryukov 6,558
1 OriginalGriff 6,288
2 Peter Leow 2,534
3 Abhinav S 2,358
4 Maciej Los 2,352


Advertise | Privacy | Mobile
Web01 | 2.8.150414.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100