Hi,

i have couple of doubts..

1) How do i use MSComm Component in a module...i could gather that i might have to use 'class module' for that..but not able to make that work.

2) if i use a class module..how to pass parameters to a class...as i would like to pass some parameters to Mscomm every-time i call the class module

Thanks in advance.

Press F2 open the MSCommLib in the dropdown list study the Constant, Properties, Methods and Events. If you want to become a good VB programmer you should know how to apply all these reading the CLASS/OBJECT. Press F4 for the properties and change some values. From that you can create a new classes with parameters.

Dim c As New MSCommLib.MSComm

with c

With c
.Break
.CommID
etc..

End With


Or

you can type c followed by dot(.) c. to see all the elements.

Hope it helps

commented: thanks +1

Thank you phpbeginners for the help...now i have been able to create the module class using Mscomm reference...

now am stuck with one more thing with Mscomm..need you r help..

we can do mscomm.settings = "9600,n,8,1" ....
but if i want something of sort
mscomm.settings = "br,pr,db,sb"

where br,pr,db,sb are values provided by user...as i dont want these values hardcoded...

Thanks in advance.

got my answer...need to use 'api'

Declare Function ConfigurePort Lib "winspool.drv" Alias "ConfigurePortA" (ByVal pName As String, ByVal hwnd As Long, ByVal pPortName As String) As Long

explanation
· pName
Points to a null-terminated string that specifies the name of the server on which the specified port exists. If this parameter is NULL, the port is local.

· hWnd
Identifies the parent window of the port-configuration dialog box.

· pPortName
Points to a null-terminated string that specifies the name of the port to be configured.

user get '0' (if cancel is pressed) or '1'(if ok is pressed) as return

Private Declare Function ConfigurePort Lib "winspool.drv" Alias "ConfigurePortA" (ByVal pName As String, ByVal hwnd As Long, ByVal pPortName As String) As Long

Private Sub Form_Load()
MsgBox ConfigurePort(vbNullstring, Me.hwnd, "COM2:")
MsgBox ConfigurePort(vbNullstring, Me.hwnd, "LPT1:")
End Sub

Thank you phpbeginners for the help...now i have been able to create the module class using Mscomm reference...

now am stuck with one more thing with Mscomm..need you r help..

we can do mscomm.settings = "9600,n,8,1"....
but if i want something of sort
mscomm.settings = "br,pr,db,sb"

where br,pr,db,sb are values provided by user...as i dont want these values hardcoded...

Thanks in advance.

If I understood... this is not a MSComm's doubt, but a concatenate syntax doubt...

Seems to me you want the "9600" - and the others values - to be a value given by the user (in a textbox, for example...)
If this is correct, try to put these values you want in a string variable, then pass THIS new string to the settings properties...

Dim cParametros as String

cParametros = txtVeloc.Text
cParametros = cParametros & "," & txtParidade.Text
cParametros = cParametros & "," & txtNum.Text
cParametros = cParametros & "," & txtParada.Text

mscomm.settings = cParametros

Assumes that the "txtVeloc" is a textbox that contains the baud, "txtParidade" contains parity information, and so on...
If these values are already stored in others variables, you can change the textbox names to your variables names, or

mscomm.settings = YourBaudVariable & "," & YourParityVariable & "," & YourBitsVariable & "," & YourStopBitVariable

Of course you can use this second method with textboxes too, change the variable names to textboxes names in the sequence you want.


Hope this helpfully.
Sidnei


Thank you phpbeginners for the help...now i have been able to create the module class using Mscomm reference...

now am stuck with one more thing with Mscomm..need you r help..

we can do mscomm.settings = "9600,n,8,1" ....
but if i want something of sort
mscomm.settings = "br,pr,db,sb"

where br,pr,db,sb are values provided by user...as i dont want these values hardcoded...

Thanks in advance.

commented: thanks +1

thanks sidnei...

my solution was a work around...your's is exactly what i was looking for..

Thanks

If I understood... this is not a MSComm's doubt, but a concatenate syntax doubt...

Seems to me you want the "9600" - and the others values - to be a value given by the user (in a textbox, for example...)
If this is correct, try to put these values you want in a string variable, then pass THIS new string to the settings properties...

Dim cParametros as String

cParametros = txtVeloc.Text
cParametros = cParametros & "," & txtParidade.Text
cParametros = cParametros & "," & txtNum.Text
cParametros = cParametros & "," & txtParada.Text

mscomm.settings = cParametros

Assumes that the "txtVeloc" is a textbox that contains the baud, "txtParidade" contains parity information, and so on...
If these values are already stored in others variables, you can change the textbox names to your variables names, or

mscomm.settings = YourBaudVariable & "," & YourParityVariable & "," & YourBitsVariable & "," & YourStopBitVariable

Of course you can use this second method with textboxes too, change the variable names to textboxes names in the sequence you want.


Hope this helpfully.
Sidnei

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.