Solved

ini files and comboboxes (VBA)

Posted on 2004-09-23
4
489 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
[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
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 article will show, step by step, how to integrate R code into a R Sweave document
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

623 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