VB.net代码中的“System.InvalidCastException” [英] 'System.InvalidCastException' in VB.net code

查看:327
本文介绍了VB.net代码中的“System.InvalidCastException”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这段代码中,错误是暂停程序其余部分的执行,错误如下:

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



代码snipet:


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



我想知道如何解决这个问题,任何帮助将不胜感激,谢谢



-Jordan


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

-Jordan

推荐答案

If Key1 AndAlso (nMap(0, Count) = 0) Then
    nMap(0, Count) = 1
ElseIf Key1 Then
    nMap(0, Count) = 0
End If


你没有告诉我们nMap是什么,或者哪个行有错误。你甚至不能告诉我们Count Is。但是,显然你正在使用系统试图为你投射的东西,因为你没有做任何演员,我会说Count是最有可能的竞争者。所以,给我们更多的信息,或者弄清楚为什么这个代码中的某些东西的值被隐式地转换,并且失败
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


这篇关于VB.net代码中的“System.InvalidCastException”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆