Comprehensive CAN monitor for Windows® and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
-
MarkSPS
- Posts: 2
- Joined: Tue 11. Oct 2016, 12:43
Post
by MarkSPS » Thu 13. Oct 2016, 16:43
Hi,
In my project I need to open a file for Text Streaming
Code: Select all
' Open file for input streaming
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, f, ts
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile("C:\test\test.csv")
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Is there an OpenFileDialog feature available so that the user can select the file to open instead of simply a fixed filename in the code above?
Thanks
-
PEAK-Support
- Sales & Support

- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Post
by PEAK-Support » Fri 14. Oct 2016, 12:39
Herse some sample VBS code that we found in the WEB and changed it for our need.
It´s also depending on the used OS if the sample work or not!
Please keep in minde --> this have nothing to do with our PCAN-Explorer 4/5/6 - this is VBS!
We could not do Standard VBS support in this forum - so use it as it is - change it for your need
1. use a SUB "TestGetFileName" which call 2 differnet type of open a file with a Dialog (Function
GetFileName1 and the Function
GetFileName2)
Code: Select all
Dim sFileSelected
Sub TestGetFileName
PrintToOutputWindow "call GetFileName1:"
GetFileName1
PrintToOutputWindow sFileSelected
PrintToOutputWindow "call GetFileName2:"
GetFileName2
PrintToOutputWindow sFileSelected
End Sub
Function GetFileName1
Set wShell=CreateObject("WScript.Shell")
Set oExec=wShell.Exec("mshta.exe ""about:<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
sFileSelected = oExec.StdOut.ReadLine
End Function
Function GetFileName2
Set oExec=CreateObject("WScript.Shell").Exec( "mshta.exe ""about:" & "<" & "input type=file id=FILE>" & "<" & "script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);" & "<" & "/script>""" )
Tst = oExec.StdOut.ReadAll
Tst = Replace( Tst, vbCRLF, "" )
MsgBox "==" & Tst & "=="
End Function
2. Using an alternative Version of opening a file
Code: Select all
Sub Browse4Files()
Dim objShell
Dim objFolder
Dim objFolderItem
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Choose a file:", &H4000, "C:\")
If (objFolder Is Nothing) Then
PrintToOutputWindow "no file selected"
Else
Set objFolderItem = objFolder.Self
Selection = objFolderItem.Path
PrintToOutputWindow "Selected file: " & Selection
End If
Set objShell = Nothing
Set objFolder = Nothing
Set objFolderItem = Nothing
End Sub
More samples could be found by g**gle the WEB
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
-
MarkSPS
- Posts: 2
- Joined: Tue 11. Oct 2016, 12:43
Post
by MarkSPS » Fri 14. Oct 2016, 15:39
Hi Uwe,
Thanks for your reply and help. The examples work well.
Thanks