Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jan 2003
    Location
    Renfrewshire, Scotland
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB Maestro needed! (97)

    Hi,

    I've been tasked to create a function in Word 97 that will read from an .ini file user details from login details. I want to take these details to be able to use them in a Form, and to prompt for details from people who have not logged into that machine before.

    Once I get started I think I'll be able to cope, but can anyone point me in the right direction?

    Thanks!

    Alba

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB Maestro needed! (97)

    Since INI files are just plain text files you can use the File I/O commands to read the INI file line by line, checking for the information you want.

    Dim FF As Integer
    Dim strFile As String
    Dim strLine As String

    <font color=448800>'Get Free File Handle</font color=448800>
    FF = FreeFile
    strFile = "C:fullpathtoyourfile.ini"
    <font color=448800>'Open File</font color=448800>
    Open strFile For Input As #FF

    <font color=448800>'Loop through file, getting 1 line at a time</font color=448800>
    Do While Not EOF(FF)
    Input #FF, strLine
    <font color=448800>'Check to see we have hit the INI section you want</font color=448800>
    If strLine = "[Your Section]" Then
    Exit Do
    End If
    Loop

    <font color=448800>'Assumption - Next 2 lines in INI file is the information you want</font color=448800>
    Input #FF, strLine
    Debug.Print strLine

    Input #FF, strLine
    Debug.Print strLine

    <font color=448800>'Close File and File Handle</font color=448800>
    Close FF

    That should give you a good start. If you have any problems, please post back.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Perth, Western Australia, Australia
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB Maestro needed! (97)

    if you want to avoid the file open/close issues look into using System.PrivateProfileString(filename, section, key)

    This will enable you to read/write the keys directly to the file and create the ini file if one does not exist.

    It is dependent however on the ini file having the section label and key label information stored along with the user login details.

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB Maestro needed! (97)

    I knew there was a way to read INI files like that. I just couldn't come up with it.

    Thanks for the shorter, easier method.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

Posting Permissions

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