?
Solved

Ini files

Posted on 1999-07-07
15
Medium Priority
?
455 Views
Last Modified: 2010-05-02
I am creating an ini for my app but I'm not sure how to take out the quotes.  All ini files that I've seen do not have any.  Any thoughts?
0
Comment
Question by:markg1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 1

Expert Comment

by:stewfidgeon
ID: 1522438
What quotes? Eh?

0
 

Author Comment

by:markg1
ID: 1522439
Sorry, in my ini it's like this:
[operating system]
"Windows 95"
"Windows 98"
"Windows NT"

In all the ini files I've seen there are no quotes.
I am using the ini to add items to combo boxes.
0
 
LVL 6

Expert Comment

by:VBGuru
ID: 1522440
use WritePrivateProfileString and GetPrivateProfileString APIs to save/load data with INI files
for more info
http://www.matthart.com/vbhelp/vbmain.htm#INIEX
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:stewfidgeon
ID: 1522441
Ok, what code are you using to write to the ini file? Presumably with the WritePrivateProfileString API???
0
 
LVL 1

Expert Comment

by:stewfidgeon
ID: 1522442
if you use the code below, you shouldn't get any "" in your file.

Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

That bit goes in a module's declaration section.

This bit goes in your form or function.

lngBytesReturned = WritePrivateProfileString("operating system", "OS", "Windows NT", strTargetPath)

Where lngBytesReturned =1 if the call succeeds, or 0 if it fails. "OS" can be replaced by your own line description, strTargetPath is the location of the ini file, and "Windows NT" is the text you wish to write to the file. You can replace "Windows NT" wit Cstr(var), where var is a variable whose value you wish to write to the file.

Does that answer it?? Lemme know if you need any more help.

0
 

Author Comment

by:markg1
ID: 1522443
I am not that familiar with VB and I am just fooling around with how it works.
What I want to do is use an ini file to add those items to a combo box.
0
 
LVL 1

Expert Comment

by:stewfidgeon
ID: 1522444
That wasnt what you asked. Never mind, heres the solution to your next question.

'This bit is declared in a module

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

Public Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long



' This bit goes in you form load procedure
Dim x As Integer
Dim numentries As String * 255
Dim Counter As Integer
Dim lngBytesReturned As Long
Dim strIniPath As String
Dim strComboValue As String * 255
Dim strTrimedValue As String

strIniPath = "C:\temp.ini"

lngBytesReturned = GetPrivateProfileString("NumItems", "Numberofitems", "", numentries, Len(numentries), strIniPath)

Counter = CInt(Left(numentries, InStr(numentries, Chr(0)) - 1))

For x = 1 To Counter
    lngBytesReturned = GetPrivateProfileString("OperatingSystem", "Value" & Right$(CStr(x), 1), "", strComboValue, Len(strComboValue), strIniPath)
    strTrimedValue = Left(strComboValue, InStr(strComboValue, Chr(0)) - 1)
    Combo1.AddItem strTrimedValue
Next x


It read the number of entries to put into the combo box from the ini file, and then reads their values and puts them into a combo box.
0
 

Author Comment

by:markg1
ID: 1522445
Sorry for the misunderstanding.
Could you explain how the counter works more fully.
I've only been fooling with this for a few months, so I'm not that swift.
0
 

Author Comment

by:markg1
ID: 1522446
Sorry for the misunderstanding.
Could you explain how the counter works more fully.
I've only been fooling with this for a few months, so I'm not that swift.
0
 
LVL 1

Expert Comment

by:TDragon
ID: 1522447
good code stewfidgeon

markg1:
The counter would be used to tell your program how many operating systems there are to load into the combo box.

Here is what your INI would look like to work with my modifications to stewfidgeon's code (listed after this):

[OperatingSystems]
Count     = 3
Value1    = Windows 95
Value2    = Windows 98
Value3    = Windows NT

Here is my version (I'll explain the differences at the bottom):

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

Public Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long



' This bit goes in you form load procedure
Dim x As Integer
Dim numentries As String * 255
Dim Counter As Integer
Dim lngBytesReturned As Long
Dim strIniPath As String
Dim strComboValue As String * 255
Dim strTrimedValue As String

strIniPath = "C:\temp.ini"

lngBytesReturned = GetPrivateProfileString("OperatingSystems", "Count", "", numentries, Len(numentries), strIniPath)

Counter = CInt(Left(numentries, lngBytesReturned))

For x = 1 To Counter
    lngBytesReturned = GetPrivateProfileString("OperatingSystems", "Value" & trim(CStr(x)), "", strComboValue, Len(strComboValue), strIniPath)
    strTrimedValue = Left(strComboValue, lngBytesReturned)
    Combo1.AddItem strTrimedValue
Next x


MY CHANGES:
Basically the code was all there, just changed it to get the count from the same SECTION of the INI as the items you were reading.  This would allow you to store multiple item lists in the same file and have a separate COUNT in each related SECTION.
If you programmatically, or manually, add an item you would need to increase the COUNT for the related section and add a VALUE# for the new item.  (Which is why I removed the single digit limit from stewfidgeon's code (where is was reading VALUE#))

stewfidgeon had all the information, I just wanted to add a little extra help while explaining the COUNT thing.

0
 

Author Comment

by:markg1
ID: 1522448
Thanks, I get it now.
I thought the count was getting created dynamically by going though the ini file, rather than it's value being in the ini file.
0
 
LVL 1

Accepted Solution

by:
stewfidgeon earned 200 total points
ID: 1522449
The counter was just an idea so you could put the code into a function. That way you'd not need to change the value of numentries, which is the number of items to add to the list box.

You could change it, so that the combobox name and ini file headers/name were passed to the function aswell. Then you could use it to fill any combobox with any values from an ini file. :-)
0
 
LVL 1

Expert Comment

by:stewfidgeon
ID: 1522450
A good modification TDragon. I was getting a lil bit lazy with that single digit thing :)
0
 

Author Comment

by:markg1
ID: 1522451
Thanks for your help.  Sorry for being so dense.
0
 
LVL 1

Expert Comment

by:stewfidgeon
ID: 1522452
Nah, everyone has to start somewhere.

You might wanna consider giving away fewer points for easy questions, that way you can ask more of 'em.

;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question