Comm32 Logo
Home Button  Buy Button 

Topic:   Using SComm32 in VB6 application (without form)

By: BAPosted on: Apr 25 2013 at 07:53:29 PM
How can I use the SComm32 ocx in a vb6 application which does not have forms?
We have a legacy application and would like to replace MSComm32 with SComm32 (due to some issues with USB 2 serial adapter drivers). SComm32 seems to work fine (when added to the VB6 project as a component) and put on a form. But when it is added as a reference, the application won't compile.

The compiler gives an error about .Input property does not exists (which at least shows up in the intellisence in VB6 IDE).

By: GuestPosted on: Apr 25 2013 at 09:11:44 PM
Can't you have a small form with the visible property set to false. You can load the form but don't make it visible. You can then set all the comm32 properties via that hidden form.

By: GuestPosted on: Apr 25 2014 at 06:46:59 PM
You can use the MSComm control without a form, so what would be the SComm version of "Set objVComm = CreateObject("MSCommLib.MSComm")"?

By: Support Posted on: Apr 26 2014 at 09:26:36 AM
'// Example for VB6
'// At the top of your code (ie outside of any sub or function)

Dim SComm1 as Object

'// Then, for example, in your Form Load or Module Main sub

Set SComm1 = CreateObject("SComm1.SComm")

'// You can now use any of the properties and methods in your code.

By: Mitch Posted on: Aug 20 2014 at 12:58:40 PM
I would Agree. BUT! This would kill all abilities to do any event driven OnComm functions on the SComm1 variable. Your code might want to use early bindings (easiest solution) to fix this error.

private withevents SComm1 as SComm32.SComm

set scomm1 = createobject("Scomm32.scomm")

This will now allow the OnComm event to work properly. The late binding issue to an object is an issue some people have attempted to get around in VB. As an improvement, it would be nice if SComm would offer the ability to perform a call back instead of an event.


By: Support Posted on: Aug 20 2014 at 09:13:44 PM
Yes. If you want to use the OnComm event then you need to do what Mitch said.

So. At the very top of your code outside of any function
Private withevents SComm1 as SComm32.SComm

Then inside the load event
Set SComm1 = CreateObject("Scomm32.SComm")

But there is a slight problem with SComm1.Input.

"Input" is a reserved word in VB and many script languages. SComm works round that when the component is on a form or when declared code As Object. But if declared WithEvents then our .Input method breaks.

No problem though - internally we also expose a .Read function that works exactly the same as .Input So just use SComm1.Read instead of .Input

By: Guest Posted on: Dec 29 2015 at 02:40:33 PM
Sorry to pop this one to the top - but I notice in the latest v9 version the syntax is more like the original MSComm32 syntax.

Private WithEvents SComm1 As SCommLib.SComm

Set SComm1 = CreateObject("SCommLib.SComm")

Basically identical to MSComm32 but without the "M".

I never used an earlier version so can't say if WithEvents worked or not. But it does work in v9. Declaring in code just like MSComm and the OnComm event is triggered as expected.

Although, as support said, if the component is created WithEvents then the .Input function doesn't work. But it's no porblem to change the call with .Read instead of .Input

At least it works in Windows 10 !! Thank you :)

By: GuestPosted on: Feb 22 2016 at 12:25:19 PM
Hey Guys,

Im using VB6 SP6. i want to use events (and i dont have a form).

Try to do this:
Private WithEvents SComm1 As SCommLib.SComm
Set SComm1 = CreateObject("SCommLib.SComm")
It will return a type mismatch

When i use this is seems to work:
Dim SComm1 as Object
Set SComm1 = CreateObject("SCommLib.SComm")
But that will kill my event triggers?

By: GuestPosted on: Feb 22 2016 at 02:18:36 PM
Fixed myselve, had some problems with the reference, had to remove MScomm32 from the reference

Reply - add a comment to this topic.

You may enter letters, numbers and standard punctuation only. HTML and other scripts/tags will be rejected.

Topic:- Using SComm32 in VB6 application (without form)


Enter the numbers.

Your name here is optional