Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I am migrating my vb6 project to vb.net. currently i have two forms and second form contains public function GetData , in VB6 i was calling this function from form1 as below

str =Form2.GetData

 

Form2 is the name of second form..

 

how can i do this u=in VB.net . Do not want to create object of Form2 in form1.

 

help needed...........

Posted

If you don't want to create an object of Form2 in Form1 but you need to call a method on that other object, you could do something like this using a Shared [static in C#] method:

 

Class Form2
   ....
   Public Shared Function GetData(....)
       ...
   End Function
End Class

Class Form1
   ...
   Sub Form1_Load()
         Dim DataObject as Object
         DataObject = Form2.GetData(...)
   End Sub
End Class

 

This code will work regardless of if the Classes are Forms or any other type of class. However; as PD stated there are major differences between VB6 and .NET Forms, you should look at the post he provided.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...