Solved

ini files and comboboxes (VBA)

Posted on 2004-09-23
4
477 Views
Last Modified: 2012-06-21
Novice:  I am trying to figure out how to get all the keys within a section of my ini file to populate a combobox on my user form.  Is this possible?  I was using text files for input.  But that required several text files for each form.  So I created an ini file, but I'm not sure how to retrieve the information.  Also, can I write to an ini file based on a user's selection?

For example the section is "author", the keys are a list of author names.

Thanks for any guidance.  -- JTG
0
Comment
Question by:jtaylerg
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:thunder_moose
ID: 12142067
Hey there,

Could you give a bit more information? Perhaps paste the .ini file you created here? The code would be different depending on how it's formatted.

Thanks,
TM



0
 

Author Comment

by:jtaylerg
ID: 12146237
Hi TM,

As I mentioned, I'm a novice and may not be formatting correctly.  But here's the text:

[Author]
A1="John Smith"
A2="Jane Doe"
A3="George Johnson"
A4="Steve Martin"

[Delivery]
D1="Via FedEx"
D2="Via Facsimile"
D3="Via U.S. Mail"
D4="Personal & Confidential"

[Closing]
C1="Sincerely"
C2="Very truly yours"
C3="Best regards"

Thanks -- JTG
0
 
LVL 3

Accepted Solution

by:
thunder_moose earned 250 total points
ID: 12162278
Hey again,

Sorry for taking so long to get back to you, but it was weekend and all. Easy enough to do what you want. To read out the authors the code would look something like this:

Sub Populate_Combo()
Dim intFreeFile As Integer, intEntryLen As Integer, intQuotePos As Integer
Dim intLen As Integer
Dim sTemp As String

intFreeFile = FreeFile
Open "C:\YourIni.Ini" For Input As intFreeFile

While Not EOF(intFreeFile)
      Line Input #intFreeFile, sTemp
      If Len(sTemp) Then
         If InStr(sTemp, "[Authors]") Then
            Do
               Line Input #intFreeFile, sTemp
               intEntryLen = Len(sTemp)
               intQuotePos = InStr(sTemp, Chr(34)) + 1
               intLen = intEntryLen - intQuotePos
               If intLen < 0 Then intLen = 0
               sTemp = Mid(sTemp, intQuotePos, intLen)
               If Len(sTemp) And InStr(sTemp, "[") = 0 Then
                  ComboBox1.AddItem (sTemp)
               End If
            Loop Until InStr(sTemp, "[")
         End If
      End If
Wend

Close #intFreeFile

End Sub

To use it just put "Populate_Combo" in the Load event of your form. Please note that this a quick and dirty one, since I don't have a lot of time at the moment. It should do what you want though, just change the name of the combo to yours (if changed) and change ini file to the one you're using.

Best of luck,
TM
0
 

Author Comment

by:jtaylerg
ID: 12166346
Thanks so much for getting back to me.  

I'm looking forward to giving this a try and dumping the multiple txt files.

Have a good week and thanks again.

JTG
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 94
t-sql sp_addlinkedserver possible risks 3 53
Way to decrease size of apk file 9 43
Interview question Javascript, database 12 31
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now