?? frminit.frm
字號:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form FrmInit
Caption = "TC35連接與初始化設置"
ClientHeight = 2520
ClientLeft = 60
ClientTop = 450
ClientWidth = 5175
LinkTopic = "Form1"
ScaleHeight = 2520
ScaleWidth = 5175
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Cmdcancel
Caption = "退出系統"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 3840
TabIndex = 6
Top = 1680
Width = 1095
End
Begin VB.TextBox SMSCTxt
Height = 375
Left = 2160
TabIndex = 5
Top = 960
Width = 2055
End
Begin MSCommLib.MSComm MSComm1
Left = 4440
Top = 360
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton CmdQuit
Caption = "斷開"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2400
TabIndex = 3
Top = 1680
Width = 1215
End
Begin VB.CommandButton CmdConnect
Caption = "系統連接與初始化"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 2
Top = 1680
Width = 2055
End
Begin VB.ComboBox CmbPort
Height = 315
Left = 2160
TabIndex = 1
Top = 360
Width = 1935
End
Begin VB.Label Label2
Caption = "短消息中心號碼:"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 375
Left = 120
TabIndex = 4
Top = 960
Width = 1815
End
Begin VB.Label Label1
Caption = "請選擇您使用的端口:"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 255
Left = 120
TabIndex = 0
Top = 360
Width = 2295
End
End
Attribute VB_Name = "FrmInit"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Option Explicit
Dim port(5)
Private Function timedelay(n As Integer) '延時函數
Dim savetime As Double
savetime = timeGetTime()
While timeGetTime < savetime + n '循環等待
DoEvents '轉讓控制權,以便讓操作系統處理其它的事件
Wend
End Function
Private Function ATCMD(s1 As String, s2 As String) As Boolean
Dim dummyar As Integer
Dim receivebuffer As String, tmpbool As Boolean
MSComm1.InBufferCount = 0
MSComm1.Output = s1 + vbCr
timedelay (100)
If MSComm1.InBufferCount > 0 Then
receivebuffer = receivebuffer + MSComm1.Input
If InStr(receivebuffer, "OK") Then
tmpbool = True
End If
If InStr(receivebuffer, "ERROR") Then
tmpbool = False
End If
End If
ATCMD = tmpbool
End Function
Private Sub Cmdcancel_Click()
Unload Me
End
End Sub
Private Sub CmdConnect_Click()
Dim cs As String, cn As String, cf As String
Dim smscNO As String
On Error GoTo err
portitem = Val(CmbPort.Text) 'PortItem為全局變量,保存串行端口號
MSComm1.CommPort = portitem
MSComm1.PortOpen = True '打開端口
If Not ATCMD("AT", "連接測試") Then
GoTo connectFail
End If
MsgBox "連接成功!"
cn = "AT+CNMI=2,1,0,0,1"
If SMSCTxt.Text = "" Then
GoTo smscfail
Else
smscNO = Trim(SMSCTxt.Text)
cs = "AT+CSCA=" & Chr$(34) & smscNO & Chr$(34)
SMSCTxt.Enabled = False
End If
cf = "AT+CMGF=0"
If Not ATCMD(cn, "選擇新的短消息提示") Then
GoTo InitFail
End If
If Not ATCMD(cs, "短消息服務中心號碼設置") Then
GoTo InitFail
End If
If Not ATCMD(cf, "選擇短消息支持文字格式") Then
GoTo InitFail
End If
MsgBox "初始化正常!"
Unload Me
Exit Sub
err:
MsgBox "對不起,您選擇的端口已經被打開,請選擇別的端口", vbOKOnly, "通知"
Exit Sub
connectFail: MsgBox "連接失敗!"
Exit Sub
InitFail: MsgBox "初始化出錯!"
Exit Sub
smscfail: MsgBox "請輸入短消息中心號碼!"
End Sub
Private Sub CmdQuit_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
SMSCTxt.Enabled = True
End Sub
Private Sub Form_Load()
Dim i As Integer
port(0) = "1"
port(1) = "2"
port(2) = "3"
port(3) = "4"
port(4) = "5"
For i = 0 To 4
CmbPort.AddItem port(i)
Next i
CmbPort.ListIndex = 0
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -