Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Options buttons and ini-file

Status
Not open for further replies.

speek

Technical User
Mar 29, 2008
25
US
I'm working on a program with some option buttons. The values of these option buttons are stored in an ini-file when the program is closed. When I check the ini-file the correct values are there. But when I start the program all the option buttons are set to false (while there must always be one set to true). The values of all other controls are loaded correctly. Why are option button values not loaded?
 
Make sure your .INI file is in the same directory as your executable if you're using a compiled VB program (or you have the path in a registry value). Step through the code and see where it's dropping the values.

If you're using VBA (with Office, e.g.), the only way to get the .INI file to work is to open the item you're using (Excel spreadsheet, Access database, etc.) from the File Menu (NOT using the quick open shortcuts, open dialog box that comes up when you open Access, double click from explorer, etc.) You have to have the application open and then open the file.

Hope this helps.

Llamaman
 
Yes, the ini-file is in the same directory as the executable. I'm using VB6.

The ini-file works fine with all other controls. That's why I don't understand why it doesn't work with option buttons. The values of the option buttons are in the ini-file and the ini-loads when the program is started. But non of the option buttons gets marked ??
 
Maybe the problem is not the .ini file? Have you checked the values to see if your app is capturing the data from the .ini, like a msgbox with the values from the .ini file, etc.?
 
Well other other controls get their values from the ini file correctly. So the loading of the ini-file seems to work fine. The INI module contains the function INI_LoadControlValues and in that function "OptionButton" is one of the cases. So I really can't grasp what's going wrong.
 
Where did you get your .INI module?
Can you post the code or a link?
 
I don't know where I got it. I will copy it here (hope it's OK to post so much text):

Option Explicit

' Read INI functions
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
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

' Write INI function
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
'

Public Sub INI_LoadControlPos(ByVal frm As Form, ByVal INIFile As String)

Dim i As Long
Dim j As Long
Dim buff As String
Dim ControlX As Control
Dim cIndex As Integer

' Loop through all the controls
For i = 0 To frm.Controls.Count - 1
' Get the current control
Set ControlX = frm.Controls(i)

Select Case TypeName(ControlX)
Case "ListView"
For j = 1 To ControlX.ColumnHeaders.Count
' Save the width of each columnheader
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
ControlX.ColumnHeaders.Item(j).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.ColumnHeader.Item(&quot; & j & &quot;).Width&quot;, INIFile))
Else
ControlX.ColumnHeaders.Item(j).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.ColumnHeader.Item(&quot; & j & &quot;).Width&quot;, INIFile))
End If
Next j

Case &quot;CoolBar&quot;

For j = 1 To ControlX.Bands.Count
' Save the info for each band
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
ControlX.Bands.Item(j).NewRow = CBool(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).NewRow&quot;, INIFile))
ControlX.Bands.Item(j).Position = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Position&quot;, INIFile))
ControlX.Bands.Item(j).Height = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Height&quot;, INIFile))
ControlX.Bands.Item(j).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Width&quot;, INIFile))
Else
ControlX.Bands.Item(j).NewRow = CBool(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).NewRow&quot;, INIFile))
ControlX.Bands.Item(j).Position = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Position&quot;, INIFile))
ControlX.Bands.Item(j).Height = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Height&quot;, INIFile))
ControlX.Bands.Item(j).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Width&quot;, INIFile))
End If
Next j

Case &quot;SlidingDivider&quot;
On Error Resume Next
If Not ControlX.Index <> &quot;&quot; Then
ControlX.Left = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Left&quot;, INIFile))
ControlX.Top = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Top&quot;, INIFile))
ControlX.Height = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Height&quot;, INIFile))
ControlX.Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Width&quot;, INIFile))
Else
cIndex = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Index&quot;, INIFile))
ControlX(cIndex).Left = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Left&quot;, INIFile))
ControlX(cIndex).Top = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Top&quot;, INIFile))
ControlX(cIndex).Height = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Height&quot;, INIFile))
ControlX(cIndex).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Width&quot;, INIFile))
End If

End Select

Next i

End Sub

Public Sub INI_LoadControlValues(ByVal frm As Form, ByVal INIFile As String)

' Function: INI_LoadControlValues
'
' Place in Form_Load to load the values for
' the controls you pass in the array. This
' function is mainly used for saving user-
' defined options/settings such as check-
' boxes and radio buttons. Currently only
' supports controls with the Value property
'
' Ex: INI_LoadControlValues Me, &quot;c:\windows\myini.ini&quot;

Dim i As Long ' Control counter
Dim j As Long ' ListView columnheader counter
Dim ControlX As Control
Dim ControlX_Type As String
Dim ControlX_Val As String

' Loop through all the controls
For i = 0 To frm.Controls.Count - 1
' Get the current control
Set ControlX = frm.Controls(i)

' Save the values for each control if there is one associated with it
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
ControlX_Val = INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Value&quot;, INIFile)
Else
ControlX_Val = INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Value&quot;, INIFile)
End If

' Determine what kind of control this is
' and get the data accordingly.
ControlX_Type = TypeName(ControlX)
Select Case ControlX_Type

Case &quot;CheckBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)
Case &quot;OptionButton&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)
Case &quot;HScrollBar&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)
Case &quot;VScrollBar&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)
Case &quot;Slider&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)

Case &quot;FolderTreeview&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.SelectedFolder = ControlX_Val
Case &quot;DriveListBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Drive = ControlX_Val
Case &quot;DirListBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.path = ControlX_Val
Case &quot;FileListBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.path = ControlX_Val
Case &quot;CcXploreTreeView&quot;
ControlX.CurrentFolder = INI_Read(&quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.CurrentFolder&quot;), INIFile)
Case &quot;CcXploreListView&quot;
ControlX.CurrentFolder = CStr(INI_Read(&quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.CurrentFolder&quot;), INIFile))
ControlX.Pattern = CStr(INI_Read(&quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Pattern&quot;), INIFile))
If ControlX.Pattern = &quot;&quot; Then ControlX.Pattern = &quot;*.*&quot;

Case &quot;TextBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Text = ControlX_Val
Case &quot;ComboBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Text = ControlX_Val

End Select

Next i

End Sub

Public Sub INI_LoadForm(ByVal frm As Form, Optional ByVal INIFile As String, Optional ResetFile As Boolean = False)

' This is for incase the file was already deleted
On Error Resume Next

' Create a generic INI name from the App title
If INIFile = &quot;&quot; Then INIFile = App.path & &quot;\&quot; & App.Title & &quot;.ini&quot;

If ResetFile = True Then Kill INIFile: Exit Sub
INI_LoadFormPos frm, INIFile
INI_LoadControlPos frm, INIFile
INI_LoadControlValues frm, INIFile

End Sub

Public Sub INI_LoadFormPos(ByVal frm As Form, ByVal INIFile As String)

' Function: INI_LoadFormPosition
'
' Place in Form_Load to place a form at its last position
' and size as long as you had INI_SaveFormPosition in that
' form's Form_Unload event.

' Don't position or resize the form if there
' are no values to read back form the ini.

Dim X As Integer
Dim buff As String

' Form.Left
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Left&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Left = CInt(buff)

' Form.Top
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Top&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Top = CInt(buff)

' Form.Height
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Height&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Height = CInt(buff)

' Form.Width
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Width&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Width = CInt(buff)

' Form.Tag
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Tag&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Tag = CStr(buff)

' Form.WindowState
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.WindowState&quot;, INIFile)
If buff <> &quot;&quot; Then frm.WindowState = vbMaximized

End Sub

Public Function INI_Read(ByVal Section As String, ByVal KeyName As String, Optional ByVal INIFile As String) As Variant

' Function: INI_Read
'
' Reads back a value from an INI
'
' [Section]
' KeyName = Value

' Create a generic INI name from the App title
If INIFile = &quot;&quot; Then INIFile = App.path & &quot;\&quot; & App.Title & &quot;.ini&quot;

Dim X As Integer
Dim buff As String

buff = Space(255)
X = GetPrivateProfileString(Section, CStr(KeyName), vbNullString, buff, 255, INIFile)
INI_Read = Left(buff, X)

End Function

Public Function INI_ReadBool(ByVal Section As String, ByVal KeyName As String, ByVal INIFile As String) As Boolean

' Function: INI_ReadValue
'
' Reads back a value from an INI

Dim X As Integer
Dim buff As String

buff = Space(255)
X = GetPrivateProfileString(Section, CStr(KeyName), vbNullString, buff, 255, INIFile)
If LCase(Left(buff, X)) = &quot;true&quot; Or LCase(Left(buff, X)) = &quot;1&quot; Then INI_ReadBool = True Else INI_ReadBool = False

End Function

Public Sub INI_SaveControlPos(ByVal frm As Form, ByVal INIFile As String)

Dim i As Long
Dim j As Long
Dim ControlX As Control

' Loop through all the controls
For i = 0 To frm.Controls.Count - 1
' Get the current control
Set ControlX = frm.Controls(i)

' Save some specials values for ListView's and CoolBar's
Select Case TypeName(ControlX)
Case &quot;ListView&quot;

For j = 1 To ControlX.ColumnHeaders.Count
' Save the width of each columnheader
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.ColumnHeader.Item(&quot; & j & &quot;).Width&quot;), CStr(ControlX.ColumnHeaders.Item(j).Width), INIFile
Else
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.ColumnHeader.Item(&quot; & j & &quot;).Width&quot;), CStr(ControlX.ColumnHeaders.Item(j).Width), INIFile
End If
Next j

Case &quot;CoolBar&quot;

For j = 1 To ControlX.Bands.Count
' Save the info for each band
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).NewRow&quot;), CStr(ControlX.Bands.Item(j).NewRow), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Position&quot;), CStr(ControlX.Bands.Item(j).Position), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Height&quot;), CStr(ControlX.Bands.Item(j).Height), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Width&quot;), CStr(ControlX.Bands.Item(j).Width), INIFile
Else
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).NewRow&quot;), CStr(ControlX.Bands.Item(j).NewRow), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Position&quot;), CStr(ControlX.Bands.Item(j).Position), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Height&quot;), CStr(ControlX.Bands.Item(j).Height), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Width&quot;), CStr(ControlX.Bands.Item(j).Width), INIFile
End If
Next j

Case &quot;SlidingDivider&quot;
On Error Resume Next
If Not ControlX.Index <> &quot;&quot; Then
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name) & &quot;.Left&quot;, CStr(ControlX.Left), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name) & &quot;.Top&quot;, CStr(ControlX.Top), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name) & &quot;.Height&quot;, CStr(ControlX.Height), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name) & &quot;.Width&quot;, CStr(ControlX.Width), INIFile
Else
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Index&quot;, CStr(ControlX.Index), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Left&quot;, CStr(ControlX.Left), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Top&quot;, CStr(ControlX.Top), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Height&quot;, CStr(ControlX.Height), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Width&quot;, CStr(ControlX.Width), INIFile
End If

End Select ' Case TypeName(ControlX)

Next i

End Sub

Public Sub INI_SaveControlValues(ByVal frm As Form, ByVal INIFile As String, Optional ByVal SaveOthers As Boolean = False)

' Function: INI_SaveControlValues
'
' Place in Form_UnLoad to save the values for
' the controls you pass in the array. This
' function is mainly used for saving user-
' defined options/settings such as check-
' boxes and radio buttons. Currently only
' supports controls with the Value property
'
' Ex: INI_SaveControlValues Me, &quot;c:\windows\myini.ini&quot;

Dim i As Long ' Control counter
Dim j As Long ' ListView columnheader counter
Dim ControlX As Control
Dim ControlX_Type As String
Dim ControlX_Val As Variant

' Loop through all the controls
For i = 0 To frm.Controls.Count - 1
' Get the current control
Set ControlX = frm.Controls(i)

ControlX_Val = &quot;&quot;
' Determine what kind of control this is
' and get the data accordingly.
ControlX_Type = TypeName(ControlX)

Select Case ControlX_Type

' Controls having to do with setting options
Case &quot;CheckBox&quot;
ControlX_Val = ControlX.Value
Case &quot;OptionButton&quot;
ControlX_Val = ControlX.Value
Case &quot;Slider&quot;
ControlX_Val = ControlX.Value
Case &quot;HScrollBar&quot;
ControlX_Val = ControlX.Value
Case &quot;VScrollBar&quot;
ControlX_Val = ControlX.Value

' Controls having to do with file access
Case &quot;FolderTreeview&quot;
ControlX_Val = ControlX.SelectedFolder
Case &quot;DriveListBox&quot;
ControlX_Val = ControlX.Drive
Case &quot;DirListBox&quot;
ControlX_Val = ControlX.path
Case &quot;FileListBox&quot;
ControlX_Val = ControlX.path
Case &quot;CcXploreListView&quot;
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.CurrentFolder&quot;), CStr(ControlX.CurrentFolder), INIFile
If ControlX.Pattern = &quot;&quot; Then ControlX.Pattern = &quot;*.*&quot;: WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Pattern&quot;), CStr(ControlX.Pattern), INIFile

Case &quot;CcXploreTreeView&quot;
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.CurrentFolder&quot;), CStr(ControlX.CurrentFolder), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.RootFolder&quot;), CStr(ControlX.RootFolder), INIFile

' Usually will not be saved
Case &quot;TextBox&quot;
If SaveOthers = True And ControlX.PasswordChar = &quot;&quot; Then ControlX_Val = ControlX.Text
Case &quot;ComboBox&quot;
ControlX_Val = ControlX.Text

End Select

' Save the values for each control if there is one associated with it
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
If ControlX_Val <> &quot;&quot; Or ControlX_Type = &quot;TextBox&quot; Or ControlX_Type = &quot;ComboBox&quot; Then WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Value&quot;), CStr(ControlX_Val), INIFile
Else
If ControlX_Val <> &quot;&quot; Or ControlX_Type = &quot;TextBox&quot; Or ControlX_Type = &quot;ComboBox&quot; Then WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Value&quot;), CStr(ControlX_Val), INIFile
End If

Next i

End Sub

Public Sub INI_SaveForm(ByVal frm As Form, Optional ByVal INIFile As String, Optional ByVal SaveOthers As Boolean)

' This function calls it's 3 child functions

' Create a generic INI name from the App title
If INIFile = &quot;&quot; Then INIFile = App.path & &quot;\&quot; & App.Title & &quot;.ini&quot;

Call INI_SaveFormPos(frm, INIFile)
Call INI_SaveControlPos(frm, INIFile)
Call INI_SaveControlValues(frm, INIFile, SaveOthers)

End Sub

Public Sub INI_SaveFormPos(ByVal frm As Form, ByVal INIFile As String)

' Function: INI_SaveFormPosition
'
' Place in Form_Unload to save the form's position and size
' so you can retrieve them in Form_Load with INI_LoadFormPosition


' We don't want to save data when the form is minimized or
' maximized because we get strange numbers.
If frm.WindowState = 1 Then Exit Sub

If frm.WindowState = 0 Then
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Left&quot;, CStr(frm.Left), INIFile) ' Form.Left
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Top&quot;, CStr(frm.Top), INIFile) ' Form.Top

Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Height&quot;, CStr(frm.Height), INIFile) ' Form.Height
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Width&quot;, CStr(frm.Width), INIFile) ' Form.Width
End If

Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Tag&quot;, CStr(frm.Tag), INIFile) ' Form.Tag

If frm.WindowState = vbMaximized Then ' Form.WindowState
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.WindowState&quot;, CStr(frm.WindowState), INIFile)
Else
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.WindowState&quot;, &quot;&quot;, INIFile)
End If

End Sub

Public Sub INI_Write(ByVal Section As String, ByVal KeyName As String, ByVal vValue As Variant, Optional ByVal INIFile As String)

' Function: INI_Write
'
' Writes a value to an INI
'
' [Section]
' KeyName = Value

' Create a generic INI name from the App title
If INIFile = &quot;&quot; Then INIFile = App.path & &quot;\&quot; & App.Title & &quot;.ini&quot;

Call WritePrivateProfileString(Section, CStr(KeyName), CStr(vValue), INIFile)

End Sub


 
I don't know where I got it. I will copy it here (hope it's OK to post so much text):

Option Explicit

' Read INI functions
Private Declare Function GetPrivateProfileInt Lib &quot;kernel32&quot; Alias &quot;GetPrivateProfileIntA&quot; (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib &quot;kernel32&quot; Alias &quot;GetPrivateProfileStringA&quot; (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

' Write INI function
Private Declare Function WritePrivateProfileString Lib &quot;kernel32&quot; Alias &quot;WritePrivateProfileStringA&quot; (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
'

Public Sub INI_LoadControlPos(ByVal frm As Form, ByVal INIFile As String)

Dim i As Long
Dim j As Long
Dim buff As String
Dim ControlX As Control
Dim cIndex As Integer

' Loop through all the controls
For i = 0 To frm.Controls.Count - 1
' Get the current control
Set ControlX = frm.Controls(i)

Select Case TypeName(ControlX)
Case &quot;ListView&quot;
For j = 1 To ControlX.ColumnHeaders.Count
' Save the width of each columnheader
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
ControlX.ColumnHeaders.Item(j).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.ColumnHeader.Item(&quot; & j & &quot;).Width&quot;, INIFile))
Else
ControlX.ColumnHeaders.Item(j).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.ColumnHeader.Item(&quot; & j & &quot;).Width&quot;, INIFile))
End If
Next j

Case &quot;CoolBar&quot;

For j = 1 To ControlX.Bands.Count
' Save the info for each band
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
ControlX.Bands.Item(j).NewRow = CBool(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).NewRow&quot;, INIFile))
ControlX.Bands.Item(j).Position = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Position&quot;, INIFile))
ControlX.Bands.Item(j).Height = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Height&quot;, INIFile))
ControlX.Bands.Item(j).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Width&quot;, INIFile))
Else
ControlX.Bands.Item(j).NewRow = CBool(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).NewRow&quot;, INIFile))
ControlX.Bands.Item(j).Position = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Position&quot;, INIFile))
ControlX.Bands.Item(j).Height = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Height&quot;, INIFile))
ControlX.Bands.Item(j).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Width&quot;, INIFile))
End If
Next j

Case &quot;SlidingDivider&quot;
On Error Resume Next
If Not ControlX.Index <> &quot;&quot; Then
ControlX.Left = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Left&quot;, INIFile))
ControlX.Top = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Top&quot;, INIFile))
ControlX.Height = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Height&quot;, INIFile))
ControlX.Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Width&quot;, INIFile))
Else
cIndex = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Index&quot;, INIFile))
ControlX(cIndex).Left = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Left&quot;, INIFile))
ControlX(cIndex).Top = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Top&quot;, INIFile))
ControlX(cIndex).Height = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Height&quot;, INIFile))
ControlX(cIndex).Width = CInt(INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Width&quot;, INIFile))
End If

End Select

Next i

End Sub

Public Sub INI_LoadControlValues(ByVal frm As Form, ByVal INIFile As String)

' Function: INI_LoadControlValues
'
' Place in Form_Load to load the values for
' the controls you pass in the array. This
' function is mainly used for saving user-
' defined options/settings such as check-
' boxes and radio buttons. Currently only
' supports controls with the Value property
'
' Ex: INI_LoadControlValues Me, &quot;c:\windows\myini.ini&quot;

Dim i As Long ' Control counter
Dim j As Long ' ListView columnheader counter
Dim ControlX As Control
Dim ControlX_Type As String
Dim ControlX_Val As String

' Loop through all the controls
For i = 0 To frm.Controls.Count - 1
' Get the current control
Set ControlX = frm.Controls(i)

' Save the values for each control if there is one associated with it
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
ControlX_Val = INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Value&quot;, INIFile)
Else
ControlX_Val = INI_Read(&quot;Control Data&quot;, frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Value&quot;, INIFile)
End If

' Determine what kind of control this is
' and get the data accordingly.
ControlX_Type = TypeName(ControlX)
Select Case ControlX_Type

Case &quot;CheckBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)
Case &quot;OptionButton&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)
Case &quot;HScrollBar&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)
Case &quot;VScrollBar&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)
Case &quot;Slider&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Value = CInt(ControlX_Val)

Case &quot;FolderTreeview&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.SelectedFolder = ControlX_Val
Case &quot;DriveListBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Drive = ControlX_Val
Case &quot;DirListBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.path = ControlX_Val
Case &quot;FileListBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.path = ControlX_Val
Case &quot;CcXploreTreeView&quot;
ControlX.CurrentFolder = INI_Read(&quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.CurrentFolder&quot;), INIFile)
Case &quot;CcXploreListView&quot;
ControlX.CurrentFolder = CStr(INI_Read(&quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.CurrentFolder&quot;), INIFile))
ControlX.Pattern = CStr(INI_Read(&quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Pattern&quot;), INIFile))
If ControlX.Pattern = &quot;&quot; Then ControlX.Pattern = &quot;*.*&quot;

Case &quot;TextBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Text = ControlX_Val
Case &quot;ComboBox&quot;
If ControlX_Val <> &quot;&quot; Then ControlX.Text = ControlX_Val

End Select

Next i

End Sub

Public Sub INI_LoadForm(ByVal frm As Form, Optional ByVal INIFile As String, Optional ResetFile As Boolean = False)

' This is for incase the file was already deleted
On Error Resume Next

' Create a generic INI name from the App title
If INIFile = &quot;&quot; Then INIFile = App.path & &quot;\&quot; & App.Title & &quot;.ini&quot;

If ResetFile = True Then Kill INIFile: Exit Sub
INI_LoadFormPos frm, INIFile
INI_LoadControlPos frm, INIFile
INI_LoadControlValues frm, INIFile

End Sub

Public Sub INI_LoadFormPos(ByVal frm As Form, ByVal INIFile As String)

' Function: INI_LoadFormPosition
'
' Place in Form_Load to place a form at its last position
' and size as long as you had INI_SaveFormPosition in that
' form's Form_Unload event.

' Don't position or resize the form if there
' are no values to read back form the ini.

Dim X As Integer
Dim buff As String

' Form.Left
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Left&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Left = CInt(buff)

' Form.Top
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Top&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Top = CInt(buff)

' Form.Height
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Height&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Height = CInt(buff)

' Form.Width
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Width&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Width = CInt(buff)

' Form.Tag
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Tag&quot;, INIFile)
If buff <> &quot;&quot; Then frm.Tag = CStr(buff)

' Form.WindowState
buff = INI_Read(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.WindowState&quot;, INIFile)
If buff <> &quot;&quot; Then frm.WindowState = vbMaximized

End Sub

Public Function INI_Read(ByVal Section As String, ByVal KeyName As String, Optional ByVal INIFile As String) As Variant

' Function: INI_Read
'
' Reads back a value from an INI
'
' [Section]
' KeyName = Value

' Create a generic INI name from the App title
If INIFile = &quot;&quot; Then INIFile = App.path & &quot;\&quot; & App.Title & &quot;.ini&quot;

Dim X As Integer
Dim buff As String

buff = Space(255)
X = GetPrivateProfileString(Section, CStr(KeyName), vbNullString, buff, 255, INIFile)
INI_Read = Left(buff, X)

End Function

Public Function INI_ReadBool(ByVal Section As String, ByVal KeyName As String, ByVal INIFile As String) As Boolean

' Function: INI_ReadValue
'
' Reads back a value from an INI

Dim X As Integer
Dim buff As String

buff = Space(255)
X = GetPrivateProfileString(Section, CStr(KeyName), vbNullString, buff, 255, INIFile)
If LCase(Left(buff, X)) = &quot;true&quot; Or LCase(Left(buff, X)) = &quot;1&quot; Then INI_ReadBool = True Else INI_ReadBool = False

End Function

Public Sub INI_SaveControlPos(ByVal frm As Form, ByVal INIFile As String)

Dim i As Long
Dim j As Long
Dim ControlX As Control

' Loop through all the controls
For i = 0 To frm.Controls.Count - 1
' Get the current control
Set ControlX = frm.Controls(i)

' Save some specials values for ListView's and CoolBar's
Select Case TypeName(ControlX)
Case &quot;ListView&quot;

For j = 1 To ControlX.ColumnHeaders.Count
' Save the width of each columnheader
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.ColumnHeader.Item(&quot; & j & &quot;).Width&quot;), CStr(ControlX.ColumnHeaders.Item(j).Width), INIFile
Else
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.ColumnHeader.Item(&quot; & j & &quot;).Width&quot;), CStr(ControlX.ColumnHeaders.Item(j).Width), INIFile
End If
Next j

Case &quot;CoolBar&quot;

For j = 1 To ControlX.Bands.Count
' Save the info for each band
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).NewRow&quot;), CStr(ControlX.Bands.Item(j).NewRow), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Position&quot;), CStr(ControlX.Bands.Item(j).Position), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Height&quot;), CStr(ControlX.Bands.Item(j).Height), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Bands.Item(&quot; & j & &quot;).Width&quot;), CStr(ControlX.Bands.Item(j).Width), INIFile
Else
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).NewRow&quot;), CStr(ControlX.Bands.Item(j).NewRow), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Position&quot;), CStr(ControlX.Bands.Item(j).Position), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Height&quot;), CStr(ControlX.Bands.Item(j).Height), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Bands.Item(&quot; & j & &quot;).Width&quot;), CStr(ControlX.Bands.Item(j).Width), INIFile
End If
Next j

Case &quot;SlidingDivider&quot;
On Error Resume Next
If Not ControlX.Index <> &quot;&quot; Then
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name) & &quot;.Left&quot;, CStr(ControlX.Left), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name) & &quot;.Top&quot;, CStr(ControlX.Top), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name) & &quot;.Height&quot;, CStr(ControlX.Height), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name) & &quot;.Width&quot;, CStr(ControlX.Width), INIFile
Else
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Index&quot;, CStr(ControlX.Index), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Left&quot;, CStr(ControlX.Left), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Top&quot;, CStr(ControlX.Top), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Height&quot;, CStr(ControlX.Height), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot;) & &quot;.Width&quot;, CStr(ControlX.Width), INIFile
End If

End Select ' Case TypeName(ControlX)

Next i

End Sub

Public Sub INI_SaveControlValues(ByVal frm As Form, ByVal INIFile As String, Optional ByVal SaveOthers As Boolean = False)

' Function: INI_SaveControlValues
'
' Place in Form_UnLoad to save the values for
' the controls you pass in the array. This
' function is mainly used for saving user-
' defined options/settings such as check-
' boxes and radio buttons. Currently only
' supports controls with the Value property
'
' Ex: INI_SaveControlValues Me, &quot;c:\windows\myini.ini&quot;

Dim i As Long ' Control counter
Dim j As Long ' ListView columnheader counter
Dim ControlX As Control
Dim ControlX_Type As String
Dim ControlX_Val As Variant

' Loop through all the controls
For i = 0 To frm.Controls.Count - 1
' Get the current control
Set ControlX = frm.Controls(i)

ControlX_Val = &quot;&quot;
' Determine what kind of control this is
' and get the data accordingly.
ControlX_Type = TypeName(ControlX)

Select Case ControlX_Type

' Controls having to do with setting options
Case &quot;CheckBox&quot;
ControlX_Val = ControlX.Value
Case &quot;OptionButton&quot;
ControlX_Val = ControlX.Value
Case &quot;Slider&quot;
ControlX_Val = ControlX.Value
Case &quot;HScrollBar&quot;
ControlX_Val = ControlX.Value
Case &quot;VScrollBar&quot;
ControlX_Val = ControlX.Value

' Controls having to do with file access
Case &quot;FolderTreeview&quot;
ControlX_Val = ControlX.SelectedFolder
Case &quot;DriveListBox&quot;
ControlX_Val = ControlX.Drive
Case &quot;DirListBox&quot;
ControlX_Val = ControlX.path
Case &quot;FileListBox&quot;
ControlX_Val = ControlX.path
Case &quot;CcXploreListView&quot;
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.CurrentFolder&quot;), CStr(ControlX.CurrentFolder), INIFile
If ControlX.Pattern = &quot;&quot; Then ControlX.Pattern = &quot;*.*&quot;: WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Pattern&quot;), CStr(ControlX.Pattern), INIFile

Case &quot;CcXploreTreeView&quot;
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.CurrentFolder&quot;), CStr(ControlX.CurrentFolder), INIFile
WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.RootFolder&quot;), CStr(ControlX.RootFolder), INIFile

' Usually will not be saved
Case &quot;TextBox&quot;
If SaveOthers = True And ControlX.PasswordChar = &quot;&quot; Then ControlX_Val = ControlX.Text
Case &quot;ComboBox&quot;
ControlX_Val = ControlX.Text

End Select

' Save the values for each control if there is one associated with it
' But first check if the control is part of an array
On Error Resume Next
If (Not ControlX.Index <> &quot;&quot;) Then
If ControlX_Val <> &quot;&quot; Or ControlX_Type = &quot;TextBox&quot; Or ControlX_Type = &quot;ComboBox&quot; Then WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;.Value&quot;), CStr(ControlX_Val), INIFile
Else
If ControlX_Val <> &quot;&quot; Or ControlX_Type = &quot;TextBox&quot; Or ControlX_Type = &quot;ComboBox&quot; Then WritePrivateProfileString &quot;Control Data&quot;, CStr(frm.Name & &quot;.&quot; & ControlX.Name & &quot;(&quot; & ControlX.Index & &quot;)&quot; & &quot;.Value&quot;), CStr(ControlX_Val), INIFile
End If

Next i

End Sub

Public Sub INI_SaveForm(ByVal frm As Form, Optional ByVal INIFile As String, Optional ByVal SaveOthers As Boolean)

' This function calls it's 3 child functions

' Create a generic INI name from the App title
If INIFile = &quot;&quot; Then INIFile = App.path & &quot;\&quot; & App.Title & &quot;.ini&quot;

Call INI_SaveFormPos(frm, INIFile)
Call INI_SaveControlPos(frm, INIFile)
Call INI_SaveControlValues(frm, INIFile, SaveOthers)

End Sub

Public Sub INI_SaveFormPos(ByVal frm As Form, ByVal INIFile As String)

' Function: INI_SaveFormPosition
'
' Place in Form_Unload to save the form's position and size
' so you can retrieve them in Form_Load with INI_LoadFormPosition


' We don't want to save data when the form is minimized or
' maximized because we get strange numbers.
If frm.WindowState = 1 Then Exit Sub

If frm.WindowState = 0 Then
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Left&quot;, CStr(frm.Left), INIFile) ' Form.Left
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Top&quot;, CStr(frm.Top), INIFile) ' Form.Top

Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Height&quot;, CStr(frm.Height), INIFile) ' Form.Height
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Width&quot;, CStr(frm.Width), INIFile) ' Form.Width
End If

Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.Tag&quot;, CStr(frm.Tag), INIFile) ' Form.Tag

If frm.WindowState = vbMaximized Then ' Form.WindowState
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.WindowState&quot;, CStr(frm.WindowState), INIFile)
Else
Call WritePrivateProfileString(&quot;Form Data&quot;, CStr(frm.Name) & &quot;.WindowState&quot;, &quot;&quot;, INIFile)
End If

End Sub

Public Sub INI_Write(ByVal Section As String, ByVal KeyName As String, ByVal vValue As Variant, Optional ByVal INIFile As String)

' Function: INI_Write
'
' Writes a value to an INI
'
' [Section]
' KeyName = Value

' Create a generic INI name from the App title
If INIFile = &quot;&quot; Then INIFile = App.path & &quot;\&quot; & App.Title & &quot;.ini&quot;

Call WritePrivateProfileString(Section, CStr(KeyName), CStr(vValue), INIFile)

End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top