将基于值的字符从标签插入另一个标签 [英] Insert Character based of value from label into another label

查看:84
本文介绍了将基于值的字符从标签插入另一个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vs2015.我正在尝试查看标签中的值,并基于该值我想在其他标签中输入字符.  它是基于范围的.

这是我的代码:

如果Val(lblTotalMileage.Text)< ="100",然后

           lblShipZone.Text ="A";

       ElseIf Val(lblTotalMileage.Text)> "100"或者
Val(lblTotalMileage.Text)< ="200"然后

           lblShipZone.Text ="B";

       ElseIf Val(lblTotalMileage.Text)> " 200"或者
Val(lblTotalMileage.Text)< ="300"然后

           lblShipZone.Text ="C";

       ElseIf Val(lblTotalMileage.Text)> " 300"或者
Val(lblTotalMileage.Text)< ="400"然后

           lblShipZone.Text ="D";

       ElseIf Val(lblTotalMileage.Text)> " 400"或者
Val(lblTotalMileage.Text)< ="500"然后

           lblShipZone.Text ="E";

       ElseIf Val(lblTotalMileage.Text)> " 500"或者
Val(lblTotalMileage.Text)< ="600"然后

           lblShipZone.Text ="D";

       ElseIf Val(lblTotalMileage.Text)> "600"或者
Val(lblTotalMileage.Text)< ="700"然后

           lblShipZone.Text ="E";

       ElseIf Val(lblTotalMileage.Text)> "700"然后

           lblShipZone.Text ="F";

      如果结束

解决方案

应该是此 如果Val(lblTotalMileage.Text)< = 100 (因为您不比较字符串),则您应该在此实例中比较数字,特别是双精度类型.

以及使用And或AndAnd ElseIf Val(lblTotalMileage.Text)> 100 AndAlso Val(lblTotalMileage.Text)< = 200然后 而不是Or .

您还应该在代码窗口的顶部放置Option Strict On,然后在没有正确提供类型转换或在比较中使用不正确的类型的地方看到大量错误.

如果要使用用于数学类型功能的数字类型,则在尝试将其用于数学类型功能之前,不需要使用字符串类型或将字符串类型转换为适当的数字类型.


I am using vs 2015.  I am trying to look at a value in a label and based off that value I want to enter a character in a different label.  It is based of a range.

Here is my code:

If Val(lblTotalMileage.Text) <= "100" Then

            lblShipZone.Text = "A"

        ElseIf Val(lblTotalMileage.Text) > "100" Or
Val(lblTotalMileage.Text) <= "200" Then

            lblShipZone.Text = "B"

        ElseIf Val(lblTotalMileage.Text) > "200" Or
Val(lblTotalMileage.Text) <= "300" Then

            lblShipZone.Text = "C"

        ElseIf Val(lblTotalMileage.Text) > "300" Or
Val(lblTotalMileage.Text) <= "400" Then

            lblShipZone.Text = "D"

        ElseIf Val(lblTotalMileage.Text) > "400" Or
Val(lblTotalMileage.Text) <= "500" Then

            lblShipZone.Text = "E"

        ElseIf Val(lblTotalMileage.Text) > "500" Or
Val(lblTotalMileage.Text) <= "600" Then

            lblShipZone.Text = "D"

        ElseIf Val(lblTotalMileage.Text) > "600" Or
Val(lblTotalMileage.Text) <= "700" Then

            lblShipZone.Text = "E"

        ElseIf Val(lblTotalMileage.Text) > "700" Then

            lblShipZone.Text = "F"

        End If

解决方案

Val returns a Double value for a string provided and your code is then comparing a double value to a different type which is a string.

This If Val(lblTotalMileage.Text) <= "100" should be this If Val(lblTotalMileage.Text) <= 100 as you are not comparing strings you should be comparing numerics and specifically double types in this instance.

As well use And or AndAlso ElseIf Val(lblTotalMileage.Text) > 100 AndAlso Val(lblTotalMileage.Text) <= 200 Then rather than Or.

You also should place Option Strict On at the top of your code window and then you should see numerous errors where you are not providing type conversions properly or where you are using improper types in comparisons.

If you want to work with numeric types for math type capabilities then you need to not use string types or else convert string types to appropriate numeric types prior to attempting to use them for math type capabilities.


这篇关于将基于值的字符从标签插入另一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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