How would I Read from the Ini and set a value to a check.
Printable View
How would I Read from the Ini and set a value to a check.
1) On a module Declare the following Api
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
2)Try to create a function that read from Api Function ex
3)call created function from anywhere
Thry this site http://216.26.168.92/vbapi/ref/g/get...ilestring.html
I'm a newb so that won't help
Declare Function GetPrivateProfileStringByKeyName& Lib _
"kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName$, ByVal lpszKey$, ByVal lpszDefault$, ByVal lpszReturnBuffer$, ByVal cchReturnBuffer&, ByVal lpszFile$)
Function ReadFromFile(strFileSection As String, strKey As String) As String
Dim strValue As String
Dim lngRetLen As Long
strValue = String(READ_BUFF + 1, Space(1))
lngRetLen = GetPrivateProfileStringByKeyName(strFileSection, strKey, "", strValue, READ_BUFF, strMySystemFile)
If lngRetLen > 1 Then
ReadFromFile = Left(strValue, lngRetLen)
Else
ReadFromFile = ""
End If
End Function
IF YOUR INI LOOKS LIKE THIS:
[PROFILES]
CUSTNO=12345
CUSTNAME=ANDRE
ON FORM LOAD:
CustId = ReadFromFile("PROFILES", "CUSTNO") 'returns 12345
CustName = ReadFromFile("PROFILES", "NAME") 'returns ANDRE
I want to get my app to see in ctrl.ini under
[Setting]
Minimizable=yes
and if the entry is yes it sets Check1.Value = 1 but if the entry is no then the value should be 0
In a Module, add:
VB Code:
Declare Function GetPrivateProfileStringByKeyName& Lib _ "kernel32" Alias "GetPrivateProfileStringA" _ (ByVal lpApplicationName$, ByVal lpszKey$, ByVal lpszDefault$, ByVal lpszReturnBuffer$, ByVal cchReturnBuffer&, ByVal lpszFile$)
In the form with Check1, add:
VB Code:
Public strMySystemFile Private Sub Form_Load() Dim strTemp1 As String strMySystemFile = "ctrl.ini" strTemp1 = ReadFromFile("Setting","Minimizable") If UCase$(strTemp1) = "YES" Then Check1.Value = 1 If UCase$(strTemp1) = "NO" THen Check1.Value = 0 End Sub Function ReadFromFile(strFileSection As String, strKey As String) As String Dim strValue As String Dim lngRetLen As Long strValue = String(READ_BUFF + 1, Space(1)) lngRetLen = GetPrivateProfileStringByKeyName(strFileSection, strKey, "", strValue, READ_BUFF, strMySystemFile) If lngRetLen > 1 Then ReadFromFile = Left(strValue, lngRetLen) Else ReadFromFile = "" End If End Function
It doesn't work
What happens when you try it? Any error messages? Make sure that you set strMySystemFile to the correct path and file name for the ctrl.ini file on your PC. Then, put a Stop statement before and after the 'strTemp1 = ... ' statement and check the values for your variables. Post back the results.
:confused: err... I'm a newb so that's why i'm asking
Try the attached project. Make sure that strMySystemFile is set to the correct path to the ctrl.ini file. For example, if the file is in the Windows folder on the C: drive, then make sure that strMySystemFile = "C:\Windows\ctrl.ini".
I'll try it
bump....HELP>>>>>
PERFECT DEMO HERE:
http://www.planet-source-code.com/vb...=Ranma+Saotome
FULL SOURCE
Add the Form_Load code below to your form:
VB Code:
Private Sub Form_Load() Dim strTemp1 As String strMySystemFile = App.Path & "\RA2MD.ini" strTemp1 = ReadFromFile("Video", "AllowHiResModes") If UCase$(strTemp1) = "YES" Then Check2.Value = 1 If UCase$(strTemp1) = "NO" Then Check2.Value = 0 strTemp1 = ReadFromFile("Video", "AllowVRAMSidebar") If UCase$(strTemp1) = "YES" Then Check3.Value = 1 If UCase$(strTemp1) = "NO" Then Check3.Value = 0 strTemp1 = ReadFromFile("Video", "VideoBackBuffer") If UCase$(strTemp1) = "YES" Then Check4.Value = 1 If UCase$(strTemp1) = "NO" Then Check4.Value = 0 End Sub
Please let us know if this works. Post back the results of what happens.
It Works!!!.....:cool: :)