Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Handle Events In A Class Of A Controls Array


Hi

I think I have been reading what I am going to ask but i don't remember where.

Look, i have a custom class to handle the events of all controls I have on a form for example, so for each control I crate a new instance of the class and assign that object.

The problem I have is when the object I am passing it part of a control array. The error I am getting that my object doesn't admit those set of events. So anybody could explain me how to make this, or giving the place where are this explained?

thanks very much




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Add Activex Controls At Runtime And Handle The Events
I want to add Activex controls at runtime in my program developed by Visual Basic. I use the function :form.controls.add(proid,name...).But I do not know how to handle the events.
Because withevents variable can not be declare as array,I can't
handle the events of all Activex controls added dynamically.Do you have any idea?Would you please tell me,thank you very much!

How To Handle Events For Control Array Generated On Runtime In VB.NET?
Hello!

Does anyone can help me by telling that how can I I handle an event for array of controls which generates on runtime in VB.Net. I am using withevents but it works only for one instance of control, not for array.

Thank You!

Regards,

Muhammad Khan.

Events In Array Of Controls Added
Using this code in VBA (or VB with MsForms 2.0) (1 Form with 1 Multipage):

Code:
Dim ArrTextb(1 To 5) As MSForms.TextBox
Dim WithEvents mytb As MSForms.TextBox

Private Sub UserForm_Initialize()
MultiPage1.Pages.Clear
MultiPage1.Pages.Add
MultiPage1.Pages(0).Caption = "tab1"

For i = 1 To 5
Set ArrTextb(i) = MultiPage1.Pages(0).Controls.Add("Forms.textbox.1", _
"tbox" & i)
ArrTextb(i).Top = i * 20
ArrTextb(i).Left = 10
ArrTextb(i).Value = ArrTextb(i).Name
Next

Set mytb = MultiPage1.Pages(0).Controls.Add("Forms.textbox.1", _
"mytb")
mytb.Left = 100
mytb.Top = 20
mytb.Value = mytb.Name
End Sub

Private Sub mytb_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MsgBox "mytb_MouseUp"
End Sub
which is the way for managing the events of array of textboxes(ArrTextb)
(like mytb) because 'WithEvents' do not support array.
PS. I need Multipage control.
Actually i need an event that tell me when focus is on or out the textboxes!

Thanks.

Events For A Dynamic Array Of Controls On A Userform
I'm trying to create an array of controls on a userform which are created at runtime, which I can then reference using an index number to define events.

My problem is that I'm declaring a dynamic array of controls using:

Dim textbox() As Object

and then in the Initialization event for the userform, I have the line:

Set textbox(c) = userform.Controls.Add("Forms.Textbox.1")

to add new textbox controls.


But now, once I have the array of textbox controls, I can't define an event for each of the controls in the array. I.e. the syntax:

Private Sub textbox(c)_Change()gettext = textbox(c).TextEnd Sub

doesn't work because VBA doesn't recognize textbox(c)_Change() syntax.

It has been suggested that I use:
Private Sub textbox_Change(Index as Integer)gettext = textbox(c).TextEnd Sub

but this doesn't work either because VBA doesn't recognize textbox_Change(Index as Integer) as referring to the entire array of textbox controls and the event never fires, at least not the way I've declared the array.

Lastly, using the OnChange property of a control has also been suggested, but it seems like VBA in Excel doesn't recognize it (although it's a legitimate property in VB), e.g. the syntax textbox(c).OnChange = "changesub") isn't recognized.

I have to add controls to the array at runtime and not at designtime because the number of textbox controls in the array depends on an integer variable.

Any advice would be much appreciated.

How To Handle Grid_click Events Vs Grid_mousedown Events
I'm new to Visual Basic, but have done event-driven programming before, using a different IDE.

I'm maintaining a program running under Win 98, that is using a msFlexGrid control.

When the user left-clicks on a cell, I want specific actions to be taken, depending on the cell. I've got this part working just the way I want it.

However, I've discovered that If the user right-clicks on a cell, something undesireable happens.

All of the processing for the desired events (left clicks) are handled in grid_click().

I need to detect if the right mouse button is being pressed, and ignore them.

I've decided to create a breakpoint in grid_MouseDown(), to see if grid_MouseDown() was called before grid_click(), since grid_click is always called, regardless of the right or left button is pressed.

When I set a breakpoint in grid_MouseDown(), the breakpoint in grid_click() never occurs, and vice-versa.

I know I have some fundamental mis-conceptions about event handling, but I don't know what.

Would someone please help me out ?

thanks

tony

Handle WebBrowser Events
Hi, I'm using the WebBrowser as my interface, writing the document in the BeforeNavigate2 event.

How can I handle bookmarks putting bookmarks into the document? Is there another event I can use to write the document that won't be called when a bookmark is clicked?

Cheers

Tim

Events Overlap, How To Handle It?
Hi!

I am using the farpoint spreadsheet ActiveX. I use
the farpoint LeaveCell event to handle the tab and return event. The action for this event is to move the cursor to the next editable cell. But when I click a cell in the spread sheet, it also invokes the LeaveCell event handler. This is not what I wanted.

When I click a cell anywhere in the spread sheet, I need my cursor to be positioned at that cell. To do that, I added a click event handler. The problem is my click does not invoke the click event handler but instead still invoking the leaveCell event handler. Only if I delete the leaveCell event handler, then the click event handler is invoked.

Thus, it seems the leaveCell event overlaps and takes over the click event. Anybody knows how to solve my problem to let my application works correctly.

Thanks.
Aijun.

Capture Process Events To Handle.
hi again, could someone tell me if it's possible to capture the events that are passed to / from a handle and put them in a list / textbox?
eg: if i want to watch what happens with a command button ( clicks , paint etc... ) i get the info appearing in text , such as the WM_COMMAND.
i tried this a while ago and the app just crashed off everytime , but i really would like to view some of the processes i have going on within my form to give me a better understanding.
ty

Responding To Events Of A Window Via It's Handle
Given a Window Handle (long) that is returned utilising the EnumWindows API, is it possible to handle events that occur within that window? If so, can anyone offer any hints on how this can be done?

I seem to be able to get my app to respond to windows within the VB app itself, but not to windows of external applications.

How Do I Handle A Shell Programs Events?
I am writing an application that runs an executable file multiple times. I start by running shellexecute. After the program opens I get the menuID's. I then open the necessary menu item and enumerate the children to find the handle for the item that needs to be changed. I then use sendmessage to send BM_Click to the OK button. It's here that I have problems. I don't know how to use VB6 to find out if the window closed. This also goes for opening a form in the executable file. After I use sendmessage:
   l = SendMessage(hWnd, WM_COMMAND, mnuID, 0&)
I search for the window using FindWindow( I know the name of the window beforehand). There are times when Findwindow runs before the window opens and therefore runs in an infinite loop.

Any help would be greatly appreciated. Thanks,......Joe



How To Catch Events Of One Class In Other Class
hi,

how can i catch events raised in one class module in other class module. i have declared the variable in target class with WithEvents keyword but the event is not showing in right hand side drop down menu


please help

thanks

bye.

pratik

Web Browser To Handle Events Of The Elements Inside...
For example,

The webbrowser control displays a simple HTML page with a button.

How can I make my VB program handle the click event of that button inside the browser..


Thanks...

Please Help! How To Handle Form Events When Window Is Resized?
I'm new to VB 6.0. I really don't know what is the easiest way to handle events, when window is resized by user. Please help.
Here is full form's text from VB, I want to execute
Public Sub formResize()
every time vhen window is resized

thanks


Option Explicit

Const BORDER = 120 'Bulgarian constant
Const MIN_WINDOW_SIZE = 4200 'too

Private Sub Form_Load()
Resize
rtbStatusList.Text = "30.11.2005 15:24:11 Papiermangel" + vbCr + "30.11.2005 16:55:00 Papierende" + vbCr + "30.11.2005 20:12:11 Keine Verbindung"
rtbStatusList.Text = rtbStatusList.Text + rtbStatusList.Text
rtbStatusList.Text = rtbStatusList.Text + rtbStatusList.Text
End Sub

Private Sub Resize()
On Error Resume Next
End Sub

Public Sub formResize()
Dim w As Integer
Dim h As Integer

w = ScaleWidth
h = ScaleHeight
If (w < MIN_WINDOW_SIZE) Then
w = MIN_WINDOW_SIZE
End If
If (h < MIN_WINDOW_SIZE) Then
h = MIN_WINDOW_SIZE
End If
fraCardInfo.Width = w - picCreditCard.Width - BORDER * 3
fraButtons.Width = w - picCreditCard.Width - BORDER * 3
picCreditCard.Left = w - picCreditCard.Width - BORDER
rtbStatusList.Width = w - BORDER * 2
rtbStatusList.Height = h - rtbStatusList.Top - BORDER
End Sub

How Can I Handle Events For Dynamic Components Added To A Vb Form?
How can I handle events for dynamic components added to a Vb form?

Vb6 - Compile Error: Connot Handle Events For The Object Specified
Hello gentlemen,
I have another vb issue that I can't resolve.
This time, I am loading my source code from a Class Module called "clsFTP.cls".

My class module is called: clsFTP(clsFTP.cls)

While trying to run it, I get a "compile Error: Can not handle Events for the object specified" on this line of code:


Code:
Private WithEvents cFTP As clsFTPwith


This specific code was hilited during the error:

Code:
WithEvents cFTP As clsFTP


Below is my source code:

Code:

LocalFilename = "\Livctrls03-08Data1APPUNCLAIMWUCCTestDatabasesDataFiles" & LocalFilename


'This loads/initialises the FTP object
Set cFTP = New clsFTP

If cFTP.OpenConnection("10.8.37.44", "mfuchk", "58UA?UUW") Then

bSuccess = cFTP.FTPUploadFile(LocalFilename, RemoteFilename)

If bSuccess Then
sError = "FTP - File Upload to Server was Successful"
Else
sError = cFTP.SimpleLastErrorMessage
End If

cFTP.CloseConnection
Else
sError = cFTP.SimpleLastErrorMessage
End If

MsgBox sError

'unload/terminate the ftp object
Set cFTP = Nothing
Set txtfl = Nothing
Exit Sub

Errorhandler:
MsgBox Str(Err.Number) & ": " & Err.Description, , "Error"



Below is codes in my Class Module:

Code:
Private WithEvents cFTP As clsFTP 'GX added******

Private Const MAX_PATH = 260
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const NO_ERROR = 0
Private Const FILE_ATTRIBUTE_READONLY = &H1
Private Const FILE_ATTRIBUTE_HIDDEN = &H2
Private Const FILE_ATTRIBUTE_SYSTEM = &H4
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Const FILE_ATTRIBUTE_COMPRESSED = &H800
Private Const FILE_ATTRIBUTE_OFFLINE = &H1000
Private Const INTERNET_FLAG_PASSIVE = &H8000000
Private Const FORMAT_MESSAGE_FROM_HMODULE = &H800
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000

Private Const ERROR_NO_MORE_FILES = 18
Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_INVALID_PORT_NUMBER = 0
Private Const INTERNET_SERVICE_FTP = 1
Private Const FTP_TRANSFER_TYPE_BINARY = &H2
Private Const FTP_TRANSFER_TYPE_ASCII = &H1

'Private WithEvents cFTP As clsFTP ' GX

Private Const rDayZeroBias As Double = 109205# ' Abs(CDbl(#01-01-1601#))
Private Const rMillisecondPerDay As Double = 10000000# * 60# * 60# * 24# / 10000#

Private Const BUFFERSIZE = 255

Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As Currency
ftLastAccessTime As Currency
ftLastWriteTime As Currency
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type

' -- private functions

Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As Any, lpLocalFileTime As Any) As Long
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, ByVal lpSource As Long, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Private Declare Function FTPGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszOldName As String, ByVal lpszNewName As String) As Boolean
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszName As String) As Boolean
Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszName As String) As Boolean

Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" (ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long, ByVal Flags As Long, ByVal Context As Long) As Long
Private Declare Function FTPPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Boolean
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long

Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpLibFileName As String) As Long

Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Private Declare Function InternetWriteFile Lib "wininet.dll" (ByVal hFile As Long, ByRef sBuffer As Byte, ByVal lNumBytesToWrite As Long, dwNumberOfBytesWritten As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByRef sBuffer As Byte, ByVal lNumBytesToRead As Long, dwNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (ByRef lpdwError As Long, ByVal lpszErrorBuffer As String, ByRef lpdwErrorBufferLength As Long) As Boolean
Private Declare Function InternetAutodial Lib "wininet.dll" (ByVal dwFlags As Long, ByVal dwReserved As Long) As Long



' -- Private Variables

Private hOpen As Long
Private hConnection As Long
Private hFile As Long
Private dwType As Long
Private dwSeman As Long

Private szErrorMessage As String

Public Event FileTransferProgress(dCurrentBytes As Double, dTotalBytes As Double)



What am I doing wrong here?

Giftx.

Word 97 - Events Of Controls Made With Controls.add
I'm looking for a way to trap the events of controls made with the controls.add-methode.

f.e. a textboxes made with controls.add ....

    Set Mycmd = Controls.Add("Forms.textbox.1")
    
    Mycmd.Left = 10: Mycmd.Top = 10
    Mycmd.Width = 90: Mycmd.Height = 15.75
    Mycmd.Text = "This is the content of the TextBox1"

    Set Mycmd = Controls.Add("Forms.textbox.1")
    
    Mycmd.Left = 10: Mycmd.Top = 20
    Mycmd.Width = 90: Mycmd.Height = 15.75
    Mycmd.Text = "This is the content of the TextBox2"


... creates two nice textboxes.
But I cannot trap the events of the textboxes ...


Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Stop
End Sub


... because it does not recognise the object textbox1, textbox2 etc..

Anyone a idee how to solve this?

Please notice that I'm using VBA in Word 97
With greetings and thanks in advance for your reply,

Adrey



Edited by - Adrey on 4/22/2003 1:25:45 PM

Referring Controls Of User Controls In Class Module
Hi,
I'm developing an ActiveX control for Web application. ActiveX control has User Control form and Class Module. I want to refer the image control placed in user control in Class Module. Can u please send me a sample coding.

thanks in advance,

Accessing Class Functions Via A Window Handle
So, I have an application that runs in the system tray. It also has a popup window whose visibility can be toggled via the icon in the system tray.

When I try to run a second instance of this program I want to be able to access the function of the currently running instance that displays the popup window in order to display it and bring it back to the front for the user.

This is all being run via Citrix so the user doesn't have access to the try and if they lose the window they need some way to get it back.

Also, I am currently able to reference the running app by its window handle. Is there any way I can get access to the class function via this ID?

Thanks.

Raise Error In Class, Handle In Form?
Hello all,

Is it possible to have an error raised in a class which is then handled in the calling form? I'm coming from an MVC frame of mind here so I want to seperate my error checking code from my error handling code. So far, I have been fruitless as any time I raise an error in the class, the standard VB error display box appears instead of my custom MsgBox present in the form.

Thank you in advance.

Window Class Handle Namer Thing...
Hi! I'm hoping someone can help me, I've been searching the net and these forums but I can't seem to find what I'm looking for. I used to have a program, over a year ago, which basically listed the Window Class Name, Handle, Title (text), what it's parent window was, etc., whenever a mouse moved over a window. It was a pretty basic program, but it would come in pretty handy right now, and I was wondering if anyone had something that did that.

Any help is appreciated - thanks!

Is It Better To Handle Date In Front End(Asp.net Or Vb Class) Or At The Back End(SQL).
Is it better to handle date in Front end(Asp.net or vb class) or at the back end(SQL).
For Eg i should fetch records which r 4 weeks before.where shall i apply the business rule in front end or back end.is there any ambiguties in converting or processing date returned by sql in Asp.NEt

How To Raise A Event In A User-defined Class Module And Handle This Event By The Same Class Module?
Hi! Everybody!
I meet a question. How i can raise a event in a user-defined class module and i want use one function to handle this event in the same class module? It means i want to event source and the event sink in the same class! How can i achieve it?
Thank you anybody's help!
Thank you very much!

SubClassing A Class Module...think It Involves Creating A Handle?
'ello
I have a class module, that will use SendMessage to communicate with another application...
what I want is for that application to be able to SendMessage back to the class module...

How do I create a handle/window blah blah for a class module and subclass it?

Class Events?
I've coded myself into a corner, and I don't even know which terms/words to use to search for a solution to solve my problem. My original goal was that I noticed I was using the same kinds of controls and control names for multiple forms: lblTitleBar, lblCmd1, lblCmd2, cmdTmr, etc. I figured that I could consolidate this duplicated code into a class and create an instance on each form. At that point, my basic controls would be setup, formatted, and ready to use for each form. As it stands now, the visible GUI part is working as planned, but I can't figure out how to now capture the events for these objects. Am I not setting them up properly? Is there a way I can pass basic VB events (Click, DblClick, MouseMove, etc) to the class or reference these events on the parent form?

Now, I've seen that I can create the variables on each form and then, they will work as planned, but it would kinda defeat the purpose of trying to centralize the code if I still need to have multiple variable declarations, etc per form, no?


VB Code:
Option Explicit 'clsFormPublic lblTitleBar          As LabelPublic lblCmd1              As LabelPublic lblCmd2              As Label Private foForm              As Form Private cmdTmr              As Timer Private shpTitleBar         As ShapePrivate shpForm             As Shape Public Sub NewObject(ByRef roForm As Form)        Dim li          As Integer     Set foForm = roForm     Set lblTitleBar = foForm.Controls.Add("VB.Label", "lblTitleBar")        Set lblCmd1 = foForm.Controls.Add("VB.Label", "lblCmd1")    Set lblCmd2 = foForm.Controls.Add("VB.Label", "lblCmd2")        Set cmdTmr = foForm.Controls.Add("VB.Timer", "cmdTmr")        Set shpTitleBar = foForm.Controls.Add("VB.Shape", "shpTitleBar")    Set shpForm = foForm.Controls.Add("VB.Shape", "shpForm")        ' Label Objects    With lblTitleBar            ' Dimensions        .Top = 2        .Left = 2        .Width = roForm.ScaleWidth - 4        .Height = 19                ' Visibility        .Visible = True        .BorderStyle = 0                ' Color        .BackColor = &H808080        .ForeColor = &H80000009                ' Text        .Caption = "Test_Form"        .Font.Bold = True        .Font.Name = "MS Sans Serif"            End With        With lblCmd1                        ' Dimensions        .Width = 16        .Height = 16        .Top = lblTitleBar.Top + 1        .Left = roForm.ScaleWidth - 3 - .Width                ' Visibility        .Visible = True        .BackStyle = 0      ' Transparent        .BorderStyle = 1    ' Fixed Single        .Appearance = 0     ' Flat        .Alignment = 2      ' Centered                            ' Text        .Caption = "X"        .Font.Bold = True        .Font.Name = "Verdana"                .ZOrder            End With                     With lblCmd2            ' Dimensions        .Width = 16        .Height = 16        .Top = lblTitleBar.Top + 1        .Left = roForm.ScaleWidth - 4 - (.Width * 2)                ' Visibility        .Visible = True        .BackStyle = 0      ' Transparent        .BorderStyle = 1    ' Fixed Single        .Appearance = 0     ' Flat        .Alignment = 2      ' Centered                            ' Text        .Caption = "_"        .Font.Bold = True        .Font.Name = "Verdana"                .ZOrder                    End With     ' Shape Objects    With shpTitleBar        .Left = 1        .Top = 1        .Width = roForm.ScaleWidth - 2        .Height = lblTitleBar.Height + 2        .Visible = True    End With     With shpForm        .Left = 1        .Top = shpTitleBar.Height + shpTitleBar.Top + 1        .Width = shpTitleBar.Width        .Height = roForm.ScaleHeight - lblTitleBar.Height - 4        .Visible = True    End With End Sub
Now, all I want to do is know when someone clicks or when the mouse is over one of these newly created labels...

VB Code:
Option Explicit' Main FormPrivate foFormCls       As clsForm Private Sub Form_Load()        Set foFormCls = New clsForm        Call foFormCls.NewObject(Me) End Sub Private Sub lblTitleBar_Click()   Msgbox "Doesn't Work"End Sub

( I've attached a sample screenshot to show how the GUI appears. If you don't click on one of the labels, Form_Click(), etc will fire. )

Class Modules And Events
I just started to get into the wonders of the Class Module (up until today I had no idea what they did). When I realized that they are more like objects and can have methods and properties, I decided they could have methods. After some searching on the forum I found myself correct, but with a lack of knowledge on HOW to actually make an event. For example, a simple textbox has a Change event that will occur when the textbox changes. Basically my question is this, how can I make a class module perform something when an event occurs?

Events In A Class Module
Hello, all

Could you explain the difference between events in a class module and event in a standard module? And Why are events important in class modules?

many thanks,

TK

(class) Interfaces And Events
I'm wanting to create a generic interface for some Mapper classes, and have come up with the following:


VB Code:
'interface IMapperPublic Function Update() As BooleanEnd Function Public Function Delete() As BooleanEnd Function Public Function Insert() As BooleanEnd Function Public Property Let MappableObject(ByRef DomainObject As IDomainObject)End Property


The problem i have is i can't figure out how to raise events from an interface. I would like to have (to start with) a generic "error" event,


VB Code:
'ideal error event in IMapperPublic Event MapperError(byval ErrString as string, byval ErrNum as integer, byval ErrTitle as string)


But events aren't inherited. So how could i do the following (this is what i'd ideally like it to work like):

VB Code:
'a formprivate withevents Mapper as IMapper public sub SomeSub()[indent]dim objClient as new clsClient 'i know i know, its just for the example :P dim MapperFactory as new clsMapperFactory'factory decides which implementation 'of the Mapper to return based on the objects TypeOf'returns client mapper implementationset Mapper = MapperFactory.GetMapper(objClient)  if Mapper.Update() = false then'...end if'but if update generates an error (and ideally raises the MapperError event), 'how would it get passed to the form to handle/ display? 'Using true on success or false on failiure is not descriptive enough.[/indent]end sub public sub MapperError(byval ErrString as string, byval ErrNum as integer, byval ErrTitle as string)[indent]msgbox errnum & vbcrlf & errnum, vbokonly, errTitle[/indent]end sub


If the events have to be defined in the implementing mapper, then i'll be losing the genericability (?!!).

Any ideas would be welcomed.

edit:

Here's a psuedocode example of how i'd like the ClientMapper to work:

VB Code:
'clsClientMapperoption explicitimplements IMapperprivate objClient as clsClient Private function IMapper_Update() as boolean[indent]on error goto ErrHandlerdim myRS as new adodb.recordset sql = "update tblClients set clName = " & objClient.Name & " '...etcmyRS.open conx, sql, 'etc...[/indent]exit functionErrHandler:[indent]raiseevent IMapper_MapperError(myRS.errors.item(1).description, 'etc)[/indent]end function

Events Not Firing From Within Class
Hi folks,

I have a form and 2 classes. (The first class calls the second class). My form calls the first class which then calls the second class.

I want to raise an event in the second class and have it captured by the main form. I have the code in place but my debugs in the events for the main form never happen. Is it possible to do what im trying to do and get a sub class to fire events in a main form or do the events have to be captured in the previous class first and the refired to the main form?

cheers

Class Object Events
Hi

I made a class that selects an area with a rubberband. This gives me the left and top and the right and bottom to work with. My problem is once I get this info I want this area to live on it's own with events such as myArea_click(x as single,y as single). How do I create and get this type of event to completely ignore the button down event of the form without using a conditional in the button down event.

In other words - How do I make this area a completely independent object such as a picturebox?

Class + Events + Brainblock
I just can't figure out why the event in the class won't fire...


Code:
'in the form
Option Explicit
Private TestClass As Class1
Private WithEvents TestEvents As Class1

Private Sub Form_Load()
Set TestClass = New Class1
End Sub

Private Sub Command1_Click()
TestClass.testing
End Sub

Private Sub TestEvents_Fire()
MsgBox "event fired"
End Sub

'and in a class module
Option Explicit
Public Event Fire()

Public Sub testing()
RaiseEvent Fire
End Sub


I have a feeling I should know this, but just not coming to me!

How To Catch Class Events?
I've written a couple of class-modules with some public events.

I call these by using the RaiseEvent command... but how do i catch them?

This is the code in a module:


Code:
Public ClassInst as MyClass


but placing


Code:
Public Sub ClassInst_SomeEvent(Someargs as Types)
MsgBox "whoho, you cached it!"
End Sub


doesn't work...

how do i do that?

Events And A Collection Class
I am currently at a loss. A little while ago I asked how to create a Collection Class. I've got the code and it works.

Only one small problem. My program start an ActiveX EXE witch searches a database and give data by raising an event. This is the problem. When the Collection Class is passed back, I can't use indexes anymore.

An example


Code:
Private WithEvents MyData As CollClass
________________________________________________________

Public Sub MyData(Data As UserType)
msgbox Data(i).Name
End Sub


This is where the event is triggerd. The problem is that this code doesn't work. I get the message that the object variable is not set and so on. You all had it once or twice.

Why is this and how can I overcome this problem. The strange thing is that by using the For Each ... Next structure I can access the data in the Class. What's going on???

Picking Up Events Within A Class
Say I have this code in a Class.
Code:Public Event Hello(blnFlag As Boolean)
Public Sub r()
RaiseEvent Hello(True)
End Sub

How could I pick up the Event Hello when I call "r"? Is this even possible?

Sending Events To A Class Possible?
after quite a bit a wheel spinning here, I am uncertain if it is possible to send an event (RaiseEvent) to a class you have just instantiated

every example I see only has the class raising an event in the client (the creator of the class). After quite a lot of brainstorming, I am still unsuccessful ...

thanks in advance, rick


... incidentally microsoft has considerable code in the samples directory for their coffee pot example showing the effects on a CPU of running separate threads. Saddly, the only separate thread they ever run is a Timer API - really a huge waste of their code since if I can not find a way to run the server's thread without halting my client's thread (waiting for the return) then the whole separate thread becomes useless

How Handle Controls In The Form
Hi
Is there any way to use a loop and make a string from properties of different controls in a form?

I mean I have textboxes and comboboxes and UC on the form.for adding a new record I use cn.execute like that


Code:
cn.execute "insert into table (x,y,z) values (" & [color=Green]text1.text & "," .....[/color]

exept of :


Code:
[color=Green]Text1.text & "," & combo1.text & "," .....[/color]

I like to use a for next to make it automaticly:


Code:
for i=1 to me.controls.count
strX=strX & me.controls(i).text
next

the problem is the controls(i) do not sort as the sequens I add the controls and dont know how can I change me.controls(index).

any help please
thanks

DirectSound Events - Class Module?
Is it possible to supply DX8.CreateEvent() with an instance of a class instead of an instance of a form?

I've been a noob all day...

Object Or Class Does Not Support The Set Of Events
I'm building an Access Database (Access 2002) and while it works fine on my machine, testers are all getting 'Object or Class does not support the set of events' when they try to open it (same OS, same Acces version). I have found many, many discussions of this problem on the internet, but not one solution.

Thanks,
---bnpatten
Richmond,VA

Object Or Class Does Not Suport The Set Of Events
I have two forms, on form1 I have a control array. On the other form (form2) I want to have a reference to one of the controls in the control array. I declared a variable of the same type using WithEvents, but when I try to set a refernce I get an error. "Object or class does not suport the set of events". I need to raise the events from the control on form2.

Raised Class Events Not Working
I have written a small project that when the mainform is loading it creates a class object with events.

This is the only variable declared in the MainForm code.


Code:

Private WithEvents gEmailSettings As Email_Settings



Now on load the class is created...


Code:

Private Sub Form_Load()

' Create the Email_Settings class instance
Set gEmailSettings = New Email_Settings
' Sets the status bar to reflect how many accounts are loaded.
StatusBar1.Panels(1).Text = gEmailSettings.AccountsLoaded & " Mail Account(s) are loaded "

End Sub



I have the events declared in the MainForm code.


Code:

Private Sub gEmailSettings_AccountError(ByVal errCode As Integer)
If errCode = 1 Then
MsgBox "There are no email accounts present in the Database." & Chr(13) & "Please go to settings and add an account", vbCritical, "Critical Error"
Unload MainForm
End If
If errCode = 2 Then
MsgBox "No Primary Account could be found. Cannot continue." & Chr(13) & "Please go to settings and set a Primary Account", vbCritical, "Critical Error"
Unload MainForm
End If
End Sub

Private Sub gEmailSettings_Critical(ByVal errCode As Integer)
MsgBox "There was an error trying to connect to the Database." & Chr(13) & "Please contact your system administrator", vbCritical, "Critical Error"
Unload MainForm
End Sub



Now the problem is that I am intentionally raising an event to test it through code that is called from the initializing of the class.


Code:

' This event is raised if there is a critical error in getting the email settings
Public Event Critical(ByVal errCode As Integer)

' This event is raised if there is an account error
Public Event AccountError(ByVal errCode As Integer)

' Parses the passed command line arguments for individual elements and adds them to a recordset.
Private Function ParseCLA()
Dim tArray() As String ' Temporary String array to hold all parsed arguments
' Use the split function to parse out all arguments into an array
If Command = "" Then GoTo ParseError
If IsNull(Command) Then GoTo ParseError
tArray() = Split(Command, ";")
If UBound(tArray) <> 3 Then GoTo ParseError

' Takes the first 3 arguments and assigns them to the global variables
gSpinLoc = tArray(0)
gCurrentUser = tArray(1)
gCurrentBrokerID = tArray(2)
ParseError:
RaiseEvent Critical(1)
End Function



ParseCLA gets called while the class gets initialized. During the check on Ubound(tarray) it fails (on purpose) and then jumps to ParseError. At this point the RaiseEvent is used to trigger the Critical event on Mainform.

While stepping through the code I can see that it it does jump to the ParseError label and steps through the RaiseEvent Critical(1) code. It does not step into the GEmailSettings_Critical sub on Mainform at all.

It does not do this while stepping or running the program without any breaks either.

Creating a command on MainForm that runs a public function in the class that calls ParseCLA() will trigger the event.

Can class events be called during the initializing of a class or the loading of a form? Any ideas as to why it refuses to actually raise the event during the initializing of the class module/form is appreciated.

How Do I Use Global Events In A Class Module?
If I have a class module attached to my project with a global event, ie:

Public Event MyEvent()

How do I set code up to respond when this event happens in form1?

Raising Events From A Collection Of Class's
I have a collection of class's. I am raising an event in these class's but am finding it difficult to see how i get this event into my collection and into the calling program. The collection is a class itself with the usual, Add, Remove, Item.
Any help or suggestions greatly appreacited.

Global Timer Class With Events?
I am new to COM programming. Is it possible to construct a timer that can used globally, instead of just one form?

I have an app at factory which is reading in temperatures, tach rates, etc.

I would like to get timer that works on all forms.

Using label change events, I would like to alert the Global timer that a certain threshold has been surpassed by examining the value of the label.caption. I would then like to pass the control name as an argument to the Global timer. The timer will then turn the control's visible property on/off at 1-sec intervals to better alert the operator.

Is there a way upgrade the existing timer control to do this? I'd appreciate any general ideas about this, or let me know if it's a bad way to do this.

Thanks for any input,
Dave

Timer Events In Class Module
I am a VB beginner and hope somebody can give me some advice on the following matter:

I am working on a class module that is able to receive the following information:

Controlname: ie. lblInfo
background color of the control: ie. &H00C0FFFF&
foreground color of the control: ie. &H00FF0000&
desired background color: ie. frmData.background
desired foreground color: ie. frmData.background

The class has some internal code that breaks the colornumbers down to rgb colors and subsequently changes the current background and foreground colors of the control to the desired background and foreground colors. In the example above background and foreground color of the lblInfo control would fade to the background color of the frmData, which contains lblInfo.

The code for that is rather simple and works fine. The problem is that I would like to control the speed of the fading process. I don't like the side effects of API Sleep calls or DoWhile Loops with DoEvents. So I wonder if it is possible to use a timer event in a class module?

The following code is in the class module.

Declaration Section:
Private WithEvents Timer1 As betterTimer
...
Private Sub Class_Initialize()
Set Timer1 = New betterTimer
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
...
Public Sub Timer1_Timer
code for fading ...
End Sub

So it is possible to get a Sub Timer1_Timer into my class module, but if I call the sub from my main form:

Dim calc As New clsFade
calc.Timer1_Timer

then the programm runs through the Sub Timer1_Timer once and returns to the calling form. I guess that is to be expected. But what can I do to make the programm go over the code in the Timer routine at every timer interval until I set timer.enabled = False? Is it possible at all to do that in a class module?

Your help would be highly appreciated. Thank you.

Carl

Tricky Question To Handle Controls (Is This Possible?)
Hi... I have a question for you all...

I'm wondering if this is possible (The reason I ask is because if this is possible it would save lot of space of repeated code)...

Lets say we have 6 controls: PictA, PictB,PictC,PictD,PictE,PictF
And 1 selector: A,B,C,D,E,F

Ex:

VB Code:
Select Case Selector Case "A"    PictA.Visible    PictA.enable = true      .    . '*** These means plenty of code for PictA    .    PictA = "C:MyImage.jpg" Case "B"    PictB.Visible    PictB.enable = true      .    . '*** These means plenty of code for PictB    .    PictB = "C:MyImage.jpg" Case "C"    PictC.Visible    PictC.enable = true      .    . '*** These means plenty of code for PictC    .    PictC = "C:MyImage.jpg"    .    .    . Case "F"    PictF.Visible    PictF.enable = true      .    . '*** These means plenty of code for PictF    .    PictF = "C:MyImage.jpg" End Select

The point is that there is a lot of code, but is repeated for every case so I'm thinking if there is a way to simplify by using strings... like..


VB Code:
Const MyControl = "Pict" . . . '*** Somewhere in the program.. MyControl rol = MyControl & Selector (And now after using a function or something I don't know we would have)     NewControl.Visible    NewControl.enable = true      .    . '*** These means plenty of code for NewControl     .    NewControl = "C:MyImage.jpg"

And these code would be the only one, no need to repeat it.

I know it sounds crazy but I just want to make sure if it is possible or not...

Tnx!

How Do I Get Events From A Late Bound Class (activex Dll)
is it possible?

I have a class in an activex dll that raises its events.

Now, In my exe app i have to late bind to that class by CreateObject() .. because this is a plugin framework i'm working on..

But i can't do

Dim WithEvents cMyClass as Object ' compiler error.

to catch the events.

Creating A New Control With Events Inside A Class
I want to insert a timer in a class, so as it can keep track of how much time has been going till it has started processing.

Now first, i added this to the Class (Declarations) seciton


Code:
private WithEvents TimeTaken as vb.timer
This will add the timer to the class, with its events. Then in the
Class_Initialize, i added the "SET" piece to refernce the item


Code:
Private sub Class_Initialize()
Set TimeTaken = New vb.timer
End Sub
Now, when VB comes to processing this instruction, it gives out an error. The error is "INVALID USE OF 'NEW' KEYWORD".

Now i've seen other programs that work using this method. This one is an example

FTP Client Sample

It has 2 winsock controls which are created in the class (declared WithEvents)

Now it works.... coz many users have tested it. But dont know why, on my pc it doesnt. It gives me that problem. I'm on VB5.

Can anybody tell me how to be able to reference a new item in a class? and how it can work obviously

thanks in advance


PS: This post has no connection to the other post about winsock

(VB6) Class + Events + Recursive Call = Headache!!
Hello everybody ... as you can guess I have a headache.
I wanted to create a class (Class1) with events which contains a class which ... and so on.
The aim is that I want to get back the event from all the class level items.
It looks like something like that:
a) the class named Class1:
Property Get/Let Name() as string
Property Get/Set SubClass() as Class1
Event NameEvent(aName as String)
Write RaisEvent in the Let Name property (for exple)

b) the structure of the program:
Class1.item
|
|==>Class1.item
|
|==> Class1.item
etc.

c) In the sub Main (or others) de declaration is:
Public WithEvents C1 as Class1
Sub Main()
Dim TmpC1 as Class1
Set C1 = New Class1
C1.Name = "A"
Set TmpC1 = New Class1
TmpC1.Name = "AA"
Set C1.SubClass = TmpC1
'etc.
end sub
Private Sub C1_NameEvent(aName as String)
Debug.? aName
end Sub

You will notice that you will NOT get of the "SubClass".

WHY and HOW to do that (if possible)
THANKS a lot (Good luck).

Raising Mouse Click Events In A Class
Ive created a class, and would like to add Mouse click events to it. How? Thanks =)

Raising Mouse Click Events In A Class
Ive created a class, and would like to add Mouse click events to it. How? Thanks =)

Copyright © 2005-08 www.BigResource.com, All rights reserved