vba 将变量从子级传递给父级,就像函数 VB.NET
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10712741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pass variable From child to parent, Like a Function VB.NET
提问by John Nu?ez
I have created 2 forms (Parent & Child), i want to store the unique textbox value to a variable into the parent form.
我创建了 2 个表单(父和子),我想将唯一的文本框值存储到父表单中的变量中。
Also like this:
也像这样:
Parent Code:
父代码:
dim passed_value = new childform()
passed_value.show()
On close:
关闭时:
refresh passed_value variable using childform textbox value.
使用子表单文本框值刷新passed_value 变量。
回答by Writwick
You can Do the Following to accomplish the Task :
您可以执行以下操作来完成任务:
- Declare a
String
variable in the child form.
String
在子窗体中声明一个变量。
Public value As String
- Use
ShowDialog()
in the Main Form to show the Child form.
- 使用
ShowDialog()
在主窗体显示子窗体。
Dim frm As New Form2
frm.ShowDialog()
- [Set the
value
in your form as per your needs]
- [
value
根据您的需要在您的表格中设置]
value = "New Value"
- Now get the
value
variable from the Child form and set the textbox text according to it.
- 现在
value
从 Child 表单中获取变量并根据它设置文本框文本。
TextBox1.Text = frm.value
回答by Yatrix
I would make it a property and give it the necessary access, which to me looks to be ReadOnly
.
我会将其设为属性并为其提供必要的访问权限,在我看来,它是ReadOnly
.
Private _myValue As DataType
Public ReadOnly Property MyValue() As DataType
Get
Return _myValue
End Get
You could access it as such: myForm.MyValue
.
您可以这样访问它:myForm.MyValue
.