Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
|
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 24th, 2006, 09:42 PM
Registered User
 
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Again: Reference between child window of MDI

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


 
Old September 25th, 2006, 09:40 PM
Registered User
 
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying MDI Child Form Menus with MDI Parent ashu_from_india Pro VB 6 3 June 10th, 2008 11:01 PM
MDI & MDI Child Forms Menu's in VB2005 yulyos Visual Studio 2005 0 September 7th, 2007 09:49 AM
Reference between child window of MDI in vb 2005 ly_he Pro Visual Basic 2005 0 September 21st, 2006 03:30 AM
Opening MDI Child on Button Click of MDI Child Sachin Shinde Visual Studio 2005 0 June 8th, 2006 05:05 AM
Mdi child window minimizes vsramiya Pro VB 6 2 October 28th, 2005 07:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.