Read object from form1 into a class vb.net -


I need to read the content of a text box present in form1. So far I have not had any wrong problems, I have created a function that works perfectly. The problem is now that this function has become very big to keep it in Form 1, so I created a square, which I imported in Form 1. This class was included in the function that was in first form 1, now the compiler gives me this message:

"An non-shared member requires an object reference "

Probably because he can not read the object in Form 1. So I wonder how to use this resource, I tried to import form1 class like this:

  Import App.Form1  

Square of function

  public function export () oSheet.Cells (2, 2) .value = Oggettivo_1_1. Value 'oggettivo_1_1_.value is an object of form1 end function  

But I always get this error, is there anyone who can help me?

Import Typically in a namespace type (Like classrooms) are used to make available. It does not provide an item reference that you have an important part of the error message. Since we do not know how a class has been created here, there is a general way to go about it:

  public class form 1 private myClass as class1 'whatever you make it a sub form_load ... MyClass is named = New Class 1 (m) ... End Sub  

As you have described, it tells that the class is more or less helpful for a form, the class The context of that form is required without and there is no reason for the existence of one A, we use the constructor to pass form references:

  public class 1 as a private myFrm form 1 public sub new (FR form 1) myFrm = frm end sub public function Export () myFrm.oSheet cell (2, 2) .value = ... end function  

Your class can now reference the form using local form references. Since we do not know how your app is ready, this allows the form to reference the reference methods and things in the form in the classroom.

At some point, if / when your app becomes class driven or class oriented, then you want to do something different.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -