February 7th, 2000, 11:57 AM
I want to know which is the purpose of an INI file. I'm making an app with VB6.0 - SQL server7.0. I know that some apps have an INI file which contains password, and other parametres..
I would like to know more about INI files and his utilities. I want to know which are the typical the things you put in an INI file and how to use thems.
I suppose that using them I can get some advantage in my app. isn't it???
Any advice will be greatly apreciatted.
Nauj
rino_2
February 7th, 2000, 02:04 PM
Hi,
INI files are great but some say not quite as great as the regestry. INI files are used to store information in such as the users name or background colour of the program. Its not a good idea to use INI files to store User Names and Passwords as anybody can access an INI file and see what the password is. To use INI files you need to know the two API calls:
GetPrivateProfileString
WritePrivateProfileString
As you may have probably guessed GetPrivateProfileString is used to read INI files and the latter is used to write to INI files. Here is an example that I have taken from some place:
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, 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
Private Sub Form_Load()
Dim Ret As String, NC As Long
'Write the setting to the file (c:\test.ini) under
' Project1 -> Keyname
WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
'Create a buffer
Ret = String(255, 0)
'Retrieve the string
NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
'NC is the number of characters copied to the buffer
If NC <> 0 Then Ret = Left$(Ret, NC)
'Show our string
MsgBox Ret
'Delete the file
Kill "c:\test.ini"
End Sub
I hope it helps!!!
Starcraft
February 7th, 2000, 07:15 PM
you no, you can write to ".dat" files also, and you cant read them unless you open it with notepad