I have a form with 5 controls.

For textbox I am accesing like frmNote.txtNumber.Text.

When I am accessing this property directly from form frmNote then I am getting the value of textbox.

But when I created a method for example NewMethod() in different vb file and call this method from frmNote form button click event then I am not able to access frmNote.txtNumber.Text value over there inside method.

It is coming blank. Do I need to pass all control values to method from form or is there any other way around.

有帮助吗?

解决方案

Because txtNumber isn't shared, you can't access it from other class. You must pass it's value to NewMethod. Code will look like this:

Public Sub NewMethod(text as String)
    'Use text
End Sub

And calling NewMethod:

NewMethod(txtNumber.Text)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top