|
Private iFlow As Integer, iTempEcho As Boolean
Sub LoadPropertySettings()
Dim i As Integer, Settings As String, Offset As Integer
' Load Port Settings
For i = 1 To 16
cboPort.AddItem "Com" & Trim$(Str$(i))
Next i
' Load Speed Settings
cboSpeed.AddItem "110"
cboSpeed.AddItem "300"
cboSpeed.AddItem "600"
cboSpeed.AddItem "1200"
cboSpeed.AddItem "2400"
cboSpeed.AddItem "4800"
cboSpeed.AddItem "9600"
cboSpeed.AddItem "14400"
cboSpeed.AddItem "19200"
cboSpeed.AddItem "28800"
cboSpeed.AddItem "38400"
cboSpeed.AddItem "56000"
cboSpeed.AddItem "57600"
cboSpeed.AddItem "115200"
cboSpeed.AddItem "128000"
cboSpeed.AddItem "256000"
' Load Data Bit Settings
cboDataBits.AddItem "4"
cboDataBits.AddItem "5"
cboDataBits.AddItem "6"
cboDataBits.AddItem "7"
cboDataBits.AddItem "8"
' Load Parity Settings
cboParity.AddItem "Even"
cboParity.AddItem "Odd"
cboParity.AddItem "None"
cboParity.AddItem "Mark"
cboParity.AddItem "Space"
' Load Stop Bit Settings
cboStopBits.AddItem "1"
cboStopBits.AddItem "1.5"
cboStopBits.AddItem "2"
' Set Default Settings
Settings = Form1.MSComm1.Settings
' In all cases the right most part of Settings will be 1 character
' except when there are 1.5 stop bits.
If InStr(Settings, ".") > 0 Then
Offset = 2
Else
Offset = 0
End If
cboSpeed.Text = Left$(Settings, Len(Settings) - 6 - Offset)
Select Case Mid$(Settings, Len(Settings) - 4 - Offset, 1)
Case "e"
cboParity.ListIndex = 0
Case "m"
cboParity.ListIndex = 1
Case "n"
cboParity.ListIndex = 2
Case "o"
cboParity.ListIndex = 3
Case "s"
cboParity.ListIndex = 4
End Select
cboDataBits.Text = Mid$(Settings, Len(Settings) - 2 - Offset, 1)
cboStopBits.Text = Right$(Settings, 1 + Offset)
cboPort.ListIndex = Form1.MSComm1.CommPort - 1
optFlow(Form1.MSComm1.Handshaking).Value = True
If Echo Then
optEcho(1).Value = True
Else
optEcho(0).Value = True
End If
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim OldPort As Integer, ReOpen As Boolean
On Error Resume Next
Echo = iTempEcho
OldPort = Form1.MSComm1.CommPort
NewPort = cboPort.ListIndex + 1
If NewPort <> OldPort Then ' If the port number changes, close the old port.
If Form1.MSComm1.PortOpen Then
Form1.MSComm1.PortOpen = False
ReOpen = True
End If
Form1.MSComm1.CommPort = NewPort ' Set the new port number.
If Err = 0 Then
If ReOpen Then
Form1.MSComm1.PortOpen = True
End If
End If
If Err Then
MsgBox Error$, 48
Form1.MSComm1.CommPort = OldPort
Exit Sub
End If
End If
Form1.MSComm1.Settings = Trim$(cboSpeed.Text) & "," & Left$(cboParity.Text, 1) _
& "," & Trim$(cboDataBits.Text) & "," & Trim$(cboStopBits.Text)
If Err Then
MsgBox Error$, 48
Exit Sub
End If
Form1.MSComm1.Handshaking = iFlow
If Err Then
MsgBox Error$, 48
Exit Sub
End If
SaveSetting App.Title, "Properties", "Settings", Form1.MSComm1.Settings
SaveSetting App.Title, "Properties", "CommPort", Form1.MSComm1.CommPort
SaveSetting App.Title, "Properties", "Handshaking", Form1.MSComm1.Handshaking
Form1.Label2 = Form1.MSComm1.Settings
Form1.Label4 = Form1.MSComm1.CommPort
Form1.Label6 = Form1.MSComm1.Handshaking
Unload Me
End Sub
Private Sub Form_Load()
' Set the form's size
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
' Make sure the frame is the top most control
fraSettings.ZOrder
' Load current property settings
LoadPropertySettings
End Sub
Private Sub optEcho_Click(Index As Integer)
If Index = 1 Then
iTempEcho = True
Else
iTempEcho = False
End If
End Sub
Private Sub optFlow_Click(Index As Integer)
iFlow = Index
End Sub