Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 24th, 2006, 10:42 PM
Registered User
 
Join Date: Sep 2006
Location: Beijing, , China.
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


Reply With Quote
  #2 (permalink)  
Old September 25th, 2006, 10:40 PM
Registered User
 
Join Date: Sep 2006
Location: Beijing, , China.
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.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 11th, 2008 12:01 AM
MDI & MDI Child Forms Menu's in VB2005 yulyos Visual Studio 2005 0 September 7th, 2007 10:49 AM
Reference between child window of MDI in vb 2005 ly_he Pro Visual Basic 2005 0 September 21st, 2006 04:30 AM
Opening MDI Child on Button Click of MDI Child Sachin Shinde Visual Studio 2005 0 June 8th, 2006 06:05 AM
Mdi child window minimizes vsramiya Pro VB 6 2 October 28th, 2005 08:32 AM



All times are GMT -4. The time now is 02:28 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.