Results 1 to 12 of 12
  1. #1
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Retrieving information from an ini file (Office 2003)

    I have an ini file which I am using to populate information into a document. A few of the parameters within the ini file contain about five lines of text. When I pick up the parameter and save it to a string I am only getting part of the text not all (about 10 words are being missed from the end of the parameter).

    Has anyone come across this problem before?

    Any help, greatly appreciated.
    Jack

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieving information from an ini file (Office 2003)

    The standard method for retrieving information from an ini file returns a string with a maximum length of 256 characters.

    One workaround is to break up the value into several keys in the ini file, each with a length of 256 characters or less, and assemble them into one string in code.

    Another workaround is to open the ini file as a standard text file, and use the instructions for reading data from a text file to retrieve the string.

  3. #3
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieving information from an ini file (Office 2003)

    Hi Hans

    Is this a Microsoft Word 2003 issue? I only ask as one of the team is working in Word XP and is not gettting the problem.

    Thanks
    Jack

  4. #4
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieving information from an ini file (Office 2003)

    I'm using System.PrivateProfileString as well.

    Regards
    Jack

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieving information from an ini file (Office 2003)

    I am using Office XP SP3. I did a test in Word VBA. A long string value in an ini file was truncated to 256 characters when I retrieved it using System.PrivateProfileString.

    Which method are you using to retrieve the value?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieving information from an ini file (Office 2003)

    Can you double check that your team member with Word 2002/XP is not experiencing the problem?

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieving information from an ini file (Offic

    > Has anyone come across this problem before?

    Frequently.

    I have three options in my environment routines

    #Const Mechanism = "L" - low-volume, strings < 256, INI file < 65K
    #Const Mechanism = "H" - high volume , strings > 256, INI file >65K
    #Const Mechanism = "R" - use the standard VBA System registry method

  8. #8
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieving information from an ini file (Offic

    Thanks for this .... but where do I need to place the code. I have put this with my constants and also within the function but am still not able to pick up all the text. Do I need to do anything else?

    Apologies for being a bit thick !!!!
    Regards
    Jack

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieving information from an ini file (Offic

    You're not thick - I sent you the smallest piece of code I thought that i could post without overwhelming the lounge. Attached is the current version of my module for Word; Excel etc. vary slightly in the details.

    Most of these (attached) procedures contain embedded testing procedures. You can drag out the commented "SUB TEST", decomment, and run it to see what it does.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieving information from an ini file (Offic

    Chris,

    At the core of your code is a function strGetFileData; this is not included in the module you posted, however, so Jack still doesn't know how you get long strings out of the ini file.

  11. #11
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieving information from an ini file (Offic

    Hi Chris

    Many thanks for your help. I have since solved the "string" issue I had. Someone in the office had been dealing with string manipulation and we have been able to incorporate the below function into the VBA code.


    Declare Function GetPrivateProfileString Lib "kernel32.dll" 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

    The Function is:
    Public Function GetIniString(pINIFile As String, pSection As String, pstrParameter As String, pstrValue As String) As String

    Dim Buffer As String * 1024
    Dim nChars As Long

    nChars = GetPrivateProfileString(pSection, pstrParameter, pstrValue, Buffer, Len(Buffer), pINIFile)
    GetIniString = Mid(Buffer, 1, nChars)

    End Function

    I was able to pass in the relevant information and was able to pick up all the text from the ini file.

    Many thanks for your help though.
    Regards
    Jack

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieving information from an ini file (Offic

    >this is not included in the module you posted

    Quite so. I decided not to post the bulk of my utils.DOT (It's over 100K!) but wanted Jack to get some idea of how I coped with three different mechanisms for obtaining data. The Module posted has all the code relevant to stripping sections, keys, data etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •