Module in VB.net

Ruud

Member
Joined
Jan 2, 2007
Messages
10
Programming Experience
1-3
hello,
i want to ask everyone here how do these:

i heve vb 6.0 source code like this:
example:
i have Vb.net form name: form1 with textbox1, and button1.

sub button1.click()
{
Test form1
}


and i have module name Module1 and this module do this:

Sub Test(byVal Frm as Form)

frm.TextBox1.Teks=10

end sub

And my questions is how to make it work in VB.net?
Please somebody help me!
Thanks Very much
 
first off that example code is not vb6

but here's how it would be in vb.net:
VB.NET:
'on the form:
Private Sub Button1_Click (...) Handles Button1.Click
  Call Test(Me)
End Sub

'in the module:
Friend Sub Test (ByVal Frm As Form)
  Frm.TextBox1.Text = "10"
End Sub
 
Problem

VB.NET:
Private Sub Button1_Click (...) Handles Button1.Click
Call Test(Me)
End Sub
'in the module:
VB.NET:
Friend Sub Test (ByVal Frm As Form)
Frm.TextBox1.Text = "10"
End Sub
============================
i have tried but error occure, because can not found TextBox1 in class Form. so what must i do?

how about if i have form2 also. and Form2 has Button1 and TextBox1.

i tried this:

' in module
VB.NET:
Friend Sub Test (ByVal Frm As Form1)
Frm.TextBox1.Text = "10"
End Sub

that running successful,l but when i use this function in form2 error has occure, what must i do so i can use this function in form2 and form1??

Thanks very much...
 
Last edited by a moderator:
I'm not sure if this is the best approach, but if you wanted to send multiple forms to the same method you could do the following.

VB.NET:
Friend Sub Test(ByVal Frm As Object)
        If TypeOf Frm Is Form Then
            Dim tmpForm As Form = CType(Frm, Form)
            If tmpForm.Name = "Form1" Then
                Dim tmpForm1 As Form1 = CType(Frm, Form1)
                tmpForm1.TextBox1.Text = "10"
            ElseIf tmpForm.Name = "Form2" Then
                Dim tmpForm2 As Form2 = CType(Frm, Form2)
                tmpForm2.TextBox1.Text = "10"
            End If
        End If
    End Sub
 
Thanks

thanks you! but to much if, coz i use 40 forms. but i have knew the solution now!
Thanks Very much
 
Back
Top