Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi,

 

this question have been asked before.. but i dont get it.

Ive searched the forum A LOT of times for questions related to mine.

 

I want to use a module with common functions to edit controls on forms.

 

The code i got right now:

# Form1

Public Class Form1
   Inherits System.Windows.Forms.Form

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       ModuleTestFunction()
   End Sub
End Class

#Module1

Module Module1
   Public frm1 As New Form1
   Public Function ModuleTestFunction() As Object
       frm1.TextBox1.Text = "Hello World!"
   End Function
End Module

 

When clicking the button, nothing happends.

If i put an msgbox into the function, it will show up, but the

textbox remains unchanged.

 

Can anyone please tell me what i do wrong?

Thanks!

 

// Peter

Edited by PetCar
Posted

Thanks! I got it to work.. with a class. But is this the right procedure?

#Form1

Public Class Form1
   Inherits System.Windows.Forms.Form

   Private otherClass As New Class1(Me)

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       otherClass.ShowTextContent()
   End Sub

End Class

#Class1

Public Class Class1

   Private callingForm As Form1

   Public Sub New(ByVal newCallingForm As Form)
       callingForm = newCallingForm
   End Sub

   Public Sub ShowTextContent()
       callingForm.TextBox1.Text = "Hello World!"
   End Sub

End Class

 

Thanks!

// Peter

  • Leaders
Posted

Looks fine to me. What procedure are you talking about?

(I'd usually instantiate another new class within the 'New' subroutine of a class)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

I want to create procedures and functions for showing a notifier popup, change the statusbar text etc.

 

(I'd usually instantiate another new class within the 'New' subroutine of a class)

 

How do you mean?

 

I have been programming VB6 for way to long.. :)

 

// Peter

  • Leaders
Posted

Like this:

Private X As Class 1
Public Sub New()
X = New Class1
End Sub

This is how I usually do it in VB6, but I don't know if there's anything 'evil' about the other way in .NET.

 

For the notifiers and status bars, they should be accessible, granted that you actually have them on your form. :)

You can also make procedures that take controls as ByRef arguments, and just change the values on the control from there.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

Thanks alot guys!!

Now im on track again :)

 

I got a big project comming up that have to be done in .net

so i have to play around with this "new" OOP.

 

VB6 has infected my brain :)

 

// Peter

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...