level 7
peeppp
楼主
使用几个AIGPT(chatgpt,文心一言),给关键词,要求编一个程序,试下效果,换了几个AI,都有语法错误,烦请大侠能不能看看这代码是不是按我要求写的?出错的那2处代码怎么改?
==========================================
编一个VB6.0程序,功能是:上面有两个文本框text1和text2,两个按钮Command1和Command2,一个Combo1,将 filePath = "d:\t1.txt" 设为全局变量进行调用,在text1和text2中分别输入内容后,点击 Command1按钮就将text1和text2存入d:\t1.txt中,每次一行,可以无限次点击并保存,在text1中输入内容,点Command2就遍历d:\t1.txt,找到对应的内容加载到text2中,而combo1中可以实时显示出t1.txt中text1段中的内容,这样可以快速选择,以达到在text1中输入内容点击Command2同样的效果,注意不要出现 Exit While 语法错误 ,如果点击Command1时,text1中输入的内容与 t1.txt中text1段相同时,用msgbox提示“存在重复内容”,只有不重复的才能保存。
===========================================



Dim filePath As String
Private Sub Form_Load()
filePath = "d:\t1.txt" '设定全局变量
End Sub
Private Sub Command1_Click()
Dim txt1 As String, txt2 As String
Dim fileNum As Integer
txt1 = Text1.Text
txt2 = Text2.Text
If txt1 = "" Or txt2 = "" Then '如果text1或text2中有一个为空则提示错误
MsgBox "请输入内容!", vbExclamation
Exit Sub
End If
fileNum = FreeFile '打开文件
Open filePath For Append As fileNum
Dim lineText As String
Dim flag As Boolean
flag = False
While Not EOF(fileNum) '遍历文件
Line Input #fileNum, lineText
Dim pos As Integer
pos = InStr(lineText, ":") '查找冒号分隔符位置
Dim str1 As String
str1 = Trim(Left(lineText, pos - 1)) '获取text1部分的内容
If str1 = txt1 Then '如果存在重复内容则退出
flag = True
MsgBox "存在重复内容!", vbExclamation
Exit While
End If
Wend
If Not flag Then '如果没有重复内容则将text1和text2写入文件
Print #fileNum, txt1 & ": " & txt2
End If
Close fileNum '关闭文件
Text1.Text = "" '清空text1和text2
Text2.Text = ""
End Sub
Private Sub Command2_Click()
Dim fileNum As Integer, lineText As String
Combo1.Clear
fileNum = FreeFile '打开文件
Open filePath For Input As fileNum
While Not EOF(fileNum) '遍历文件
Line Input #fileNum, lineText
Dim pos As Integer
pos = InStr(lineText, ":") '查找冒号分隔符位置
Dim str1 As String, str2 As String
str1 = Trim(Left(lineText, pos - 1)) '获取text1部分的内容
str2 = Trim(Right(lineText, Len(lineText) - pos)) '获取text2部分的内容
Combo1.AddItem str1 '将text1部分的内容添加到Combo1中
Wend
Close fileNum '关闭文件
End Sub
Private Sub Combo1_Click()
Dim fileNum As Integer, lineText As String
fileNum = FreeFile '打开文件
Open filePath For Input As fileNum
While Not EOF(fileNum) '遍历文件
Line Input #fileNum, lineText
Dim pos As Integer
pos = InStr(lineText, ":") '查找冒号分隔符位置
Dim str1 As String, str2 As String
str1 = Trim(Left(lineText, pos - 1)) '获取text1部分的内容
str2 = Trim(Right(lineText, Len(lineText) - pos)) '获取text2部分的内容
If str1 = Combo1.Text Then '如果找到了对应的text1内容则显示text2的内容并退出循环
Text2.Text = str2
Exit While
End If
Wend
Close fileNum '关闭文件
End Sub
2023年05月25日 00点05分
1
==========================================
编一个VB6.0程序,功能是:上面有两个文本框text1和text2,两个按钮Command1和Command2,一个Combo1,将 filePath = "d:\t1.txt" 设为全局变量进行调用,在text1和text2中分别输入内容后,点击 Command1按钮就将text1和text2存入d:\t1.txt中,每次一行,可以无限次点击并保存,在text1中输入内容,点Command2就遍历d:\t1.txt,找到对应的内容加载到text2中,而combo1中可以实时显示出t1.txt中text1段中的内容,这样可以快速选择,以达到在text1中输入内容点击Command2同样的效果,注意不要出现 Exit While 语法错误 ,如果点击Command1时,text1中输入的内容与 t1.txt中text1段相同时,用msgbox提示“存在重复内容”,只有不重复的才能保存。
===========================================



Dim filePath As StringPrivate Sub Form_Load()
filePath = "d:\t1.txt" '设定全局变量
End Sub
Private Sub Command1_Click()
Dim txt1 As String, txt2 As String
Dim fileNum As Integer
txt1 = Text1.Text
txt2 = Text2.Text
If txt1 = "" Or txt2 = "" Then '如果text1或text2中有一个为空则提示错误
MsgBox "请输入内容!", vbExclamation
Exit Sub
End If
fileNum = FreeFile '打开文件
Open filePath For Append As fileNum
Dim lineText As String
Dim flag As Boolean
flag = False
While Not EOF(fileNum) '遍历文件
Line Input #fileNum, lineText
Dim pos As Integer
pos = InStr(lineText, ":") '查找冒号分隔符位置
Dim str1 As String
str1 = Trim(Left(lineText, pos - 1)) '获取text1部分的内容
If str1 = txt1 Then '如果存在重复内容则退出
flag = True
MsgBox "存在重复内容!", vbExclamation
Exit While
End If
Wend
If Not flag Then '如果没有重复内容则将text1和text2写入文件
Print #fileNum, txt1 & ": " & txt2
End If
Close fileNum '关闭文件
Text1.Text = "" '清空text1和text2
Text2.Text = ""
End Sub
Private Sub Command2_Click()
Dim fileNum As Integer, lineText As String
Combo1.Clear
fileNum = FreeFile '打开文件
Open filePath For Input As fileNum
While Not EOF(fileNum) '遍历文件
Line Input #fileNum, lineText
Dim pos As Integer
pos = InStr(lineText, ":") '查找冒号分隔符位置
Dim str1 As String, str2 As String
str1 = Trim(Left(lineText, pos - 1)) '获取text1部分的内容
str2 = Trim(Right(lineText, Len(lineText) - pos)) '获取text2部分的内容
Combo1.AddItem str1 '将text1部分的内容添加到Combo1中
Wend
Close fileNum '关闭文件
End Sub
Private Sub Combo1_Click()
Dim fileNum As Integer, lineText As String
fileNum = FreeFile '打开文件
Open filePath For Input As fileNum
While Not EOF(fileNum) '遍历文件
Line Input #fileNum, lineText
Dim pos As Integer
pos = InStr(lineText, ":") '查找冒号分隔符位置
Dim str1 As String, str2 As String
str1 = Trim(Left(lineText, pos - 1)) '获取text1部分的内容
str2 = Trim(Right(lineText, Len(lineText) - pos)) '获取text2部分的内容
If str1 = Combo1.Text Then '如果找到了对应的text1内容则显示text2的内容并退出循环
Text2.Text = str2
Exit While
End If
Wend
Close fileNum '关闭文件
End Sub