Click to See Complete Forum and Search --> : Controls in class module


moydheen
March 26th, 2001, 02:36 PM
Hello CodeGurus,

I'm having timer and mscomm control in my form, now I want to createan application without form. I'm just going to create as an activex dll the entire application.

I understand that we can do this using the createobject method. Anybody can explain me in a detail how to accompolish this.

Any help regarding this will be highly appreciated.

Thanks!!!

moydheen

Cakkie
March 27th, 2001, 01:06 AM
If you want to create a formless application, you can just use the standard exe template and remove the form from the project. Then add a module and add a sub called main. Also add a class module wich will be used to declare the variables. In vb6 you can declare a variable with events, this is needed when you want to try to catch the timer event of the timer, and any events from the comm object.


' normal module
public Sub Main()

Dim c as Class1
c.run

End Sub

' the class module
private withevents MSC as MSComm
private withevents TMR as Timer
private StopExecution as Boolean

private Sub Class_Initialize()
set MSC = new MSComm
set TMR = new Timer

' do other things like setting the timer interval etc

End Sub

public Sub DoRun()

' Do things to start execution
TMR.Enabled = true ' or something

' loop until you don't need to anymore
StopExecution = false
Do Until StopExecution
DoEvents
Loop

End Sub

private Sub TMR_Timer()
' catch timer event of our timer
End Sub
'
' other procedures, like the events of the Comm object
'



The reason you need to loop is because the program will terminate when no other object is activated (like a form)

Tom Cannaerts
slisse@planetinternet.be

The best way to escape a problem, is to solve it.

Clearcode
March 27th, 2001, 03:32 AM
Does this work with a timer?
I would have thought that the timer control was simply a wrapper for the SetTimer API call

Declare Function SetTimer Lib "user32" Alias "SetTimer" (byval hWnd as Long, byval nIDEvent as Long, byval uElapse as Long, byval lpTimerFunc as Long) as Long




Which requires a valid window handle in order to trigger the timer event.
It might be possible to create a window that is never shown in your DLL and put the timer on this using the CreateWindow api call:


'\\ Creating new windows.....
private Declare Function CreateWindowExApi Lib "user32" Alias "CreateWindowExA" (byval dwExStyle as Long, byval lpClassName as string, byval lpWindowName as string, byval dwStyle as Long, byval x as Long, byval y as Long, byval nWidth as Long, byval nHeight as Long, byval hwndParent as Long, byval hMenu as Long, byval hInstance as Long, lpParam as Any) as Long




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com

moydheen
March 27th, 2001, 10:41 AM
Dear Cakkie,

Thanks for your reply. In my program the following error occurs when I use timer class in code

Dim WithEvents tmrWaitInput As Timer
set tmrWaitInput=new Timer 'This line is giving error as Invalid use of new keyword
What could be the reason for the above error. How to handle this situation.


The folllowing is the informatin provided in MSDN
--------------------------------------------------

You tried to instantiate an Automation object, but it was not a creatable object.
For example, you tried to create a new instance of a list box by specifying ListBox
in a statement like the following:
' Valid syntax to create the variable.
Dim MyListBox As ListBox
Dim MyFormInst As Form
' Invalid syntax to instantiate the object.
Set MyFormInst = New Form
Set MyListBox = New ListBox

ListBox and Form are class names, not specific object names.
You can use them to specify that avariable will be a reference to a certainobject type,
as with the valid Dim statements above. But you can't use them to instantiate the objects
themselves in a Set statement. You must specify a specific object, rather than the
generic class name, in the Set statement:

' Valid syntax to create new instance of a form or list box.
Set MyFormInst = New Form1
Set MyListBox = New List1

----------------------------------


regards
shiek