Get Command Box Caption from .ini

This should be simple but its been awhile 4 me...
I have 4 Command Boxes: Command1, Command2, Command3, Command4.
In the form load I need all to command box captions to change according to an .ini file (path/name) c:\vbTest.ini
In the .ini It has this:
1- One
2- Two
3- Three
4- Four
I need the caption on the actual command box to have only the letters, Like:

using vb6pro
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There are some API's for saving and reading files in the .ini format.
The snippet shows how to use both.
Option Explicit
Private 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
Private 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
Private Sub SaveMySetting()
Dim r As Long
r = WritePrivateProfileString("MyApp", "1", "One", "C:\vbTest.ini")
End Sub
Private Sub Form_Load()
Dim strBuffer As String * 20
Dim strEntry As String
Dim r As Long
Dim l As Long
l = 20
r = GetPrivateProfileString("MyApp", "1", "", strBuffer, l, "C:\vbTest.ini")
strEntry = Left$(strBuffer, l)
End Sub

Open in new window

If you want to use your own format, you will have to open the file and process each line

Private Sub Form_Load()
Dim f As Integer
Dim strLine As String
Dim strLineParts() As String
f = FreeFile
Open "C:\vbTest.ini" For Input As #f
        Line Input #f, strLine
        strLineParts = Split(strLine, "-")
        Me.Controls("Command" & Trim$(strLineParts(0))).Caption = Trim$(strLineParts(1))
    Loop Until EOF(f)
Close #f
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Forced accept.

EE Admin
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.