Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 10th, 2005, 06:43 AM
andytan_86 andytan_86 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 14 andytan_86 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 25 m 14 sec
Reputation Power: 0
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...

Reply With Quote
  #2  
Old August 10th, 2005, 02:03 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 9 m 23 sec
Reputation Power: 181
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

Reply With Quote
  #3  
Old August 10th, 2005, 11:35 PM
andytan_86 andytan_86 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 14 andytan_86 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 25 m 14 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old August 11th, 2005, 05:51 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 9 m 23 sec
Reputation Power: 181
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

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Simple MSComm code, but i dun understand


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT