从字符串“"转换输入“Double”无效。 [英] Conversion from string "" to type 'Double' is not valid.'

查看:115
本文介绍了从字符串“"转换输入“Double”无效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我用过这些代码..

 Function Check_Acc_Cash() As Boolean
        Check_Acc_Cash = False

        Dim Z As VariantType
        Dim N1 As VariantType


        Z = 0


        N1 = Double.Parse(0581115201).ToString("000000000000000")

        Z = Z + Mid(N1, 1, 1) * 13
        Z = Z + Mid(N1, 2, 1) * 12
        Z = Z + Mid(N1, 3, 1) * 11
        Z = Z + Mid(N1, 4, 1) * 10
        Z = Z + Mid(N1, 5, 1) * 9
        Z = Z + Mid(N1, 6, 1) * 1
        Z = Z + Mid(N1, 7, 1) * 2
        Z = Z + Mid(N1, 8, 1) * 3
        Z = Z + Mid(N1, 9, 1) * 4
        Z = Z + Mid(N1, 10, 1) * 5
        Z = Z + Mid(N1, 11, 1) * 6
        Z = Z + Mid(N1, 12, 1) * 7
        Z = Z + Mid(N1, 13, 1) * 8

        If Z Mod 99 = Val(Mid(N1, 14, 2)) Then
            Check_Acc_Cash = True
        Else
            Check_Acc_Cash = False
        End If


    End Function

但我看到这个错误......

but i see this error...

如何解决?

真主的名字,最仁慈,最仁慈,他创造了人类

Name of Allah, Most Gracious, Most Merciful and He created the human

推荐答案

要做的第一件事是,在类或代码模块或表单的顶部写下来是放置以下行

The first thing to do is, at the top of the class or code module or form this is written in is to place the following line

Option Strict On

Option Strict On

Mid函数用于字符串,同时执行字符串和数字操作,如您所见,这是一个问题。您可以使用CDbl包装Mid,或者如果Mid的值有可能返回非double值,请使用Double.TryParse将字符串
值转换为Double。

Mid function is for strings while you are doing both string and number operations which as you can see is a problem. You can wrap Mid with CDbl or if there is a chance the value of Mid returns a non double value use Double.TryParse to convert the string value to a Double.

,这些类型不适用于VB.NET,即使它们在.NET Framework中,一切都应该被正确声明,例如如果我们处理Double而不是将该项声明为Double,而不是VariantType。

Also, these types are not for VB.NET even thou they are in the .NET Framework, everything should be declared properly e.g. if we are dealing with a Double than declare the item as a Double, not VariantType.

所以,如果不是VB.NET你会使用
以下论坛

So if by chance this is not VB.NET you would use the following forum.


这篇关于从字符串“"转换输入“Double”无效。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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