Click here to Skip to main content
12,819,402 members (28,981 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB 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

Posted 1-Jan-13 18:44pm
Updated 1-Jan-13 18:46pm
Rate this: bad
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
Kschuler 10-Jan-13 15:34pm
You got my 5. You could have taken it a bit further to explain that in you use the keywords "AndAlso" and "OrElse" and that the & character is used to concat strings.
Rate this: bad
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
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2017
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