Сайт Алексея Муртазина (Star Cat) E-mail: starcat-rus@yandex.ru
Мои программы Новости сайта Мои идеи Мои стихи Форум Об авторе
VB коды Статьи о VB6 API функции Самоучитель по VB.NET
Собрания сочинений Обмен ссылками Все работы с фото и видео
О моём деде Муртазине ГР Картинная галерея «Дыхание души»
Звёздный Кот

49 Стандартное окно Windows
для открытия и сохранения файла
Private Sub MenuOpen_Click()
Dim H As String, strFilter As String, F As Long, Razshirenie As String
Razshirenie = ".txt"
strFilter = "Блокнот (*.txt)" & Chr(0) & "*.txt" & Chr(0) & "All Files (*.*)" & Chr(0) & "*.*"
H = OpenSave(False, vbNullString, strFilter)
If Len(H) = 0 Then Exit Sub
If InStr(H, ".") = 0 Then H = H & Razshirenie
On Error Resume Next
Open H For Input As #1
F = Err
If F > 0 Then
If F = 53 Then
MsgBox "Файл не найден.", vbCritical, "Ошибка"
Else
MsgBox "Файл открыть не возможно.", vbCritical, "Ошибка"
End If
Else
Text1.Text = Input(LOF(1), 1)
NameFile = H
End If
Close #1
End Sub

Private Sub MenuSave_Click()
If Len(NameFile) = 0 Then
MenuSaveAs_Click
Else
SaveFile NameFile
End If
End Sub

Private Sub MenuSaveAs_Click()
Dim T As Long, H As String, strFilter As String, Razshirenie As String
Razshirenie = ".txt"
strFilter = "Блокнот (*.txt)" & Chr(0) & "*.txt" & Chr(0) & "All Files (*.*)" & Chr(0) & "*.*"
If Len(NameFile) Then
H = NameFile
T = Len(H)
T = T - InStrRev(H, "\")
H = Right(H, T)
End If
H = OpenSave(True, H, strFilter)
If Len(H) = 0 Then Exit Sub
If InStr(H, ".") = 0 Then H = H & Razshirenie
SaveFile H
End Sub

Module Name="Declare"
Public NameFile As String
Public strDir As String 'Путь к папке

Module Name="apiOpenSave"
Private Type OPENFILENAME 'Диалог сохранения и открытия
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
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

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
(pOpenfilename As OPENFILENAME) As Long

Public Function OpenSave(ByVal Status As Boolean, ByVal NmFile As String, _
ByVal strFilter As String) As String
Dim F As Long, X As Boolean
Dim OFN As OPENFILENAME
With OFN
.lStructSize = Len(OFN)
.hwndOwner = Form1.hWnd
.flags = 0
.lpstrInitialDir = strDir
.lpstrFile = NmFile & String$(255 - Len(NmFile), 0)
.nMaxFile = 255
.lpstrFileTitle = String$(255, 0)
.nMaxFileTitle = 255
.lpstrFilter = strFilter
.nFilterIndex = 1
.hInstance = App.hInstance
If Status = False Then
F = GetOpenFileName(OFN)
Else
F = GetSaveFileName(OFN)
End If
If F > 0 Then
F = InStr(.lpstrFile, vbNullChar)
If F > 0 Then
OpenSave = Left$(.lpstrFile, F - 1)
Else
OpenSave = .lpstrFile
End If
If X = False Then
F = InStrRev(OpenSave, "\")
strDir = Left(OpenSave, F)
End If
End If
End With
End Function

Module Name="SaveFileM"
'Сохранить Файл
Public Sub SaveFile(ByVal NmFile As String)
Dim F As Long
On Error Resume Next
Screen.MousePointer = 11
Open NmFile For Output As #1
F = Err
If F > 0 Then
If F = 75 Then
MsgBox "Файл защищён от записи.", vbCritical
Else
MsgBox "Файл сохранить не возможно.", vbCritical
End If
Else
Print #1, Form1.Text1.Text
NameFile = NmFile
End If
Close #1
Screen.MousePointer = 0
End Sub

Инфо
Сайт создан: 20 июня 2015 г.
Рейтинг@Mail.ru
Главная страница