我的添加代码在计算器中不起作用 [英] my adding code does not work in calculator

查看:87
本文介绍了我的添加代码在计算器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是

my code is

 Num1 = Val(TextBox1.Text)
        TextBox1.Clear()
        Arithmetic = "+"
'btnEqual click is
 Num2 = Val(TextBox1.Text)
        If Arithmetic = "+" Then
            Answer = Num1 + Num2
textbox1.text=Answer

推荐答案





试试这个



答案= val(Num1 + Num2);



默认情况下,字符串连接发生在你的情况下。所以上面的代码可能适合你。

希望这对你有所帮助。



问候,

RK
Hi,

Try this

Answer = val(Num1 + Num2);

By default string concatenation is happening in your case.So the above code might work for you.
Hope this helps you a bit.

Regards,
RK


既然你把它标记为ASP.NET,我会假设这个是网站代码。

在这种情况下,不会不会那样。在运行之间不保留变量值,它们在页面加载(或回发处理)完成时被销毁。



如果要保留值,则需要查看将总数存储在Cookie(在客户端上)或会话(在服务器上)并在开始工作之前检索它。

Cookies [ ^ ]



保存在会话中 [ ^ ]

从会议中读取 [ ^ ]



BTW:您确实意识到在代码隐藏中进行所有数学运算会产生一个相当慢的计算器,不是吗?
Since you are tagging this as ASP.NET, I will assume this is website code.
In which case, no it won't work like that. Variable values are not preserved between runs, they are destroyed when the page load (or postback processing) is completed.

If you want to preserve a value, you need to look at either storing the total in a Cookie (on the client) or the Session (on the server) and retrieving it before you start working.
Cookies[^]

Save in Session[^]
Read from Session[^]

BTW: You do realise that doing all your math operations in the codebehind will create a rather slow calculator, don't you?


只需

获取两个变量或文本框

例如: -

初始化值

Z = x + y





Res = Val(txt1.text)+ Val(txt2.text)
just
Get a two variable or text box
For eg:-
initialize values
Z=x+y
or

Res=Val(txt1.text)+Val(txt2.text)


这篇关于我的添加代码在计算器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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