VB icon

all Ini Functions activeX.dll

Email
Submitted on: 1/5/2015 1:47:00 PM
By: Anonymous (from psc cd)  
Level: Advanced
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0
Views: 960
 
     Performs all ini file functions from within a single dll file.
 

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 :all Ini Functions activeX.dll
'**************************************
Public 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
Public 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
Public Declare Function GetPrivateProfileSection _ Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal _ lpAppName As String, ByVal lpReturnedString As _ String, ByVal nSize As Long, ByVal lpFileName As _ String) As Long
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: all Ini Functions activeX.dll
' Description:Performs all ini file functions from within a single dll file. 
' By: Anonymous (from psc cd)
'
' Inputs:Key name
Section name
New Key Value
'
' Returns:IniFunction.KeyGet returns the value of a specified key.
IniFunction.SectionGet returns all values in the specified section to a variant
'
' Assumes:You need to add the Inifunctions.dll to the project reference.
then insert the following code in general declaration
eg.
Dim g_IniFunctions As New CInI
then use in your program the following code:
dim RC as variant,R as long,I as long
With g_IniFunctions
SectionId = .SectionGet(Section name)
End With
For R = 0 To UBound(SectionId)
I = InStr(SectionId(R), "=")
Combo1.AddItem Mid(SectionId _(R), I + 1)
Next
dim strReturnWhat as string
strReturnWhat = g_IniFunctions.KeyGet(section name), KeyName)
The other inputs are self explanatory.
ini file name is inside the INIfunctions.dll
 save class as Cini.cls and compile as INIFunctions.dll
'
' Side Effects:None that I know of, But I have only used it on VB6.
'**************************************

Public m_MstrConfigName As String
Dim m_strKeyname As String
Dim m_strsection As String
Dim m_strKeyValue As String
Dim m_strdefault As String
Private Sub Class_Initialize()
m_MstrConfigName = App.Path & "\ Your Ini file name"
End Sub
Public Property Get KeyName() As String
End Property
Public Property Let KeyName(ByVal strNewValue As String)
End Property
Public Function KeyGet(Optional strSection As String = "N/A", Optional strKeyName = "N/A", Optional strdefault As String = "")
Dim lngRet As Long
'fill in section
If strSection <> "N/A" Then
m_strsection = strSection
End If
If strKeyName <> "N/A" Then
m_strKeyname = strKeyName
End If
m_strdefault = strdefault
'get value
m_strKeyValue = Space(255)
lngRet = GetPrivateProfileString(m_strsection, _
 m_strKeyname, _
 m_strdefault, _
 m_strKeyValue, _
 Len(m_strKeyValue), _
 m_MstrConfigName)
 
If lngRet > 0 Then
m_strKeyValue = Left$(m_strKeyValue, lngRet)
Else
m_strKeyValue = vbNullString
End If
 KeyGet = m_strKeyValue
End Function
Public Sub Keysave(Optional strSection As String = "N/A", Optional strKeyName = "N/A", Optional strdefault As String = "")
Dim lngRet As Long
'fill in properties
If strSection <> "N/A" Then
m_strsection = strSection
End If
If strKeyName <> "N/A" Then
m_strKeyname = strKeyName
End If
'get value
m_strKeyValue = Space(255)
lngRet = WritePrivateProfileString(m_strsection, _
 m_strKeyname, _
 m_strKeyValue, _
 m_MstrConfigName)
 
End Sub
Public Function SectionGet(Optional strSection As String = "") As Variant
Dim lngRet As Long
Dim strBuffer As String
If Not strSection = vbNullString Then
m_strsection = strSection
End If
If Not m_strsection = vbNullString Then
strBuffer = Space(2048)
lngRet = GetPrivateProfileSection(m_strsection, _
strBuffer, _
Len(strBuffer), _
m_MstrConfigName)
 End If
If lngRet > 0 Then
strBuffer = Left$(strBuffer, lngRet)
SectionGet = Split(strBuffer, Chr$(0))
Else
SectionGet = Array()
End If
End Function


Other 209 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 Advanced 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.