How can I send to Private Sub Label26_Click a MSComm1 object  
Author Message
yanivpinhas





PostPosted: Visual Basic Express Edition, How can I send to Private Sub Label26_Click a MSComm1 object Top

Hi,

I defined MScomm1 in form1_load and I want to use him or to close him

when the user click on the label26, how can I do it

here is how I defined MSComm1:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim MSComm1 As System.IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort(1, 19200, 0, 8, 1)

End Sub

Private Sub Label26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label26.Click

' here I want to close Mscomm1 or to change him

'Or to change the port number  and this change will take effect on the all program

'

End Sub

 

Regards,

Yaniv

 

 



Visual Studio Express Editions39  
 
 
yanivpinhas





PostPosted: Visual Basic Express Edition, How can I send to Private Sub Label26_Click a MSComm1 object Top

Any ideas


 
 
DMan1





PostPosted: Visual Basic Express Edition, How can I send to Private Sub Label26_Click a MSComm1 object Top

 

Private MSComm1 As System.IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort(1, 19200, 0, 8, 1)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Label26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label26.Click

MSComm1.Close()

End Sub

 

Make MSComm1 a class level variable



 
 
nobugz





PostPosted: Visual Basic Express Edition, How can I send to Private Sub Label26_Click a MSComm1 object Top

You've made it a local variable of the Load event. Make it a member of the form:

Imports System.IO.Ports
Public Class Form1
Private WithEvents mscomm1 As SerialPort
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
mscomm1 = My.Computer.Ports.OpenSerialPort("COM1", 19200, Parity.None, 1, StopBits.One)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
mscomm1.WriteLine("Hello world")
End Sub
Private Sub mscomm1_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles mscomm1.DataReceived
'--- Handle received data...
End Sub
End Class



 
 
yanivpinhas





PostPosted: Visual Basic Express Edition, How can I send to Private Sub Label26_Click a MSComm1 object Top

thank you all..

Best Regards,

Yaniv