如何使用变量获取表单的TextBox控件的值? [英] How do I get the value of a form's TextBox control using a variable?

查看:123
本文介绍了如何使用变量获取表单的TextBox控件的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用变量输入对它的引用来从表单的TextBox控件中获取值。我正在输入模块中的代码。这是我尝试过的,但它不起作用。我得到字符串文本,但不是控件的值。
如何将对象的字符串引用转换为对表单上控件文本框的实际引用?

 Dim TextBoxText As String 
TextBoxText =" frmAddEditAssets.txtProjFed" &安培; YearNumber& "。文本"
DepreciationFed = TextBoxText
frmAddEditAssets.txtDeprFed.Text =格式(DepreciationFed," Standard")

但是,如果我硬连接第二行代码,所以没有YearNumber变量,如下所示,它可以工作:

  TextBoxText = frmAddEditAssets.txtProjFed2.Text  

我做错了什么?感谢您的帮助。


BobV365




BobV365

解决方案

您好


嗯,Form控件,TextBox,需要通过其名称来解决。


例如,Form上的默认TextBox将命名为TextBox1,并且可以按以下方式使用:TextBox的属性"Text"是找到文本的位置。

 Dim myVar1 As String ="我的朋友。" 
TextBox1.Text =" Hello there"
Dim myVar2 As String = TextBox1.Text& "," &安培;你的样本中的myVar1




,确实没有涉及任何TextBox,只是字符串


I am trying to get the value from a form's TextBox control by entering a reference to it using a variable. I am entering the code in a Module. Here is what I have tried, but it isn't working. I get the string text, but not the value of the control. How do I convert the string reference to the control into an actual reference to a control textbox on a form?

Dim TextBoxText As String
TextBoxText = "frmAddEditAssets.txtProjFed" & YearNumber & ".Text"
DepreciationFed = TextBoxText
frmAddEditAssets.txtDeprFed.Text = Format(DepreciationFed, "Standard")

However, if I hardwire the second line of code so there is no YearNumber variable, like below, it works:

TextBoxText = frmAddEditAssets.txtProjFed2.Text

What am I doing wrong? Thank you for help.

BobV365


BobV365

解决方案

Hi

Well, a Form control, a TextBox, needs to be addressed by its name.

For example, a default TextBox on a Form would be named TextBox1, and can be used in the following manner: the Property 'Text' of the TextBox is where the text is found.

    Dim myVar1 As String = "my friend."
    TextBox1.Text = "Hello there"
    Dim myVar2 As String = TextBox1.Text & ", " & myVar1


in your sample, there really isn't any TextBox involved, just strings


这篇关于如何使用变量获取表单的TextBox控件的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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