J
jaykchan
I would like to know how to call various routines dynamically using
VB.NET.
Let say I have a class called CMyBarcodeReader that needs to send a
barcode number that it has received from scanner to a routine called
HandleBarcodeNum() in one of these forms: frmOne, frmTwo, and frmThree.
Obviously, it should send the barcode number only to the currently
opened form, and the current form can be frmOne, frmTwo, or frmThree. I
can think of two possible ways to handle this:
One way is to pass the address of one of the HandleBarcodeNum() routine
to CMyBarcodeReader like what a C program may do. But I have no idea
how to do this in VB.NET. Can someone point me an example or some
useful keywords?
Another way that I can think of is to pass a flag to CMyBarcodeReader
class to indicate the currently opened form that it should send. And
then, when CMyBarcodeReader needs to send the barcode number to
HandleBarcodeNum() routine, it can check the flag and then call the
appropriate function. In other words, the code is like this:
CMyBarcodeReader:
..
..
Select(Me.m_sSendToFormName)
Case "frmOne"
Call frmOne.HandleBarcodeNum(sBarcodeNum)
Case "frmTwo"
Call frmTwo.HandleBarcodeNum(sBarcodeNum)
Case "frmThree"
Call frmThree.HandleBarcodeNum(sBarcodeNum)
End Select
..
..
The HandleBarcodeNum() routine will be defined like this in each form:
Public Shared Sub HandleBarcodeNum(ByVal sBarcodeNum As String)
....
End Sub
The problem is that I get syntax error when I refer to data elements of
the form. Seem like that routine "may" not get access to data elements
of that instance of form, and seem like a Public-Shared-Sub "may" only
get access to some kind of static data elements or class-level data
elements. How should I handle this situation? Can someone show me the
correct syntax or an example?
Is there a better way to do this?
Thanks in advance for any info.
Jay Chan
VB.NET.
Let say I have a class called CMyBarcodeReader that needs to send a
barcode number that it has received from scanner to a routine called
HandleBarcodeNum() in one of these forms: frmOne, frmTwo, and frmThree.
Obviously, it should send the barcode number only to the currently
opened form, and the current form can be frmOne, frmTwo, or frmThree. I
can think of two possible ways to handle this:
One way is to pass the address of one of the HandleBarcodeNum() routine
to CMyBarcodeReader like what a C program may do. But I have no idea
how to do this in VB.NET. Can someone point me an example or some
useful keywords?
Another way that I can think of is to pass a flag to CMyBarcodeReader
class to indicate the currently opened form that it should send. And
then, when CMyBarcodeReader needs to send the barcode number to
HandleBarcodeNum() routine, it can check the flag and then call the
appropriate function. In other words, the code is like this:
CMyBarcodeReader:
..
..
Select(Me.m_sSendToFormName)
Case "frmOne"
Call frmOne.HandleBarcodeNum(sBarcodeNum)
Case "frmTwo"
Call frmTwo.HandleBarcodeNum(sBarcodeNum)
Case "frmThree"
Call frmThree.HandleBarcodeNum(sBarcodeNum)
End Select
..
..
The HandleBarcodeNum() routine will be defined like this in each form:
Public Shared Sub HandleBarcodeNum(ByVal sBarcodeNum As String)
....
End Sub
The problem is that I get syntax error when I refer to data elements of
the form. Seem like that routine "may" not get access to data elements
of that instance of form, and seem like a Public-Shared-Sub "may" only
get access to some kind of static data elements or class-level data
elements. How should I handle this situation? Can someone show me the
correct syntax or an example?
Is there a better way to do this?
Thanks in advance for any info.
Jay Chan