Solved

ini files and comboboxes (VBA)

Posted on 2004-09-23
4
479 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This video teaches viewers about errors in exception handling.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

803 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