需要帮助转换这些,我不明白为什么会发生错误. [英] Need help converting these, i dont understand why a error is happening.

查看:82
本文介绍了需要帮助转换这些,我不明白为什么会发生错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我在转换和遇到多个错误时遇到了所有问题,我尝试了许多转换方法,但均无济于事.请看一下我是否做错了什么!

Hey all I am having a issue with converting and getting multiple errors i have tried numerous convert methods but to no avail. Please take a look and see if im doing something terribly wrong!

 Dim strInput As String = "" 'storing the input ID

        Dim fulltime As Integer ' storing values
        Dim parttime As Integer
        Dim newcar As Integer
        Dim usedcar As Integer

        strInput = txtid.Text.ToUpper() ' changes to uppercase
        ' sets the focus 
        txtid.Focus()




        If strInput Like "###NF" Then 'For new and fulltime
            newcar = CInt(txtnew.Text)
            txtnew.Text = Convert.ToString(newcar) + txtnumsold.Text 'stores value into newcar
            fulltime = Convert.ToInt32(txtfulltime.Text)
            txtfulltime.Text = Convert.ToString(fulltime) + txtnumsold.Text 'stores value into full time

        ElseIf strInput Like "###UF" Then
            usedcar = CInt(txtused.Text)
            txtused.Text = Convert.ToString(usedcar) + txtnumsold.Text
            fulltime = Convert.ToInt32(txtfulltime.Text)
            txtfulltime.Text = Convert.ToString(fulltime) + txtnumsold.Text
        ElseIf strInput Like "###NP" Then
            newcar = CInt(txtnew.Text)
            txtnew.Text = Convert.ToString(newcar) + txtnumsold.Text
            parttime = Convert.ToInt32(txtparttime.Text)
            txtparttime.Text = Convert.ToString(parttime) + txtnumsold.Text
        ElseIf strInput Like "###UP" Then
            usedcar = CInt(txtused.Text)
        txtused.Text = Convert.ToString(usedcar) + (txtnumsold.Text)
        parttime = Convert.ToInt32(txtparttime.Text)
        txtparttime.Text = Convert.ToString(parttime) + txtnumsold.Text
        End If


推荐答案

如果字符串仅包含数字字符,则需要首先进行测试.

if a string contains only numeric characters is something you've to test first. 

但是,使用Select大小写来创建代码甚至比这种难以阅读的代码更加简单.

However, it is even more simple to create your code with Select case instead of this difficult to read code. 

https://msdn.microsoft.com/en-us/library/cy37t14y.aspx

要检查数字是否为数字,可以使用VB IsNumeric函数

To check if something is numeric you can use the VB IsNumeric function

https://msdn.microsoft.com /en-us/library/6cd3f6w1(v=vs.90).aspx  (未维护,它什么也没说,也位于其他地方)

https://msdn.microsoft.com/en-us/library/6cd3f6w1(v=vs.90).aspx (that it is not maintained says nothing, it is also somewhere else)

或者您可以使用在2.0中添加到.Net的trycast函数,因为C#中没有合适的方法

or you can use the trycast functions which was added to .Net in 2.0 because there was no decent way in C#

https://msdn.microsoft.com/en-us/library/zyy863x8.aspx


这篇关于需要帮助转换这些,我不明白为什么会发生错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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