📄 frmmain.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "邮编区号查询系统"
ClientHeight = 6210
ClientLeft = 3345
ClientTop = 1170
ClientWidth = 6540
Icon = "frmMain.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6210
ScaleWidth = 6540
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame3
Caption = "直接输入地名查询"
Height = 1215
Left = 135
TabIndex = 4
Top = 4875
Width = 6255
Begin VB.TextBox txtTel
Height = 285
Left = 1065
Locked = -1 'True
TabIndex = 13
Top = 810
Width = 1095
End
Begin VB.TextBox txtPostalCode
Height = 315
Left = 3360
Locked = -1 'True
TabIndex = 11
Top = 780
Width = 1215
End
Begin VB.TextBox txtProvince
Height = 300
Left = 4920
Locked = -1 'True
TabIndex = 9
Top = 315
Width = 1215
End
Begin VB.CommandButton cmdQuery
Caption = "查询"
Height = 330
Left = 2160
TabIndex = 7
Top = 285
Width = 615
End
Begin VB.TextBox txtName
Height = 300
Left = 1080
TabIndex = 5
Top = 315
Width = 975
End
Begin VB.Label Label4
Caption = "长途区号"
Height = 255
Left = 240
TabIndex = 12
Top = 840
Width = 855
End
Begin VB.Label Label3
Caption = "邮政编码"
Height = 255
Left = 2520
TabIndex = 10
Top = 840
Width = 855
End
Begin VB.Label Label2
Caption = "所属省、市、自治区"
Height = 255
Left = 3000
TabIndex = 8
Top = 360
Width = 1815
End
Begin VB.Label Label1
Caption = "地 名"
Height = 255
Left = 240
TabIndex = 6
Top = 360
Width = 735
End
End
Begin VB.Frame Frame2
Caption = "邮编与区号"
Height = 4575
Left = 2280
TabIndex = 2
Top = 120
Width = 4095
Begin VB.ListBox lstDetail
Height = 3840
Left = 120
TabIndex = 3
Top = 480
Width = 3735
End
Begin VB.Label Label7
Caption = "邮政编码"
Height = 255
Left = 2520
TabIndex = 16
Top = 240
Width = 855
End
Begin VB.Label Label6
Caption = "长途区号"
Height = 255
Left = 1320
TabIndex = 15
Top = 240
Width = 855
End
Begin VB.Label Label5
Caption = "地名"
Height = 255
Left = 240
TabIndex = 14
Top = 240
Width = 375
End
End
Begin VB.Frame Frame1
Caption = "省、市、自治区"
Height = 4575
Left = 120
TabIndex = 0
Top = 120
Width = 2055
Begin VB.ListBox lstProvince
Height = 4200
Left = 120
TabIndex = 1
Top = 240
Width = 1695
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Base 1
Private data() As String
Private intNum As Integer
Private Sub cmdQuery_Click()
Dim str1 As String
Dim i As Integer, j As Integer
str1 = Trim(txtName.Text)
For i = 1 To intNum
If InStr(data(1, i), str1) <> 0 Then
For j = 0 To lstProvince.ListCount - 1
If lstProvince.ItemData(j) > i Then
txtName.Text = data(1, i)
txtProvince.Text = lstProvince.List(j - 1)
txtPostalCode = data(3, i)
txtTel = data(2, i)
Exit Sub
End If
Next
txtName.Text = data(1, i)
txtProvince.Text = lstProvince.List(lstProvince.ListCount - 1)
txtPostalCode = data(3, i)
txtTel = data(2, i)
Exit Sub
End If
Next
MsgBox "对不起,没有此地名。", vbInformation
End Sub
Private Sub Form_Load()
Dim i As Integer, j As Integer
Dim str1 As String, str2 As String, str3 As String
Dim int1 As Integer, int2 As Integer, int3 As Integer
If Dir(App.Path & "\province.txt") <> "" Then '读入省名
Open App.Path & "\province.txt" For Input As 1
Do While Not EOF(1)
Input #1, int1, str1
lstProvince.AddItem str1
Loop
Close
Else
MsgBox "出错,province.txt文件不在当前目录下!", vbExclamation
Unload Me
End If
If Dir(App.Path & "\postalcode.txt") <> "" Then
Open App.Path & "\postalcode.txt" For Input As 1
i = 0
Do While Not EOF(1)
intNum = intNum + 1
ReDim Preserve data(3, intNum)
Input #1, str1
If Val(str1) <> 0 Then
i = i + 1
lstProvince.ItemData(i - 1) = intNum
Input #1, str1, str2, str3
Else
Input #1, str2, str3
End If
data(1, intNum) = str1
data(2, intNum) = str2
data(3, intNum) = str3
Loop
Close
Else
MsgBox "出错,postalcode.txt文件不在当前目录下!", vbExclamation
Unload Me
End If
End Sub
Private Sub lstProvince_Click()
Dim i As Integer, j As Integer
Dim str1 As String
lstDetail.Clear
If lstProvince.ListIndex < lstProvince.ListCount - 1 Then
For i = lstProvince.ItemData(lstProvince.ListIndex) To lstProvince.ItemData(lstProvince.ListIndex + 1) - 1
str1 = ""
str1 = data(1, i) & str1 & Space((7 - Len(data(1, i))) * 2) & data(2, i) & Space(12 - Len(data(2, i))) & data(3, i)
lstDetail.AddItem str1
Next
Else
For i = lstProvince.ItemData(lstProvince.ListIndex) To intNum
str1 = ""
str1 = data(1, i) & str1 & Space((7 - Len(data(1, i))) * 2) & data(2, i) & Space(12 - Len(data(2, i))) & data(3, i)
lstDetail.AddItem str1
Next
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -