VB icon

16 and 32 bit functions to create

Email
Submitted on: 1/1/2015 2:54:00 AM
By: VB Qaid (from psc cd)  
Level: Not Given
User Rating: By 25 Users
Compatibility: VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 1031
 
     16 AND 32 bit functions to read/write ini files--very useful!
 

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 :16 and 32 bit functions to create
'**************************************
'****************************************************
'* INI_sm.BAS *
'****************************************************
Option Explicit
#If Win16 Then
Declare Function WritePrivateProfileString Lib "Kernel" (ByVal AppName As String, ByVal KeyName As String, ByVal NewString As String, ByVal filename As String) As Integer
Declare Function GetPrivateProfileString Lib "Kernel" Alias "GetPrivateProfilestring" (ByVal AppName As String, ByVal KeyName As Any, ByVal default As String, ByVal ReturnedString As String, ByVal MAXSIZE As Integer, ByVal filename As String) As Integer
#Else
' NOTE: The lpKeyName argument for GetProfileString, WriteProfileString,
'GetPrivateProfileString, and WritePrivateProfileString can be either
'a string or NULL. This is why the argument is defined as "As Any".
' For example, to pass a string specifyByVal "wallpaper"
' To pass NULL specifyByVal 0&
'You can also pass NULL for the lpString argument for WriteProfileString
'and WritePrivateProfileString
' Below it has been changed to a string due to the ability to use vbNullString
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
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
#End If
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: 16 and 32 bit functions to create
' Description:16 AND 32 bit functions to read/write ini files--very useful!
' By: VB Qaid (from psc cd)
'**************************************

Create a new module called: INI_SM.BAS
Add an attribute:
Attribute VB_Name = "ini_sm"
Add this code:
'*******************************************************
'* Procedure Name: sReadINI*
'*=====================================================*
'*Returns a string from an INI file. To use, call the *
'*functions and pass it the Section, KeyName and INI*
'*File Name, [sRet=sReadINI(Section,Key1,INIFile)].*
'*val command. *
'*******************************************************
Function ReadINI(Section, KeyName, filename As String) As String
Dim sRet As String
sRet = String(255, Chr(0))
ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), filename))
End Function
'*******************************************************
'* Procedure Name: WriteINI*
'*=====================================================*
'*Writes a string to an INI file. To use, call the *
'*function and pass it the sSection, sKeyName, the New *
'*String and the INI File Name,*
'*[Ret=WriteINI(Section,Key,String,INIFile)]. *
'*Returns a 1 if there were no errors and *
'*a 0 if there were errors.*
'*******************************************************
Function writeini(sSection As String, sKeyName As String, sNewString As String, sFileName) As Integer
Dim r
r = WritePrivateProfileString(sSection, sKeyName, sNewString, sFileName)
End Function


Other 2 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 Not Given 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.