Citire/Scriere din fisier
Last Updated: Jul 06 2011 04:09, Started by
Rengel
, Jul 05 2011 21:00
·
0
#1
Posted 05 July 2011 - 21:00
As vrea sa fac unui program un fel de fisier 'config' unde sa-i retin setarile atunci cand un utilizator vrea sa le schimbe.
Imi este foarte usor sa fac citiri scrieri in C++ (http://www.cplusplus...y/cstdio/scanf/) insa aici am mari probleme cu acest lucru. Cum as putea citi un singur integer ca in C? Cum as putea citi un cuvant? Aceiasi problema si la scriere. Mersi anticipat. Edited by Rengel, 05 July 2011 - 21:03. |
#2
Posted 05 July 2011 - 21:06
http://www.cplusplus...y/cstdio/fgets/
http://www.cplusplus...y/cstdio/fread/ http://www.cplusplus.../cstdio/fscanf/ Ca sa citesti un int ai acolo exemplu, ca sa citesti un cuvant dintr-o propozitie: 1. Citesti un caracter si-l adaugi intr-un buffer(o variabila de tip sir de caractere char *cuv) 2. Te intrebi: este diferit acest caracter de spatiu?(nu am ajuns la sfarsitul cuvantului) 3. Revii la pasul 1. pana cand dai de spatiu 4. Daca dai de spatiu ti s-a terminat cuvantul, deci in buffer pui sfarsitul de string Edited by Paullik, 05 July 2011 - 21:07. |
#3
Posted 05 July 2011 - 21:11
Cauta in documentatie despre FileSystemObject (sper ca te referi la VB 6 si nu .NET)
|
#4
Posted 05 July 2011 - 21:12
#5
Posted 05 July 2011 - 21:28
Acel obiect cu proprietatile si metodele sale e folosit in lucrul cu fisierele.
|
#6
Posted 06 July 2011 - 04:09
eu iti recomand acest modul, usor de folosit
Public S() As String Public ItemInSect As Integer Private Declare Function GetPrivateProfileString Lib "kernel32" _ Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _ ByVal lpKeyName As String, ByVal lpDefault As String, _ ByVal lpReturnedString As String, ByVal nSize As Long, _ ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileString Lib "kernel32" Alias _ "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) _ As Long Public Property Get ReadINI(strSection As String, strkey As String, _ strfullpath As String) As String Dim strbuffer As String Let strbuffer$ = String$(750, Chr$(0&)) Let ReadINI$ = Left$(strbuffer$, GetPrivateProfileString(strSection$, _ ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$)) End Property Public Sub WriteINI(strSection As String, strkey As String, strkeyvalue _ As String, strfullpath As String) Call WritePrivateProfileString(strSection$, strkey$, strkeyvalue$, _ strfullpath$) End Sub Public Function DeleteKey(strSection As String, strkey As String, _ strfullpath As String) As Boolean Call WritePrivateProfileString(strSection, strkey$, vbNullString, _ strfullpath$) End Function Public Function GetAllKeys(ByVal Section As String, strfullpath As String) _ As Collection Dim Value As String, RetVal As String, X As Integer Dim i As Integer RetVal = String$(25500, 0) X = GetPrivateProfileString(Section, vbNullString, "", RetVal, _ Len(RetVal), strfullpath) Value = Trim(Left(RetVal, X)) S = Split(Value, Chr(0)) Set GetAllKeys = New Collection With GetAllKeys For i = LBound(S) To UBound(S) If S(i) <> "" Then .Add S(i) Next End With ItemInSect = UBound(S) End Function 'Citeste 'citit = ReadWrite.ReadINI(sectiune, item, App.Path & fisierini) 'Scrie 'ReadWrite.WriteINI sectiune, item, item de scris, App.Path & fisierini 'Sterge 'ReadWrite.DeleteKey sectiune, item, App.Path & fisierini 'Numara itemii 'returneaza nr de itemi dintr-o sectiune 'GetAllKeys sectiune, App.Path & fisierini 'itemi = ItemInSect structura fisierului .ini, sau .config, sau orice extensie doresti: [Sectiune 1] Item1=1 Item2=abc [Sectiune 2] Item1=21 Item2=abcd [Sectiune 3] Item1=31 Item2=cba |
Anunturi
Bun venit pe Forumul Softpedia!
▶ 0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users