将文本框文本从表单传递给模块 [英] passing textbox text to module from form

查看:28
本文介绍了将文本框文本从表单传递给模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序从 vb6 迁移到 vb.net.

I have an application migrated from vb6 to vb.net.

我想在模块的 SearchFields 中访问 textbox1 的文本.

I want to access the text of textbox1 in SearchFields of module.

我不想将它作为参数传递,因为我要传递的控件太多了.

I do not want to pass it as a parameter because I have so many controls to pass.

请举例说明.

我的代码是frmNew page有Textbox1

My code is frmNew page have Textbox1

Private Sub Ok_Click(.....)
   call SearchFields()
   Me.Close()
End Sub

在模块内部我有下面的方法

Inside module I have method below

Sub SearchFields()
    Dim str As string
    Dim frm As New frmNew
    str = frm.Textbox1.Text
End Sub

frmNew.Textbox1.Text 一无所获

frmNew.Textbox1.Text is getting nothing

推荐答案

为了尽可能少地重新编码,您可以将两种方法更改为以下内容.为此,必须将 Textbox1 标记为 public.正如@LarsTech 指出的那样,我个人不得不将 VB6 应用程序迁移"到 .Net,这需要重新考虑您的应用程序,而不仅仅是语法更改.

To do as little recoding as possible, you can change your two methods to the following. For this to work Textbox1 must be marked public. I have personally had to "migrate" VB6 apps to .Net, as @LarsTech pointed out, this requires rethinking of your app, not just syntax changes.

Private Sub Ok_Click(.....)
   call SearchFields(Me)
   Me.Close()
End Sub

Sub SearchFields(Form frm)
    Dim str As string

    str = frm.Textbox1.Text
End Sub

这篇关于将文本框文本从表单传递给模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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