如何在同一文本框VB 2010中分隔和添加两个值 [英] How to separate and add two values in same Text box VB 2010

查看:117
本文介绍了如何在同一文本框VB 2010中分隔和添加两个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,如果输入这样的值示例



99那么在第二个文本框中它应该是9 + 9 = 18输出



如何以visual basic格式实现此逻辑请帮助我

I Have one text box in that if enter an value example like this

"99" then in second text box it should come as "9+9"=18 output

How can i implement this logic in visual basic form please help me

推荐答案

您好,



首先,您需要正确标记问题以识别您正在使用的技术。



正如您在问题中所述,它是VB项目,因此您可以使用文本框的Key Up事件来获取价值和处理。希望你知道如何编写代码来添加9 + 9并在下一个文本框中设置。



祝你好运
Hi,

First of all, you need to tag question properly to identify technology you are using.

As you stated in your question, it''s VB project so you can use Key Up event of textbox to get value and process on it. hope you have idea how to write code to add 9+9 and set in the next text box.

best luck


因为这听起来很像你的作业,我不会给你任何代码!



但这并不困难:



1)创建一个total变量来保存结果。将它设置为零。

2)循环输入字符串中的每个字符 - For Each循环将非常容易地完成。

2.1)检查字符是否为数字即''0''到''9''

2.2)如果是,请将其转换为数值,然后将其添加到总数中

2.3)如果它不是,要么忽略它,要么报告问题并退出方法 - 你的选择。

3)循环之后,将第二个文本框的Text属性设置为total,使用ToString方法。
Since this sounds a LOT like you homework, I won''t give you any code!

But it isn''t difficult at all:

1) Create a "total" variable to hold the result. Set it to zero.
2) Loop though each character in the input string - a For Each loop will do that very easily.
2.1) Check if the character is a digit i.e. ''0'' to ''9''
2.2) If it is, convert it to a numeric value, and add it to your total
2.3) If it isn''t, either ignore it, or report the problem and exit the method - your choice.
3) After the loop, set the Text property of teh second text box to the total, using the ToString method.


Dim i As Integer = 0
For Each digit In (TextBox1.Text)
           i += Val(digit)
       Next
       TextBox2.Text = i.ToString


这篇关于如何在同一文本框VB 2010中分隔和添加两个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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