📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form frmStringCompare
Caption = "Comparing strings with StrComp"
ClientHeight = 2790
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 2790
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.ListBox lstOutput
Height = 645
Left = 0
TabIndex = 6
Top = 2160
Width = 4695
End
Begin VB.TextBox txtInput2
Height = 285
Left = 0
TabIndex = 4
Top = 960
Width = 4695
End
Begin VB.TextBox txtInput1
Height = 285
Left = 0
TabIndex = 2
Top = 360
Width = 4695
End
Begin VB.CommandButton cmdCompare
Caption = "Compare"
Height = 375
Left = 0
TabIndex = 1
Top = 1320
Width = 1815
End
Begin VB.Label lblOutput
Height = 255
Left = 0
TabIndex = 5
Top = 1800
Width = 4695
End
Begin VB.Label lblInput2
Caption = "Enter second string"
Height = 255
Left = 0
TabIndex = 3
Top = 720
Width = 2415
End
Begin VB.Label lblInput1
Caption = "Enter first string"
Height = 255
Left = 0
TabIndex = 0
Top = 120
Width = 2295
End
End
Attribute VB_Name = "frmStringCompare"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 8.1
' Comparing strings with StrComp,
' relational and equality operators
Option Explicit
Private Sub cmdCompare_Click()
Dim result As Integer
result = StrComp(txtInput1.Text, txtInput2.Text)
If result = -1 Then
lblOutput.Caption = _
"The first string is less than the second string"
ElseIf result = 1 Then
lblOutput.Caption = _
"The first string is greater than the second string"
Else
lblOutput.Caption = "The strings are equal"
End If
Call lstOutput.Clear
If txtInput1.Text = txtInput2.Text Then
Call lstOutput.AddItem(txtInput1.Text & " is equal to " & _
txtInput2.Text)
End If
If txtInput1.Text <> txtInput2.Text Then
Call lstOutput.AddItem(txtInput1.Text & _
" is not equal to " & txtInput2.Text)
End If
If txtInput1.Text < txtInput2.Text Then
Call lstOutput.AddItem(txtInput1.Text & _
" is less than " & txtInput2.Text)
End If
If txtInput1.Text > txtInput2.Text Then
Call lstOutput.AddItem(txtInput1.Text & _
" is greater than " & txtInput2.Text)
End If
If txtInput1.Text <= txtInput2.Text Then
Call lstOutput.AddItem(txtInput1.Text & _
" is less than or equal to " & _
txtInput2.Text)
End If
If txtInput1.Text >= txtInput2.Text Then
Call lstOutput.AddItem(txtInput1.Text & _
" is greater than or equal to " & _
txtInput2.Text)
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -