E
eBob.com
(Not that size matters, but ...) I have a program which is getting too big.
So I'd like to split it into several source files. I know that I can create
a ModuleX.vb source file which looks like this ...
Module ModuleX
Public Sub DoX()
MsgBox("message from DoX")
End Sub
End Module
.... and a similar ModuleY.vb source file for a DoY subroutine, and then use
an "on button click" routine in my Form1 code which looks like this ...
Private Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles btnGo.Click
DoX()
DoY()
End Sub
.... and that works fine.
BUT ... what I really want to do is to use the ModuleY.vb and ModuleY.vb
source files as above and use something like the following in my Form1 code
....
Public Class Form1
Inherits System.Windows.Forms.Form
Delegate Sub DoerRoutine()
Structure OneSite
Dim SiteName As String
Dim DoerRoutineDeleg As DoerRoutine ' I want DoerRoutineDeleg to be
the address of the DoX or DoY subroutine
End Structure
Dim Sites(1) As OneSite
.... but the code which tries to initialize the Sites structure ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Sites(0).SiteName = "Site X"
Sites(0).DoerRoutineDeleg = AddressOf (DoX())
End Sub
.... causes Visual Studio to complain - it puts a squiggly line under "DoX"
with the explanation "Expression does not product a value."
Maybe I could stumble about trying various things and eventually get this to
work. But Id like to understand what is going on. Why is the initial,
straightforward version OK and the version using Delegate and AddressOf not
OK.
Thanks, Bob
So I'd like to split it into several source files. I know that I can create
a ModuleX.vb source file which looks like this ...
Module ModuleX
Public Sub DoX()
MsgBox("message from DoX")
End Sub
End Module
.... and a similar ModuleY.vb source file for a DoY subroutine, and then use
an "on button click" routine in my Form1 code which looks like this ...
Private Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles btnGo.Click
DoX()
DoY()
End Sub
.... and that works fine.
BUT ... what I really want to do is to use the ModuleY.vb and ModuleY.vb
source files as above and use something like the following in my Form1 code
....
Public Class Form1
Inherits System.Windows.Forms.Form
Delegate Sub DoerRoutine()
Structure OneSite
Dim SiteName As String
Dim DoerRoutineDeleg As DoerRoutine ' I want DoerRoutineDeleg to be
the address of the DoX or DoY subroutine
End Structure
Dim Sites(1) As OneSite
.... but the code which tries to initialize the Sites structure ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Sites(0).SiteName = "Site X"
Sites(0).DoerRoutineDeleg = AddressOf (DoX())
End Sub
.... causes Visual Studio to complain - it puts a squiggly line under "DoX"
with the explanation "Expression does not product a value."
Maybe I could stumble about trying various things and eventually get this to
work. But Id like to understand what is going on. Why is the initial,
straightforward version OK and the version using Delegate and AddressOf not
OK.
Thanks, Bob