VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



16 and 32 bit functions to create

by VB Qaid (3 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (25 Votes)

16 AND 32 bit functions to read/write ini files--very useful!

API Declarations
'****************************************************
'* 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 specify ByVal "wallpaper"
' To pass NULL specify ByVal 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

Rate 16 and 32 bit functions to create

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

Download this snippet    Add to My Saved Code

16 and 32 bit functions to create Comments

No comments have been posted about 16 and 32 bit functions to create. Why not be the first to post a comment about 16 and 32 bit functions to create.

Post your comment

Subject:
Message:
0/1000 characters