AjaxVS
Сравни 2 варианта, предложенные алибеком и тебе откроется Дао, и увидишь ты что Shell "ping > c:\buff" не пишет в файл, а лишь выводит окно консоли
"exe > txt"
=== Закусили тут ===
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (ofnFile As OpenFileName) As Long
Public Const OFN_FileEx = &H1000
Public Const OFN_ReadOnly = &H1
Public Const OFN_HideRO = &H4
Type OpenFileName
lStructSize As Long ' Длина типа данных
hwndOwner As Long ' Окно ПОД диалогом
hinstance As Long '?
sFilter As String ' Фильтр(ы)
sCustomFilter As String '?
lMaxCustFilters As Long '?
lFilterIndex As Long ' 1, если исп.фильтр
sInputFile As String ' Выбранный пользователем путь\файл
lMaxLenFile As Long ' Длина предыдущей строки
sFileName As String ' Имя файла без пути
lMaxFileTitle As Long '?
sDefDir As String ' Путь по умолчанию
sTitle As String ' Заголовок окна диалога
lFlags As Long ' Флаги файла
iFileOffset As Integer '?
iFileExt As Integer '?
sDefExt As String ' Расширение по умолчанию
lCustData As Long '?
lHook As Long '?
lTempName As Long '?
End Type
Public Function fsInputFileName(Optional vExtFile, Optional vDefDir, _
Optional vFilter, Optional vTitle) As String
Dim i As Integer
Dim sNewFileName As String
Dim sNewTitle As String
Dim sNewFilter As String
Dim sNewExt As String
Dim sNewDefDir As String
Dim ofnDialog As OpenFileName
sNewFileName = String$(512, 0)
sNewDefDir = fsDef(CurDir$, vDefDir)
sNewTitle = fsDef("Открытие файла", vTitle)
sNewFilter = _
fsDef("Все файлы" & Chr$(0) & "*.*" & Chr$(0), vFilter) & Chr$(0)
sNewExt = fsDef("", vExtFile)
With ofnDialog
.lStructSize = Len(ofnDialog)
.hwndOwner = Screen.ActiveForm.Hwnd
.sFilter = sNewFilter
.lFilterIndex = 1
.sInputFile = sNewFileName
.lMaxLenFile = Len(sNewFileName)
.sDefDir = sNewDefDir
.sTitle = sNewTitle
.lFlags = OFN_FileEx ' Or OFN_ReadOnly
.sDefExt = sNewExt
i = GetOpenFileName(ofnDialog)
If i <> 0 Then ' отделение Null-значений
fsInputFileName = Left$(.sInputFile, InStr(.sInputFile, Chr$(0)) - 1)
Else
fsInputFileName = ""
End If
End With
End Function
'
Возвращает строку, преобразуя ее из второго входного параметра, если
' он существует. В противном случае возвращает строку, передаваемую
' в функцию первым параметром.
Public Function fsDef(sStrDef As String, Optional vValue) As String
Dim sStr As String
If IsMissing(vValue) Then
sStr = sStrDef
Else
sStr = vValue
End If
fsDef = Z(sStr)
End Function
=== Кончили закусывать, выпили опять ===
Private Declare Function GetOpenFileName Lib "comdlg32" Alias "GetOpenFileNameA" (pOPENFILENAME As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (ByRef pOPENFILENAME As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustomFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As String
lpstrFileTitle As String
nMaxFileTitle As String
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Function funAjDlgFile(s_title As String, Optional s_filter As String = "", Optional s_filter_all As String = "All Files" + vbNullChar + "*.*" + vbNullChar, Optional i_save As Byte = 0) As String
Dim st_file As OPENFILENAME
Dim s_name As String
Dim i_val As Long
With st_file
.lStructSize = Len(st_file)
.lpstrTitle = s_title
.lpstrFile = Space(255)
.nMaxFile = 255
.hwndOwner = 0 'can edit
.lpstrFilter = s_filter + s_filter_all 'can edit
End With
If i_save = 0 Then
i_val = GetOpenFileName(st_file)
Else
i_val = GetSaveFileName(st_file)
End If
If i_val = 0 Then
funAjDlgFile = ""
Exit Function
End If
s_name = Left$(st_file.lpstrFile, InStr(1, st_file.lpstrFile, vbNullChar) - 1)
funAjDlgFile = s_name
End Function
Private Sub Form_Click()
Dim s As String
s = funAjDlgFile("Имитация сохранения файла..", "Text Files" + vbNullChar + "*.txt" + vbNullChar, , 1)
If Len(s) = 0 Then Exit Sub
Print "Выбран файл: " & s
End Sub
Сейчас этот форум просматривают: AhrefsBot, SemrushBot, Yandex-бот и гости: 39