极其简单的一个条件判断小程序

6 提交 / 0个新回复
最新回复
极其简单的一个条件判断小程序

以下代码该存在文本文档,改扩展名为form1.frm即可运行

旁边新建一个叫 条件.txt 的文件

文件内容如下(动态添加的,随便加点即可)

-------------------
111@#¥222
333@#¥444
55@#¥66
77@#¥88
99@#¥00
1@#¥2
你好@#¥你也好
你叫什么名字@#¥我叫AI001
你名字是@#¥我名字是AI001
上帝存在么@#¥存在,你制造了我,你就是上帝
机器学习的精髓是什么@#¥机器学习的精髓在于自动化和智能化
--------------------
 

VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2985
ClientLeft = 60
ClientTop = 450
ClientWidth = 7830
LinkTopic = "Form1"
ScaleHeight = 2985
ScaleWidth = 7830
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text3
Height = 2775
Left = 4200
MultiLine = -1 'True
TabIndex = 2
Top = 120
Width = 3495
End
Begin VB.TextBox Text2
Height = 375
Left = 240
TabIndex = 1
Top = 2520
Width = 3855
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 2415
Left = 240
MultiLine = -1 'True
TabIndex = 0
Top = 120
Width = 3855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim ss1() As String
Dim ss2() As String
Dim A() As String
Dim B() As String
Dim i, ii As Single
Dim 判断是否有储备 As Boolean
Dim 输入状态 As String
Dim 命令缓存 As String

Private Sub Form_Load()
Text3.Text = GetTxtFile(App.Path & "\条件.txt")
Text3 = 去除回车(Text3)
输入状态 = "输入"
End Sub

Public Function GetTxtFile(ByVal fName As String) As String
On Error Resume Next
Open fName For Input As #1
GetTxtFile = StrConv(InputB(LOF(1), 1), vbUnicode)
'函数返回TXT文本内容
Close #1
End Function

Public Function 去除回车(str As String) As String
If Len(str) > 2 Then
Do While Mid(str, Len(str) - 1, 2) = Chr(13) + Chr(10) '''去除多余回车
str = Mid(str, 1, Len(str) - 2)
Do While Mid(str, Len(str), 1) = "@#¥" '''去除多余"@#¥"
str = Mid(str, 1, Len(str) - 1)
Loop
Loop
去除回车 = str
End If
End Function

Public Sub SaveTxtFile(str As String, ByVal fName As String)
On Error Resume Next
Open fName For Output As #1 'save
Print #1, str
Close 1
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then

If 输入状态 = "输入" Then

拆分文章

'Text1 = ss1(0) & ss2(0) & ss1(1) & ss2(1)

判断是否有储备 = False
For i = LBound(A) To UBound(A)
If Text2 = ss1(i) Then
Text1 = ss2(i)
判断是否有储备 = True
End If
Next i

If 判断是否有储备 = False Then
Text1 = "无此命令,是否进入学习状态?(y/n)"
命令缓存 = Text2
输入状态 = "判断"
End If

ElseIf 输入状态 = "判断" Then

If Text2 = "y" Or Text2 = "Y" Or Text2 = "是" Then
输入状态 = "学习"
Text1 = "现在是学习状态,请您输入“" & 命令缓存 & "”的解释"
Else
输入状态 = "输入"
命令缓存 = ""
Text1 = "请继续输入其他命令"
End If

ElseIf 输入状态 = "学习" Then

Text3 = Text3 & Chr(13) & Chr(10) & 命令缓存 & "@#¥" & Text2
Text1 = "感谢您的协助,“" & 命令缓存 & "”的解释是“" & Text2 & "”。"

输入状态 = "输入"

End If

Text2 = ""

End If
End Sub

Private Sub Text3_Change()
Call SaveTxtFile(Text3.Text, App.Path & "\条件.txt")
End Sub

Sub 拆分文章()

Erase A()
Erase B()

A() = Split(Text3.Text, Chr(13) & Chr(10), -1, vbTextCompare)

ReDim ss1(UBound(A)) As String
ReDim ss2(UBound(A)) As String

For i = LBound(A) To UBound(A)

B() = Split(A(i), "@#¥", -1, vbTextCompare)

'For ii = LBound(B) To UBound(B)
'Next ii

ss1(i) = B(0)
ss2(i) = B(1)

Next i

End Sub

 

by:冰 星之雨