?
Solved

Get Command Box Caption from .ini

Posted on 2008-02-08
4
Medium Priority
?
214 Views
Last Modified: 2012-06-21
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:
One
Two
Three
Four

using vb6pro
0
Comment
Question by:daneburr
  • 2
3 Comments
 
LVL 77

Expert Comment

by:GrahamSkan
ID: 20856657
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

0
 
LVL 77

Accepted Solution

by:
GrahamSkan earned 1000 total points
ID: 20856703
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
    Do
        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

0
 
LVL 1

Expert Comment

by:Computer101
ID: 21160189
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 16 hours left to enroll

601 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