VB icon

INI Read and INI Write - Simple and Error Free

Email
Submitted on: 1/5/2015 6:12:00 AM
By: Jeffrey C. Tatum (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 656
 
     INI Read and INI Write made simple. I included examples in each function. If you like my codes, then please vote for me. But only if you like them. Thanks =)
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :INI Read and INI Write - Simple and Error Free
'**************************************
'INI Read and Write
Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName _
As String, lpKeyName As Any, ByVal lpDefault As String, _
ByVal lpRetunedString As String, ByVal nSize As Long, _
ByVal lpFilename As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" (ByVal lpApplicationName _
As String, ByVal lpKeyName As Any, ByVal lpString As Any, _
ByVal lplFileName As String) As Long
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: INI Read and INI Write - Simple and Error Free
' Description:INI Read and INI Write made simple. I included examples in each function. If you like my codes, then please vote for me. But only if you like them. Thanks =)
' By: Jeffrey C. Tatum (from psc cd)
'**************************************

Public Function INIRead(iAppName As String, iKeyName As String, iFileName As String) As String
'Example:
'x = INIRead("boot", "shell", "C:\WINDOWS\system.ini")
Dim iStr As String
iStr = String(255, Chr(0))
INIRead = Left(iStr, GetPrivateProfileString(iAppName, ByVal iKeyName, "", iStr, Len(iStr), iFileName))
End Function
Public Function INIWrite(iAppName As String, iKeyName As String, iKeyString As String, iFileName As String)
'Example:
'x = INIWrite("boot", "shell", "Explorer.exe", "C:\WINDOWS\system.ini")
r% = WritePrivateProfileString(iAppName, iKeyName, iKeyString, iFileName)
End Function


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.