Results 1 to 16 of 16

Thread: Reading From Ini setting values(Solved)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    114

    Unhappy 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.

  2. #2
    New Member
    Join Date
    Sep 2001
    Posts
    13

    Smile

    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

  3. #3
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    114
    I'm a newb so that won't help

  5. #5
    Lively Member
    Join Date
    Sep 2001
    Location
    Philippines
    Posts
    75
    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
    tazzzman2001
    [email protected]

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    114
    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

  7. #7
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    In a Module, add:

    VB Code:
    1. Declare Function GetPrivateProfileStringByKeyName& Lib _
    2. "kernel32" Alias "GetPrivateProfileStringA" _
    3. (ByVal lpApplicationName$, ByVal lpszKey$, ByVal lpszDefault$, ByVal lpszReturnBuffer$, ByVal cchReturnBuffer&, ByVal lpszFile$)

    In the form with Check1, add:

    VB Code:
    1. Public strMySystemFile
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     Dim strTemp1 As String
    6.  
    7.     strMySystemFile = "ctrl.ini"
    8.     strTemp1 = ReadFromFile("Setting","Minimizable")
    9.     If UCase$(strTemp1) = "YES" Then Check1.Value = 1
    10.     If UCase$(strTemp1) = "NO" THen Check1.Value = 0
    11.  
    12. End Sub
    13.  
    14.  
    15. Function ReadFromFile(strFileSection As String, strKey As String) As String
    16.  
    17.     Dim strValue As String
    18.     Dim lngRetLen As Long
    19.  
    20.     strValue = String(READ_BUFF + 1, Space(1))
    21.     lngRetLen = GetPrivateProfileStringByKeyName(strFileSection, strKey, "", strValue, READ_BUFF, strMySystemFile)
    22.     If lngRetLen > 1 Then
    23.         ReadFromFile = Left(strValue, lngRetLen)
    24.     Else
    25.         ReadFromFile = ""
    26.     End If
    27.  
    28. End Function

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    114
    It doesn't work
    Last edited by finstajr; Nov 15th, 2002 at 06:08 PM.

  9. #9
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    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.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    114
    err... I'm a newb so that's why i'm asking

  11. #11
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    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 Attached Files

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    114
    I'll try it

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    114
    bump....HELP>>>>>

  14. #14
    Lively Member ranma_at's Avatar
    Join Date
    Oct 2002
    Location
    @ Home
    Posts
    72

  15. #15
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    Add the Form_Load code below to your form:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim strTemp1 As String
    4.     strMySystemFile = App.Path & "\RA2MD.ini"
    5.     strTemp1 = ReadFromFile("Video", "AllowHiResModes")
    6.     If UCase$(strTemp1) = "YES" Then Check2.Value = 1
    7.     If UCase$(strTemp1) = "NO" Then Check2.Value = 0
    8.     strTemp1 = ReadFromFile("Video", "AllowVRAMSidebar")
    9.     If UCase$(strTemp1) = "YES" Then Check3.Value = 1
    10.     If UCase$(strTemp1) = "NO" Then Check3.Value = 0
    11.     strTemp1 = ReadFromFile("Video", "VideoBackBuffer")
    12.     If UCase$(strTemp1) = "YES" Then Check4.Value = 1
    13.     If UCase$(strTemp1) = "NO" Then Check4.Value = 0
    14.  
    15.    
    16. 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.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    114
    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
  •  



Click Here to Expand Forum to Full Width