|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Simple MSComm code, but i dun understand
hi fellow pals,
I need help on the following code regarding MSCOmm. The following program is a working program, but i dun understand the code. Can anyone help me to add some comments beside the code?? ------------------------------------------------------------ Private Sub cmdConnect_Click() MSComm1.PortOpen = True End Sub Private Sub Form_Load() MSComm1.Settings = "19200,n,8,1" MSComm1.CommPort = 1 App.Title = "Visual Basic Terminal" End Sub Private Sub MSComm1_OnComm() Select Case MSComm1.CommEvent ' Event messages Case comEvReceive Dim Buffer As Variant Buffer = MSComm1.Input Debug.Print "Receive - " & StrConv(Buffer, vbUnicode) ShowData txtTerm, (StrConv(Buffer, vbUnicode)) End Select End Sub Private Static Sub ShowData(Term As Control, Data As String) On Error GoTo Handler Const MAXTERMSIZE = 16000 Dim TermSize As Long, i ' Make sure the existing text doesn't get too large. TermSize = Len(Term.Text) If TermSize > MAXTERMSIZE Then Term.Text = Mid$(Term.Text, 4097) TermSize = Len(Term.Text) End If ' Point to the end of Term's data. Term.SelStart = TermSize ' Eliminate line feeds. Do i = InStr(Data, Chr$(10)) If i Then Data = Left$(Data, i - 1) & Mid$(Data, i + 1) End If Loop While i ' Make sure all carriage returns have a line feed. i = 1 Do i = InStr(i, Data, Chr$(13)) If i Then Data = Left$(Data, i) & Chr$(10) & Mid$(Data, i + 1) i = i + 1 End If Loop While i ' Add the filtered data to the SelText property. Term.SelText = Data Exit Sub Handler: MsgBox Error$ Resume Next End Sub ----------------------------------------------------------- help given is greatly appreciate!! thanks!!! million thanks... ![]() |
|
#2
|
|||
|
|||
|
What part of the code don't you understand? If you need help with the basic syntax of Visual Basic there are many sites with good tutorials, such as www.w3schools.com
The VB online help is very thorough, try using F1 to get context sensitive help when you are editing code. In addition, the MSComm control is documented in the online help, showing you all the properties, methods, and events available from the control and explaining what each does.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#3
|
|||
|
|||
|
Thanks, But................
Dim Buffer As Variant
Buffer = MSComm1.Input Debug.Print "Receive - " & StrConv(Buffer, vbUnicode) ShowData txtTerm, (StrConv(Buffer, vbUnicode)) Private Static Sub ShowData(Term As Control, Data As String) I dun understand this 2 line, although i look for the Help F1. ![]() |
|
#4
|
|||
|
|||
|
I don't exactly understand what you quoted either. The MSComm documentation is found here, you should be able to figure out what's going on.
http://msdn.microsoft.com/library/e...l/vbobjComm.asp |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Simple MSComm code, but i dun understand |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|