Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$old_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ext-thumbnail_url is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
Leggere e scrivere sui file .INI | IlSoftware.it

Leggere e scrivere sui file .INI

I file .INI sono dei file di testo usati abbondantemente fino a qualche anno fa nella maggior parte delle applicazioni.

I file .INI sono dei file di testo usati abbondantemente fino a qualche anno fa nella maggior parte delle applicazioni.
Essi contengono di solito informazioni riguardanti la configurazione di un’applicazione, sulle preferenze scelte dall’utente, e così via.
Anche oggi comunque l’utilizzo dei file .INI prosegue. Nelle nostre applicazioni, sviluppate con Visual Basic, l’uso dei file INI può rivelarsi pratico ed interessante.
Si può quindi utilizzare tali file di testo per memorizzarvi informazioni relative alla configurazione del programma.

La funzione che vi presentiamo qui permette di leggere un dato memorizzato all’interno di un file .INI.

Utilizzo:

stringaletta = ReadINI("c:\file.ini", "nome sezione", "nome chiave")

Accertatevi di sostituire a c:\file.ini il percorso completo ed il nome del file .INI.
A nome sezione deve essere sostituito il nome della sezione, all’interno della quale risiede il dato da recuperare. Le sezioni all’interno di un file .INI sono indicate da parentesi quadre.
A nome chiave va sostituito il nome della chiave accanto alla quale è memorizzato il dato da recuperare.

Il dato recuperato verrà in questo caso memorizzato nella variabile stringaletta.

Si può anche utilizzare i file .INI per memorizzarvi informazioni relative alla configurazione del programma.

La funzione che vi presentiamo qui permette di salvare un dato all’interno di un file .INI.

Utilizzo:

WriteINI "c:\file.ini", "nome sezione", "nome chiave", "testo da salvare"

Accertatevi di sostituire a c:\file.ini il percorso completo ed il nome del file .INI che deve essere creato o comunque il file .INI già esistente all’interno del quale volete salvare il vostro dato.
A nome sezione deve essere sostituito il nome della sezione, all’interno della quale volete salvare il vostro dato. Le sezioni all’interno di un file .INI vengono indicate con parentesi quadre.
A nome chiave va sostituito il nome della chiave in corrispondenza della quale si vuol memorizzare il dato.
Sostituite testo da salvare con il testo che volete memorizzare nel file .INI.

Il codice per leggere

Public Function ReadINI(FileName As String, Section As String, Key As String)
    Dim RetLen
    INIFileFound = True
    FileExists FileName

    If IsFileThere = False Then
        INIFileFound = False
        Exit Function
    End If
    Ret = Space$(255)
    RetLen = GetPrivateProfileString(Section, Key, “”, Ret, Len(Ret), FileName)
    Ret = Left$(Ret, RetLen)
    ReadINI = Ret
End Function

Il codice per scrivere

Public Sub WriteINI(FileName As String, Section As String, Key As String, Text As String)
    WritePrivateProfileString Section, Key, Text, FileName
End Sub

Ti consigliamo anche

Link copiato negli appunti