我想将两个文本框添加在一起 [英] I want to add two textboxes together

查看:38
本文介绍了我想将两个文本框添加在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个文本框和一个标签.

I have 2 text boxes and a label.

我希望能够在标签中显示两个文本框的连接文本.我使用了以下代码:

I want to be able to display in a label the concatenated text of the two textboxes. I have used the following code:

Private Sub CommandButton1_Click()

    Label1.Text = Val(TextBox1.Text) + Val(TextBox2.Text)  

End Sub

然而,这不起作用,我得到了

This doesn't work, however, and I am getting

编译错误:未找到方法或数据成员

Compile error: Method or data member not found

有人可以解释一下为什么会发生这种情况以及我该如何解决吗?

Can somebody explain why this is happening and how I can fix it, please?

推荐答案

在启用宏的 excel 文件中,添加 activeX 版本的命令按钮、文本框和标签.

In a Macro enabled excel file, add the activeX version of command button, text boxes and label.

在此之后,您可以使用此代码获得所需的结果:

After this you can have your desired result with this code:

Private Sub CommandButton1_Click()
Label1.Caption = TextBox1.Text & TextBox2.Text
End Sub

请检查宏是否正确保存.此解决方案适用于 Excel 2013.

Please check that the macros are saved correctly. This solution works on Excel 2013.

这篇关于我想将两个文本框添加在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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