Nov 14th, 2002, 06:33 PM
#1
Thread Starter
Lively Member
Reading From Ini setting values(Solved)
How would I Read from the Ini and set a value to a check.
Last edited by finstajr; Nov 16th, 2002 at 07:18 AM .
Nov 14th, 2002, 06:40 PM
#2
New Member
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
Nov 14th, 2002, 06:40 PM
#3
Frenzied Member
Nov 14th, 2002, 06:43 PM
#4
Thread Starter
Lively Member
I'm a newb so that won't help
Nov 14th, 2002, 10:44 PM
#5
Lively Member
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
Nov 15th, 2002, 03:31 PM
#6
Thread Starter
Lively Member
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
Nov 15th, 2002, 05:58 PM
#7
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
Nov 15th, 2002, 05:59 PM
#8
Thread Starter
Lively Member
Last edited by finstajr; Nov 15th, 2002 at 06:08 PM .
Nov 15th, 2002, 06:24 PM
#9
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.
Nov 15th, 2002, 06:29 PM
#10
Thread Starter
Lively Member
err... I'm a newb so that's why i'm asking
Nov 15th, 2002, 07:03 PM
#11
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".
Attached Files
Nov 15th, 2002, 07:05 PM
#12
Thread Starter
Lively Member
Nov 15th, 2002, 07:58 PM
#13
Thread Starter
Lively Member
Nov 15th, 2002, 10:18 PM
#14
Lively Member
Nov 16th, 2002, 01:21 AM
#15
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.
Last edited by jdc2000; Nov 16th, 2002 at 01:38 AM .
Nov 16th, 2002, 07:16 AM
#16
Thread Starter
Lively Member
It Works!!!.....
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width