如何自动选择文件?
使用VB6
现在我使用软件中的浏览按钮来选择文本文件,然后将其转换为mdb(access)。我不想选择文本文件。
一旦我在任何系统中安装了软件,文本文件就会自动选择指定的路径。然后文本文件自动转换为mdb。转换为 mdb 后,然后
将文本转换为 mdb 的 Vb 代码。
Dim db As Database, tbl As TableDef
Set db = DBEngine.OpenDatabase(App.Path & "\History.mdb")
Set tbl = db.CreateTableDef("Temp")
tbl.Connect = "Text;database=" & App.Path & "/ConvTemp/"
tbl.SourceTableName = strOutput & ".txt"
db.TableDefs.Append tbl
db.Execute "Select Temp.ID, Temp.IDTerminal, Temp.Reader, Temp.Date, Temp.Time, Temp.Cardnumber into " & strOutput & " from Temp"
db.TableDefs.Delete ("Temp")
db.Close
MsgBox strOutput
sql2 = "insert into events select * from " & strOutput & ""
If rs.State = 1 Then rs.Close
rs.Open sql2, Cn, adOpenStatic, adLockOptimistic
Set tbl = Nothing
Set db = Nothing
上面的代码适用于文本到 mdb 的转换。但我需要自动转换文本文件而不使用浏览按钮。
例如,
MDB 名称为 – History.mdb,表名称为 – event.mdb
我设置了这样的路径“C:\NewFolder” 在我的软件中
,在上述文件夹中,文本文件将以不同的名称出现。文本文件每天可能会出现 10 到 20 个具有新的不同名称的文本文件。我也无法给出文本文件名。我只需提供扩展名,如 (*.txt)。
一旦我安装了我的软件,该软件应该从 c:\NewFolder 中选择文本文件,然后它会自动转换为 mdb,转换后的文本文件应该自动删除。
预期输出
Once I installed my software in any system, the software should select the text file from the specified folder, then the text file convert into mdb. Once converted, the text files automatically delete from the specified path.
为了将文本转换为 mdb,我有代码,为了自动选择文本文件,我需要示例代码或想法,
我是 VB6 的新手,任何人都可以给出一些如何做到这一点的想法。或者可以发布自动选择文本文件的示例代码。
请。
Using VB6
Now I am using a Browse button in my software to select the text file, then it is converted in to mdb (access). I don’t want to select the text file.
Once I installed my software in any system, the text file should automatically select in a specified path. Then the text file automatically converts into mdb. Once converted in to mdb then
Vb Code for converting text to mdb.
Dim db As Database, tbl As TableDef
Set db = DBEngine.OpenDatabase(App.Path & "\History.mdb")
Set tbl = db.CreateTableDef("Temp")
tbl.Connect = "Text;database=" & App.Path & "/ConvTemp/"
tbl.SourceTableName = strOutput & ".txt"
db.TableDefs.Append tbl
db.Execute "Select Temp.ID, Temp.IDTerminal, Temp.Reader, Temp.Date, Temp.Time, Temp.Cardnumber into " & strOutput & " from Temp"
db.TableDefs.Delete ("Temp")
db.Close
MsgBox strOutput
sql2 = "insert into events select * from " & strOutput & ""
If rs.State = 1 Then rs.Close
rs.Open sql2, Cn, adOpenStatic, adLockOptimistic
Set tbl = Nothing
Set db = Nothing
Above code is working for text to mdb conversion. But I need to convert the text file automatically without using browse button.
For Example
MDB Name is – History.mdb and table name is – event.mdb
I set a path like this “C:\NewFolder” In my software
In the above folder, the text file will appear with different names. May be per day text file will appear 10 to 20 text files with new different names. I cannot able to give the text file name also. I have to give only the extension like (*.txt).
Once I installed my software, the Software should select the text file from c:\NewFolder, then it automatically converts in to mdb, after converted the text file the text file should delete automatically.
Expected Output
Once I installed my software in any system, the software should select the text file from the specified folder, then the text file convert into mdb. Once converted, the text files automatically delete from the specified path.
For converting text to mdb am having the code, for automatically selecting the text file I need a sample code or idea’s
Am new to VB6, Can any one give some idea how to do this. Or can any post a sample code for automatically selection of text file.
Please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本代码看起来如下:
上面的代码假设在您的 C:\NewFolder 中您只有 *.txt 文件,没有其他文件或文件夹。
华泰
Basic code would look something down the lines of this:
The above code assumes that in your C:\NewFolder you will only have *.txt files and no other files or folders.
HTH