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!

Option button value in ini-file

Status
Not open for further replies.

speek

Technical User
Mar 29, 2008
25
US
The values of option buttons are stored in the ini-file as true/false. When I start the program these values are not loaded. But if I change true/false in the ini-file manually to 1/0, the values are loaded correctly. Is this a known VB6 problem? What should I change to make things work?

Speek
 
VB does not recognize the string "True", as is appears in the INI, to be the same as a value True to be assigned to the Option Button.

To affect that change in your program, you could try something like

if (TextFromINI = "True") then
optRadio.Value = True
else
optRadio.Value = False
endif
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
Hi CajunCenturion,

Thanks for your help. One question: how should I define "TextFromINI"?

Speek
 
Please post the code which you are using the read the INI right now.
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
OK, here it is:

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 = "" Then INIFile = App.Path & "\" & App.Title & ".ini"

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_LoadControlValues(ByVal frm As Form, ByVal INIFile As String)

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)

etc.
 

Case &quot;OptionButton&quot;
if (ControlX_Val = &quot;True&quot;) then
ControlX.Value = True
else
ControlX.Value = False
endif



Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
CajunCenturion,

Thanks a bundle!!! It works like a charm.
Jippee :)

Speek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top