Bosna i Hercegovina


switch Lista naslova:

#1 09.07.2014-21:59
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Rad sa datotekama*
U ovoj temi ce biti demonstrirani fprimjeri rada sa datotekama.
Kreiranje, otvaranje manipulacija podacima u datotekama.
Pozdrav
↑  ↓

#2 09.07.2014-22:02
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Putanja smijestanja
Ovu proceduru morate svakko imati da bi mogli isprobati tekuce procedure koje ce biti postavljene poslije ove.
Ova procedura pronalazi putanju vase mdb a na toj putanji ce biti smjestenio i fajlovi nad kojim se vrsi manipulacija u slijedecim procedurama.
Putanja do baze:
DownloadIzvorni kod (Visual Basic):
  1. Function Db_Putanja() As String
  2. '__________________________________________________
  3. 'Ova funkcija pronalazi putanju do postojee mdb
  4. 'Autor funkcije ZXZ
  5. '__________________________________________________
  6.    Dim Db As Database, Putanja As String
  7.    
  8.     On Error Resume Next
  9.     Set Db = DBEngine(0)(0)
  10.     Putanja = Db.Name
  11.     Do Until Right$(Putanja, 1) = "\"
  12.         Putanja = Left$(Putanja, Len(Putanja) - 1)
  13.     Loop
  14.     Db_Putanja = Putanja
  15. End Function

Pozdrav
↑  ↓

#3 09.07.2014-22:04
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Kreiranje novog txt fajla
Ova procedura krira fajl pod imenom MojFajl.txt na putanji mdb u kjoj se nalazi ovaj kod.

DownloadIzvorni kod (Visual Basic):
  1. Public Function KreirajFile() As Variant
  2. '*******************************************************
  3. 'Ime:      KreirajFile   (Function)
  4. 'Sadrzaj: Kreira file MojFajl.txt na putanji baze
  5. 'Autor: zxz
  6. 'Datum: 09.07.2014, 10:44:07
  7. 'Adresa: Tuzla BiH
  8. 'EMail: zxz@icentar.ba
  9. 'www: icentar.ba
  10. 'Ulazni parametri:Nema
  11. 'Izlazni parametri:Nema
  12. '******************************************************
  13. Dim F As Integer, I As Integer
  14. Dim PutZapisa As String, Tmp As String
  15.  
  16. On Error GoTo Greska
  17. PutZapisa = Db_Putanja
  18. F = FreeFile
  19. Open PutZapisa & "\MojFajl.txt" For Output Shared As F
  20.  
  21. For I = 1 To 10
  22. Tmp = I & I & I * I
  23. Print #F, Tmp
  24. Next I
  25. Close F
  26. Izlaz:
  27. Exit Function
  28. Greska:
  29. Dim strErrString As String
  30. strErrString = "Error Information..." & vbCrLf
  31. strErrString = strErrString & "Error#: " & Err.Number
  32. strErrString = strErrString & "Description: " & Err.Description
  33. MsgBox strErrString, vbCritical + vbOKOnly, "Function: KreirajFile"
  34. Resume Izlaz
  35. End Function

Pozdrav
↑  ↓

#4 10.07.2014-21:43
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Citanje podataka iz fajla
Ova procedura cita podatke iz fajla na zadatoj putanji.
DownloadIzvorni kod (Visual Basic):
  1. Public Function OtvoriFile() As Variant
  2. '*******************************************************
  3. 'Ime:      OtvoriFile   (Function)
  4. 'Sadrzaj:Otbaranje fajla na putanji mdb
  5. 'Autor: zxz
  6. 'Datum: 10.07.2014, 10:33:56
  7. 'Adresa: Tuzla BiH
  8. 'EMail: zxz@icentar.ba
  9. 'www: icentar.ba
  10. 'Ulazni parametri:
  11. 'Izlazni parametri:
  12. '******************************************************
  13. Dim F As Integer
  14. Dim tmp As String, PutZapisa As String
  15.  
  16. On Error GoTo Greska
  17. F = FreeFile
  18. PutZapisa = Db_Putanja
  19. Open PutZapisa & "MojFajl.txt" For Input As #F
  20. While Not EOF(F)
  21. Line Input #F, tmp
  22. MsgBox tmp
  23. Wend
  24. Close #F
  25. Izlaz:
  26. Exit Function
  27. Greska:
  28. Dim strErrString As String
  29. strErrString = "Error Information..." & vbCrLf
  30. strErrString = strErrString & "Error#: " & Err.Number
  31. strErrString = strErrString & "Description: " & Err.Description
  32. MsgBox strErrString, vbCritical + vbOKOnly, "Function: OtvoriFile"
  33. Resume Izlaz
  34. End Function

Pozdrav
↑  ↓

#5 15.07.2014-12:18
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Dodavanje teksta u Fajl
Ovo je primjer dodavanja teksta u vec postojeci fajl koji sadrzi odredjene zapise.
DownloadIzvorni kod (Visual Basic):
  1. Function DodajUFaile()
  2. Dim F As Integer
  3. Dim tmp As String, PutZapisa As String
  4.  
  5.     F = FreeFile
  6.     PutZapisa = Db_Putanja
  7.    
  8.     Open PutZapisa & "MojFajl.txt" For Append As F
  9.     tmp = "Ovo je dodano"
  10.     Print #F, tmp
  11.     Close #F
  12.     MsgBox "Ok"
  13. End Function

Evo jos jedna samo malo drugacija.

DownloadIzvorni kod (Visual Basic):
  1. Function UpisUTxt(ImeFajla As String, Tekst As String)
  2. On Error GoTo Err_Handler
  3.     Dim FileNumber As Integer
  4.  
  5.     FileNumber = FreeFile
  6.     Open ImeFajla For Output As #FileNumber
  7.     Print #FileNumber, Tekst
  8.     Close #FileNumber
  9.  
  10. Exit_Err_Handler:
  11.     Exit Function
  12.  
  13. Err_Handler:
  14.     MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
  15.            "Error Number: " & Err.Number & vbCrLf & _
  16.            "Error Source: UpisUTxt" & vbCrLf & _
  17.            "Error Description: " & Err.Description, vbCritical, "An Error has Occured!"
  18.     GoTo Exit_Err_Handler
  19. End Function

Pozdrav
Ovaj komentar je mijenjan 1 puta. zadnja izmjena 20.01.2015-10:38 od strane zxz. ↑  ↓

#6 17.07.2014-13:18
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Velicina fajla
Ova procedura vraca velicinu fajla.
DownloadIzvorni kod (Visual Basic):
  1. Function VelicinaFilea()
  2. Dim F As Integer
  3. Dim PutZapisa As String
  4.  
  5.     F = FreeFile
  6.     PutZapisa = Db_Putanja
  7. Open PutZapisa & "MojFajl.txt" For Input As #F
  8. VelicinaFilea = LOF(F)
  9. Close #1
  10. End Function

Pozdrav
↑  ↓

#7 18.07.2014-10:04
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Reset naredba
Sa naredbom reset mozemo zatvoriti sve otvorene datoteke odjednom za razliku od naredbe Close koja zatvara samo odredjeni fajl (datoteku)
DownloadIzvorni kod (Visual Basic):
  1. Function NaredbaReset()
  2. Dim F1 As Integer, F2 As Integer
  3. Dim PutZapisa As String
  4.  
  5.  F1 = 1
  6.  F2 = 2
  7.  PutZapisa = Db_Putanja
  8. Open PutZapisa & "MojFajl.txt" For Input As #F1
  9. Open PutZapisa & "NekiDrugifajl.txt" For Output As #F2
  10. Reset
  11. End Function

Pozdrav
↑  ↓

#8 19.07.2014-09:44
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: SPC Naredba
Koristi se uz naredbe Print # i Print za pozicioniranje izlaza.
Sintaksa:
Spc(N), gdje je N Broj praznih mjesta izmedju izraza.
Primjer:
DownloadIzvorni kod (Visual Basic):
  1. Function SpcNaredba()
  2. Dim F As Integer
  3. Dim tmp(2) As String, PutZapisa As String
  4.  
  5.     F = FreeFile
  6.     PutZapisa = Db_Putanja
  7.    
  8.     Open PutZapisa & "MojFajl.txt" For Append As F
  9.     tmp(0) = "Prvi dodatak"
  10.     tmp(1) = "Drugi dodatak"
  11.     tmp(2) = "TreciDodatak"
  12.     Print #F, tmp(0); Spc(10); tmp(1); Spc(10); tmp(2)
  13.     Close #F
  14.     MsgBox "Ok"
  15. End Function

Pozdrav
↑  ↓

#9 20.07.2014-12:36
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Tab naredba
Tab() nareba isto se koristi uz naredbe Print # i Print za pozicioniranje izlaza.
Sintaksa:
Tab(N), gdje je N Broj praznih mjesta izmedju izraza.

DownloadIzvorni kod (Visual Basic):
  1. Function TabNaredba()
  2. Dim F As Integer
  3. PutZapisa As String
  4.  
  5.     F = FreeFile
  6.     PutZapisa = Db_Putanja
  7.     Open PutZapisa & "MjFajlTab.txt" For Output As #F
  8. Print #F, "Prva kolona"; Spc(10); "Druga kolona"; Spc(10); "Treca kolona"; Spc(10); "Cetvrta kolona"
  9. Print #F, "Prva kolona"; Tab(44); "Treca kolona"
  10. Close #F
  11. End Function

Pozdrav
↑  ↓

#10 21.07.2014-09:24
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Width Naredba
Width Naredba odredjuje sirinu zapisa.
Sintaksa:
Width #broj_fajla, sirina
DownloadIzvorni kod (Visual Basic):
  1. Function WidthNaredba()
  2. Dim F As Integer
  3. Dim PutZapisa As String
  4. Dim I As Integer
  5.  
  6.     F = FreeFile
  7.     PutZapisa = Db_Putanja
  8.     Open PutZapisa & "MjFajlWidth.txt" For Output As #F
  9.     Width #1, 10
  10. For I = 1 To 40
  11.      Print #F, Chr(48 + I);
  12. Next I
  13. Close #F
  14. End Function

Pozdrav
↑  ↓

#11 22.07.2014-17:13
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Put Naredba
Unosi podatke iz promenljive u fajl .
Sintaksa:
Put [#]broj_fajla, [slog], promenljiva

DownloadIzvorni kod (Visual Basic):
  1. Function PutNaredba()
  2. Dim F As Integer
  3. Dim PutZapisa As String
  4. Dim MojPodatak As Podatak, Broj
  5.  
  6. F = FreeFile
  7. PutZapisa = Db_Putanja
  8. Open PutZapisa & "MojFajl.txt" For Random As #F Len = Len(MojPodatak)
  9. For Broj = 3 To 10
  10.    MojPodatak.ID = Broj
  11.    MojPodatak.Naziv = "Podatak" & Broj
  12.    Put #F, Broj, MojPodatak
  13. Next Broj
  14. Close #1
  15. End Function

Pozdrav
↑  ↓

#12 23.07.2014-16:56
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Seek naredba
Naredba Seek odredjuje poziciju sledece operacije:
sintaksa:
Seek [#]broj_fajla, pozicija

DownloadIzvorni kod (Visual Basic):
  1. Function SeekNaredba()
  2. Dim F As Integer
  3. Dim PutZapisa As String
  4. Dim tmp As String
  5.  
  6. F = FreeFile
  7. PutZapisa = Db_Putanja
  8. Open PutZapisa & "MojFajl.txt" For Input As #F
  9. Seek #F, 25
  10. Line Input #F, tmp
  11. MsgBox tmp
  12. Close #F
  13. End Function

Pozdrav
↑  ↓

#13 20.01.2015-10:49
zxz Offline
Administrator
Registrovan/a od: 03.02.2009-16:22
Komentari: 8,822


Subject: Koliko ima fajlova u nekom dir
Ova procedura vraca broj fajlova (Datoteka) u navedenom direktoriju.
DownloadIzvorni kod (Visual Basic):
  1. Function BrojFajlova(DirPutanja As String) As Long
  2. On Error GoTo Error_Handler
  3.     Dim fso As Object
  4.     Dim flr As Object
  5.  
  6.     Set fso = CreateObject("Scripting.FileSystemObject")
  7.     Set flr = fso.GetFolder(DirPutanja)
  8.  
  9.     BrojFajlova = flr.Files.Count
  10.  
  11. Error_Handler_Exit:
  12.     On Error Resume Next
  13.     Set flr = Nothing
  14.     Set fso = Nothing
  15.     Exit Function
  16.  
  17. Error_Handler:
  18.     MsgBox "The following error has occured." & vbCrLf & vbCrLf & _
  19.             "Error Number: " & Err.Number & vbCrLf & _
  20.             "Error Source: BrojFajlova" & vbCrLf & _
  21.             "Error Description: " & Err.Description, _
  22.             vbCritical, "An Error has Occured!"
  23.     Resume Error_Handler_Exit
  24. End Function

Pozdrav
↑  ↓

Stranice (1): 1

Srodne teme


All times are GMT +01:00. Current time: 20.01.2017-19:07.