Dim buffer As String
Option Explicit
Private Sub Command1_Click()
Dim initial As String
Label2.Caption = "at+cmgs=" + Text2.Text + "
If Text2.Text = "" Then Exit Sub
XMComm1.Output = "at+cmgs=" & Text2.Text & Chr$(13)
Do
DoEvents
buffer$ = buffer$ & XMComm1.InputData
Loop Until InStr(buffer$, ">" & vbCrLf)
Text1.Text = buffer$
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
If Text3.Text = "" Then Exit Sub 'Avslutar sub om text3 är tom
XMComm1.Output = Text3.Text & Chr$(26)
avläsning
If Not buffer$ = "" Then
Text1.Text = buffer$
Else
buffer$ = buffer$ & XMComm1.InputData
GoTo avläsning 'loopar till avläsning
End If
End Sub
Private Sub Command3_Click() 'Vid avlsutning skall porten stängas
If XMComm1.PortOpen Then XMComm1.PortOpen = False
End
End Sub
Private Sub Form_Load()
Dim buffer As String
On Error Resume Next
XMComm1.CommPort = 1 'Porten som ska testas
XMComm1.PortOpen = True
If Err.Number > 0 Then
Err.Number = 0
XMComm1.CommPort = 2 'Öppnar port 2 om inte com 1 fungerar
XMComm1.PortOpen = True
If Err.Number > 0 Then
MsgBox "Could not open port 1 or 2.", vbExclamation
Exit Sub
End If
End If
Me.Caption = "Använder Com" & Format$(XMComm1.CommPort)
XMComm1.Settings = "9600, N, 8, 1" 'Sätter port inställningar
End Sub
Private Sub Text2_Change()
Label2.Caption = "at+cmgs=" + Text2.Text
End Sub
Private Sub Form_Unload(Cancel As Integer) 'När fönster stängs, stängs porten
On Error Resume Next
If XMComm1.PortOpen Then XMComm1.PortOpen = False
End Sub