malo sam pogresio sa onim funkcijama gore evo je ispravka,delete nema tako da moras koristiti programersku domisljatost koja je u vb-u veoma ogranicena moram reci nisam uspeo da nadjem kako bi mogao da uradis delete funkciju za txt fajl pise ti dole gde je tacno zapelo pa ti vidi mozda ti nesto padne na pamet
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Declare Function SetEndOfFile Lib "kernel32" (ByVal hFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = 3
Private Const OPEN_ALWAYS = 4
Private Const FILE_BEGIN = 0
Private Type Baza
nesto1 As String
nesto2 As Integer
Rezerva1 As String ' kasnije ces mozda shvatiti da ti treba jos koje polje
End Type
Private Sub upis_Click() ' upis podataka u fajl
Dim db As Baza
With db 'obrada
.nesto1 = "prvi"
.nesto2 = 0
End With
Open "c:\proba.txt" For Random As #1
Put #1, brojrekorda, db ' pise podatke u fajl
Close #1
End Sub
Private Sub citaj_Click() 'cita podatke iz fajla
Dim db As Baza
Dim Str As String
Dim num As Integer
Open "c:\proba.txt" For Random As #1
Get #1, brojrekorda, db ' cita podatke iz fajla
Close #1
'obrada
Str = db.nesto1
num = db.nesto2
End Sub
Private Sub citanje_svega() ' redom cita sve
Dim db As Baza
Open "c:\proba.txt" For Random As #1
Do While Not EOF(1)
Get #1, , db ' cita sledeci
'obrada
Loop
Close #1
End Sub
Private Sub obrisi_Click() ' brisanje rekorda
Dim db As Baza
Dim hFile As Long
Dim kraj As Long
Dim zadnjizapis As Integer
Open "c:\proba.txt" For Random As #1
Do While Not EOF(1)
zadnjizapis = Loc(1) + 1
Get #1, , db ' trazimo zadnji zapis
Loop
Get #1, zadnjizapis, db ' cita podatke iz zadnjeg rekorda
Put #1, brojrekorda, db ' pise podatke koje smo procitali iz zadnjeg rekorda preko rekorda koji brisemo
Close #1
kraj = FileLen("c:\proba.txt") - Len(db) ' ovde treba izracunati gde se nalazi taj zadnji zapis u bajtovima ali to nisam uspeo da nadjem kako...
hFile = CreateFile("c:\proba.txt", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0) ' otvara fajl
If hFile <> -1 Then ' ako postoji fajl
SetFilePointer hFile, kraj, 0, FILE_BEGIN ' pozicionira se u ondaj deo fajla koji treba obrisati
SetEndOfFile hFile ' odsece zadnji deo fajla
CloseHandle hFile ' zatvara
End If
End Sub
|