np.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal Hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Const SW_NORMAL = 1
Const WM_CLOSE = &H10
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lparam As Any) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
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
Function OpenDialog(Form1 As Form, Filter As String, Title As String, InitDir As String) As String
Dim ofn As OPENFILENAME
Dim a As Long
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Form1.Hwnd
ofn.hInstance = App.hInstance
If Right$(Filter, 1) <> "|" Then Filter = Filter + "|"
For a = 1 To Len(Filter)
If Mid$(Filter, a, 1) = "|" Then Mid$(Filter, a, 1) = Chr$(0)
Next
ofn.lpstrFilter = Filter
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = InitDir
ofn.lpstrTitle = Title
ofn.flags = OFN_HIDEREADONLY Or OFN_FILEMUSTEXIST
a = GetOpenFileName(ofn)
If (a) Then
ofn.lpstrFile = Replace(ofn.lpstrFile, Chr(0), "")
OpenDialog = Trim$(ofn.lpstrFile)
Else
OpenDialog = ""
End If
End Function
Private Sub Command1_Click()
Dim hn
Dim Tekst, Adres, Znacznik, spacja As String
Dim Tabela() As String, Tabela2() As String
Dim LiczbaRekordow As Integer, LiczbaWyrazow As Integer
Dim i As Integer, j As Integer
MSFlexGrid1.Cols = 8
Znacznik = Chr(13) + Chr(10): spacja = Chr(32)
hn = FindWindowEx(0, 0, "Notepad", vbNullString)
Adres = OpenDialog(Form1, "*.txt;" + Chr$(0) + "*.txt;" + Chr$(0) + "All Files *.*" + Chr$(0) + "*.*" + Chr$(0), "Odczyt", "")
If hn Then PostMessage hn, WM_CLOSE, 0&, 0&
X = ShellExecute(Hwnd, "Open", Adres, &O0, &O0, SW_NORMAL)
Open Adres For Binary As #1
Tekst = Input$(LOF(1), 1) + Znacznik
Tekst = Replace(Tekst, Znacznik + Znacznik, Znacznik)
Close #1
Tabela = Split(Tekst, Znacznik)
LiczbaRekordow = UBound(Tabela)
MSFlexGrid1.Rows = LiczbaRekordow + 1
For i = 0 To LiczbaRekordow - 1
Tabela2 = Split(Tabela(i), spacja)
LiczbaWyrazow = UBound(Tabela2)
For j = 0 To LiczbaWyrazow
MSFlexGrid1.TextMatrix(i + 1, j + 1) = Tabela2(j)
Next j
Next i
End Sub
Liczby w pliku tekstowym rozdzielone są w każdym rekordzie tylko jedną spacją np.
123 23456 2222222 444444444 77 34 76543
33333333 555555 4444444 6666666 333 222222222 444444
222 44444 7 6666666 222 4444444 5466