473,466 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multiple Source Files and Delegate/AddressOf

(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
Apr 27 '07 #1
3 2037
Hi,

Within your OneSite structure, you should change the type of the DoerRoutine
to Delegate.
Then, when you assign your sub to this, you have to use :
New EventHandler(AddressOf METHODNAME)

Then, I use (MyForm.Invoke(MySavingMethod)) to call the specific method.
Here, MyForm is the place where you want the call to be handle (example a
form in this case. This place has to Invokable.). MySavingMethod represents
the delegate to be used (for you it would be the DoerRoutine delegate).

Hope this help,
Jonathan Boivin
---
jo************@cints.net | http://www.cints.net
"eBob.com" <fa******@totallybogus.coma écrit dans le message de news:
%2***************@TK2MSFTNGP05.phx.gbl...
(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


Apr 27 '07 #2
eBob.com wrote:
<snip>
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."
<snip>

The correct syntax is:

Sites(0).DoerRoutineDeleg = AddressOf DoX

(no parenthesis)

HTH.

Regards,

Branco.

Apr 27 '07 #3
Thank you Branco. I feel sort of foolish now to have posted a question
about a simple syntax error message. But even knowing now that the error is
a syntax error, I find the error message, "Expression does not produce a
value", not very helpful.

Thanks again, Bob
"Branco Medeiros" <br*************@gmail.comwrote in message
news:11*********************@r35g2000prh.googlegro ups.com...
eBob.com wrote:
<snip>
>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."
<snip>

The correct syntax is:

Sites(0).DoerRoutineDeleg = AddressOf DoX

(no parenthesis)

HTH.

Regards,

Branco.

Apr 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
15
by: Iced Crow | last post by:
In C# I know that you can use delegates to assing multiple addresses of sub and functions to a delegate and have it fire multiple procedures... How do I do this in VB? I only know of assigning...
1
by: Eric Newton | last post by:
Given the following code, Public class ProgressFormManager Public Sub BeginInvoke(ByVal method As , ByVal args() As Object) Dim asyncCallback As New System.Threading.WaitCallback(method)...
2
by: john | last post by:
Hello, I am trying to convert from vb6 to vb.net and I have an issue with the addressOf function. Below is the code any help would be greatly appreciated. Thanks in advance. code erroring...
0
by: RSH | last post by:
I am rather new to delegates and I was working through an exersize. I have created a simple commandline project that basically adds or edits customers. I am using two delegates, one to Notify...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
6
by: Sergey Poberezovskiy | last post by:
I have the following code in C# that I have trouble converting to VB(2.0): private delegate void openDialog(); private void openWindowsDialog(openDialog open) { Thread thread = new Thread(new...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Is there a difference between AddressOf and Delegate for assiging a function/Sub to an event? Add_Handler txt1.Click AddressOf WhatColorFont or Private Sub Delegate WhatColorFont() ....
0
by: Emilio | last post by:
Good morning to everyone, I've tested this "format" od this code to enumerate some controls in a window and it works fine. Private Delegate Function EnumChildProcDelegate _ (ByVal hWnd As...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.