Solved

ini files and comboboxes (VBA)

Posted on 2004-09-23
4
474 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mirrorEnds challenge 6 82
MaxSpan challenge 9 65
method argument as final 1 62
groovy example issue 10 65
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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 …
The viewer will learn how to implement Singleton Design Pattern in Java.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

771 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

10 Experts available now in Live!

Get 1:1 Help Now