Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Thread Closed: Issue successfully resolved

???
06/21/04 16:28
Read: times


 
#72856 - VB COM2 - Off topic
Hello!
Again asking for help here, for the COM2 program in VB...

I send data from 51 to COM2 received by VB, and print it out. I let the user select the COM using.(COM1/COM2)

The program halt on the start after I choosed COM2 and said the problem comes from the array. I've struggle with the VB's array for many many times but have no succeed.

It's very annoying to check others' program so, thanks for your patient for checking mine.
------------------------------------------------
Dim Obuffer(0) As Byte
Dim Ibuffer() As Byte
Dim Oread As Integer
Dim serialport As Integer

Private Sub Form_Load()
Do
serialport = Val(InputBox("Select ComPort 1 or 2?", "ComPort selection", 1))
Loop Until serialport = 1 Or serialport = 2

Label1.Caption = ""
Label2.Caption = "Output"
Label3.Caption = "Input"
Label4.Caption = "Baud Rate = 1.2kbps, Serial mode 1 for MPU."
Text1.Text = ""

With MSComm1
.Settings = "1200,n,8,1"
.InputMode = comInputModeBinary
.RThreshold = 2
.InputLen = 2
.CommPort = serialport
.PortOpen = True
End With

End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = 0
End Sub

Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
Ibuffer = MSComm1.Input
If Ibuffer(0) = Ibuffer(1) Then Label1.Caption = Ibuffer(0)
End If
End Sub

Private Sub Text1_Change()
Oread = Val(Text1.Text)
If (Oread < 0) Or (Oread > 255) Then Text1.Text = ""
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Oread = Val(Text1.Text)

If (Oread >= 0) And (Oread <= 255) Then
Obuffer(0) = Val(Text1.Text)
MSComm1.Output = Obuffer
MSComm1.Output = Obuffer
Text1.Text = ""
Else
Text1.Text = ""
End If

MSComm1.InBufferCount = 0
End If
End Sub

------------------------------------------------

Stanley

List of 24 messages in thread
TopicAuthorDate
VB COM2 - Off topic            01/01/70 00:00      
   RE: VB COM2 - Off topic            01/01/70 00:00      
      RE: VB COM2 - Off topic            01/01/70 00:00      
   Bad style - unwarranted restriction            01/01/70 00:00      
      RE: Bad style - unwarranted restriction            01/01/70 00:00      
         RE: Wot, not serial port?!            01/01/70 00:00      
         RE: Bad style - unwarranted restriction            01/01/70 00:00      
            COM13!!            01/01/70 00:00      
               RE: COM13!!            01/01/70 00:00      
                  RE: COM13!!            01/01/70 00:00      
                     RE: COM13!!            01/01/70 00:00      
                        RE: COM13!!            01/01/70 00:00      
      How?            01/01/70 00:00      
         RE: How?            01/01/70 00:00      
         RE: How?            01/01/70 00:00      
            RE: How?            01/01/70 00:00      
      RE: Bad style - unwarranted restriction            01/01/70 00:00      
   RE: VB COM2 - Off topic            01/01/70 00:00      
   The Result            01/01/70 00:00      
      RE: The Result            01/01/70 00:00      
      RE: The Result            01/01/70 00:00      
   RE: VB COM2 - Off topic            01/01/70 00:00      
   The source code HERE.            01/01/70 00:00      
   Or the Whole achieve in Zip file            01/01/70 00:00      

Back to Subject List