Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 3rd, 2004, 05:39 AM
Registered User
Join Date: Sep 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Read from INI file

hi everybody,
    i have a vb application that i want to read its settings from a .INI file. i could already retrieve integer values from the file, but i am having trouble retrieving strings, could anyone help me, i really need it.


Reply With Quote
  #2 (permalink)  
Old September 3rd, 2004, 06:04 AM
Friend of Wrox
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp

You can use the following function.

Private Function funcGetPrivateProfileString(ByVal sKey As String, ByVal sFile As String)
Open sFile For Input As #100
Dim sLine As String
Dim strKey As String
Dim strValue As String
Dim sRetValue As String
sRetValue = ""
Dim iPos As Integer
Do While Not EOF(100)
    Line Input #100, sLine
    iPos = InStr(1, sLine, "=")
    If iPos > 0 Then
        strKey = Mid(sLine, 1, iPos - 1)
        strValue = Mid(sLine, iPos + 1, Len(sLine))
        If strKey = sKey Then
            sRetValue = strValue
            Exit Do
        End If
    End If
Close #100
funcGetPrivateProfileString = sRetValue
End Function

Then you can call the function as below.

strTest = funcGetPrivateProfileString("<key>", "<path to ini file>/sample.ini")
Reply With Quote
  #3 (permalink)  
Old September 3rd, 2004, 06:34 AM
Friend of Wrox
Join Date: Jun 2003
Location: Cardiff, , United Kingdom.
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts

Yea, you could do it that way, however there are several Windows API functions that will do it a lot quicker for you. They are GetPrivateProfileSection, GetPrivateProfileInt and GetPrivateProfileString. They are all relatively easy to use.

Owain Williams
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read data from ini file nbryson VB How-To 5 April 2nd, 2015 05:14 AM
Reading an INI file in C# @shish C# 1 April 1st, 2015 04:00 AM
ini file ptop C++ Programming 0 January 30th, 2006 06:29 AM
How to read and update .INI files using Pure C ?? Poonam C++ Programming 1 March 24th, 2005 01:22 AM
INI file access jlick Pro VB 6 4 November 7th, 2003 05:11 AM

All times are GMT -4. The time now is 05:49 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.