VB怎样从文本文件中读取数据然后再下拉框中
发布网友
发布时间:2024-10-08 01:27
我来回答
共2个回答
热心网友
时间:2024-10-31 04:14
将1.txt文件内容稍微改动了下,exe后面为exe绝对路径,如
name=1
exe=C:\Program Files\Tencent\QQ\Bin\QQ.exe
使用了FileSystemObject 、wscript shell对象模型实现
Private Sub Command1_Click()
Dim fso, wsh, file
Dim fid As String
Dim app As String
If Combo1.Text = 0 Then
MsgBox ("重新选择")
Else
Set fso = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("wscript.shell")
Set file = fso.opentextfile("c:\\1.txt")
While (Not file.AtEndOfLine)
fid = file.readline
If InStr(1, fid, "name=" & Combo1.Text, 1) <> 0 Then
fid = file.readline
app = Mid(fid, 5)
End If
Wend
wsh.run (Chr(34) & app & Chr(34))
End If
End Sub
热心网友
时间:2024-10-31 04:14
dim exe(20) as string
open "1.txt" for input as #1
dim str as string
do while not eof(1)
line write #1,str
if mid(str,1,4)="name" then
combo1.additem mid(str,6,1)
do while
line write #1,str
if mid(str,1,3)="exe" then
exe(combo1.listcount-1)=mid(str,5,len(str)-4)
exit do
end if
loop
end if
loop
close #1
combo1_click部分
shell app.path & exe(combo1.listindex)