|
Subject:
|
Again: Reference between child window of MDI
|
|
Posted By:
|
ly_he
|
Post Date:
|
9/24/2006 9:42:40 PM
|
In vb6.0, one child window, e.g. frmSub1 here, can call the function or execute the procedure in another child window, e.g. frmSub2 here, like my following MDI program:
'frmMDI Private Sub mNewSub1_Click() Dim frm As New frmSub1 frm.Show End Sub
Private Sub mNewSub2_Click() Dim frm As New frmSub2 frm.Show End Sub
'frmSub1 'Get the sum by call the frmSub2's Function Private Sub Command1_Click() Dim f As Form For Each f In Forms If TypeOf f Is frmSub2 Then Text1.Text = f.fSum(Val(Text1.Text)) ¡®can call fSum function in frmSub2 correctly. End If Next f End Sub
'Do the frmSub2's procedure and give the sum Private Sub Command2_Click() Dim f As Form For Each f In Forms If TypeOf f Is frmSub2 Then Call f.pSum(Val(Text1.Text)) ¡®Can execute pSum procedure in frmSub2 correctly. End If Next f End Sub
'frmSub2 Public Function fSum(j As Integer) As Integer Dim i As Integer, sum As Integer For i = 1 To j sum = sum + i Next i fSum = sum End Function
Public Sub pSum(j As Integer) Dim i As Integer, sum As Integer For i = 1 To j sum = sum + i Next i Text1.Text = sum End Sub
'Get the sum by Function Private Sub Command1_Click() Text1.Text = fSum(Val(Text1.Text)) End Sub
'Get the sum by Procedure Private Sub Command2_Click() Call pSum(Val(Text1.Text)) End Sub
This MDI program can be done in VB6.0 very well. But when I upgrade it into vb2005, it counts the following errors in frmSub1: Error 1: ¡°fSum¡± is not the ¡°System.Windows.Forms.Form" member. Error 2: ¡°pSum¡± is not the ¡°System.Windows.Forms.Form" member.
Please help me solve the problem. Thank you very much. LingYong He, from China
|
|
Reply By:
|
ly_he
|
Reply Date:
|
9/25/2006 9:40:44 PM
|
Thanks for dear Billy, he told me how to get around my problem as following:
Origianl code: Dim f As Form For Each f In Forms If TypeOf f Is frmSub2 Then Text1.Text = f.fSum(Val(Text1.Text)) End If Next f Modified code: Dim f As Form For Each f In Forms If TypeOf f Is frmSub2 Then Dim f2 As frmSub2 ' Added f2=CType(f, frmSub2) ' Added Text1.Text = f2.fSum(Val(Text1.Text)) ' Modified End If Next f Thanks all of you who paid attention to my question as well.
|
|