473,787 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ 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(ByV al sender As Object, ByVal e As System.EventArg s)
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 DoerRoutineDele g As DoerRoutine ' I want DoerRoutineDele g 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(ByVa l sender As Object, ByVal e As System.EventArg s)
Handles MyBase.Load
Sites(0).SiteNa me = "Site X"
Sites(0).DoerRo utineDeleg = 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 2062
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(Ad dressOf 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******@total lybogus.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(ByV al sender As Object, ByVal e As
System.EventArg s) 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 DoerRoutineDele g As DoerRoutine ' I want DoerRoutineDele g 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(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Sites(0).SiteNa me = "Site X"
Sites(0).DoerRo utineDeleg = 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(ByVa l sender As Object, ByVal e As System.EventArg s)
Handles MyBase.Load
Sites(0).SiteNa me = "Site X"
Sites(0).DoerRo utineDeleg = 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).DoerRo utineDeleg = 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.comwrot e in message
news:11******** *************@r 35g2000prh.goog legroups.com...
eBob.com wrote:
<snip>
>Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventAr gs)
Handles MyBase.Load
Sites(0).SiteNa me = "Site X"
Sites(0).DoerRo utineDeleg = 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).DoerRo utineDeleg = 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
4999
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 for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
15
6631
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 a single method to a delegate in VB.NET. I want to use it as in C#... to fire multiple events. Thanks in advance!
1
1165
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) System.Threading.ThreadPool.QueueUserWorkItem(asyncCallback, args) End Sub .... End Class
2
1973
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 here 'UPGRADE_WARNING: Add a delegate for AddressOf ViewFinderCallbackFunc Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1048"'
0
343
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 any changes to a customer, and now I want to set a delegate up to Notify of any new customers. My problem is where to place it. With the Notify of changes it was simple because I just instantiate the Delegate after i create the customer object. ...
6
3991
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 string UID; public string PWD; }
6
6871
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 ThreadStart(open)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
2
1476
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
1203
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 IntPtr, _ ByVal lParam As Integer) As Boolean Private Declare Function EnumChildWindows Lib "user32" _
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10169
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.