Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 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 February 9th, 2005, 08:15 PM
Registered User
 
Join Date: Nov 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Upgrade to VB.NET - late bound

VB6 allows late bound calls to procedures, but VB.NET gives an error. Does anyone have a solution for this?


Dim currentForm As Form = Form.ActiveForm

'The following statement gives an error; 'InitializeFields' is not a member of 'System.Windows.Forms.Form'

currentForm.InitializeFields()


Public Class Form1
    Public Sub InitializeFields
        txtText1.Text = ""
    End Sub
End Class

Public Class Form2
    Public Sub InitializeFields
        txtText1.Text = ""
    End Sub
End Class

 
Old February 10th, 2005, 08:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can late-bound, but you have to ctype current form to the appropriate form type for it to work.

Brian
 
Old February 10th, 2005, 03:58 PM
Registered User
 
Join Date: Nov 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response, but can you give me some sample code. The code should not refer to specific forms like form1 or form2 but should be generalized as in VB6.

 
Old February 10th, 2005, 04:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Actually, the best way to do the technique you want is define an interface:

public interface IlateBoundForm
  function DoThis as string
end interface

public class form2 : FOrm
..
  Dim o as IlateBoundForm = (ILateBoundForm)Form.ActiveForm.InitializeField()
..
end class

I believe that should work. Any form inheriting from ILateBoundForm could call that method. Though, it can only call only the methods defined in the interface.

Brian
 
Old March 4th, 2005, 07:41 PM
Registered User
 
Join Date: Nov 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Brian for pointing me in the right direction.






Similar Threads
Thread Thread Starter Forum Replies Last Post
The new stuff: Professional ASP.NET 3.5 Upgrade jminatel ASP.NET 2.0 Professional 0 February 29th, 2008 08:44 PM
Upgrade VB apps to VB.NET Steve McGuire Pro VB.NET 2002/2003 2 September 13th, 2006 04:21 PM
.NET Framework 1.1 upgrade: Remoting error agarwalmk General .NET 0 March 11th, 2004 02:42 PM
Visual Studio.NET 2003 Upgrade cjo ASP.NET 1.0 and 1.1 Basics 2 November 20th, 2003 12:17 PM





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