943,096 Members | Top Members by Rank

Ad:
Jan 3rd, 2010
0

Classes - using MSComm & Passing Parameter - Help Requested

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
pankaj.garg is offline Offline
67 posts
since Nov 2009
Jan 4th, 2010
2
Re: Classes - using MSComm & Passing Parameter - Help Requested
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim c As New MSCommLib.MSComm
  2.  
  3. with c
  4.  
  5. With c
  6. .Break
  7. .CommID
  8. etc..
  9.  
  10. End With
  11.  
  12.  
  13. Or
  14.  
  15. you can type c followed by dot(.) c. to see all the elements.
Hope it helps
Last edited by phpbeginners; Jan 4th, 2010 at 5:45 am.
Reputation Points: 12
Solved Threads: 32
Posting Whiz in Training
phpbeginners is offline Offline
226 posts
since Jul 2009
Jan 4th, 2010
0
Re: Classes - using MSComm & Passing Parameter - Help Requested
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.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
pankaj.garg is offline Offline
67 posts
since Nov 2009
Jan 5th, 2010
0
Re: Classes - using MSComm & Passing Parameter - Help Requested
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

[code]
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
[\code]

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.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
pankaj.garg is offline Offline
67 posts
since Nov 2009
Jan 6th, 2010
1
Re: Classes - using MSComm & Passing Parameter - Help Requested
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...


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim cParametros as String
  2.  
  3. cParametros = txtVeloc.Text
  4. cParametros = cParametros & "," & txtParidade.Text
  5. cParametros = cParametros & "," & txtNum.Text
  6. cParametros = cParametros & "," & txtParada.Text
  7.  
  8. 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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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.
Last edited by sidnei; Jan 6th, 2010 at 2:39 pm.
Reputation Points: 22
Solved Threads: 10
Junior Poster in Training
sidnei is offline Offline
55 posts
since Dec 2009
Jan 7th, 2010
0
Re: Classes - using MSComm & Passing Parameter - Help Requested
thanks sidnei...

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

Thanks

Click to Expand / Collapse  Quote originally posted by sidnei ...
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...


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim cParametros as String
  2.  
  3. cParametros = txtVeloc.Text
  4. cParametros = cParametros & "," & txtParidade.Text
  5. cParametros = cParametros & "," & txtNum.Text
  6. cParametros = cParametros & "," & txtParada.Text
  7.  
  8. 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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
pankaj.garg is offline Offline
67 posts
since Nov 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: vb problem
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: date change event trigger - Help requested





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC