Solved

ini file

Posted on 1998-06-25
12
358 Views
Last Modified: 2010-05-03
I have a menu project in vb4 pro, with 3 command buttons that I want to make customizable( command1 , command2, and command3) I have a text box (text1) to input the button number, text2 - to input the caption for that button, and text3 to input the path to the program, I then have a command4 (remember) button to apply the info in the text boxes.
Rene100 gave me this advice ,but it's not quite enough info for an idiot like myself. How exactly do I use the info?

     why don't you use a Ini-File, or even better (in win95), the windows
     registry. Then you can store the information like this:

     ini-file:
     [captions]
     button1=CaptionOfButton1
     button2=CaptionOfButton2
     ...

     [path]
     path=c:\.......

     use GetPrivateProfileString or WritePrivateProfileString to handle the data.

     When you want to use the registry, create a new key with RegCreateKey and use the
     win-api registry functions

     regards
     rene100
0
Comment
Question by:ralphy
  • 7
  • 2
  • 2
  • +1
12 Comments
 
LVL 4

Expert Comment

by:yowkee
ID: 1464287
ralphy,

  What info you actually want to save and retrieve when needed? Your textboxs were getting customize info from user and you have command4 to apply those info to 3 buttons. And then, you want to save the info when you click command4?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464288
ralphy,

  What info you actually want to save and retrieve when needed? Your textboxs were getting customize info from user and you have command4 to apply those info to 3 buttons. And then, you want to save the info when you click command4?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464289
ralphy,

  What info you actually want to save and retrieve when needed? Your textboxs were getting customize info from user and you have command4 to apply those info to 3 buttons. And then, you want to save the info when you click command4?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464290
Sorry, I don't know what happen... It just appear three posting.
Sorry if I accidentally cause this and make your unconvinient.
0
 
LVL 1

Expert Comment

by:xer_soft
ID: 1464291
ralphy,

If I were you I would set up a file some where on the hard drive that catained information for your program. Like the captions of the buttions. You could setup the file like this:

open "filename" for output as #1
print #1, information as string or number
close #1

you can use as many print #1 statments as you like but they must come befor the close #1 statement. Heres a better example:

I have a button that is changable and I want to save the information for that buttons caption. heres how I would do this:

'this code goes in the apply button
open "c:\information.dat" for output as #1
print #1, command1.caption
close #1


Then in a seperate button or in the forms load presdure put this

open "c:\information.dat" for input as #1
input #1, data1$
close #1
command1.caption = data1$

This will save the data for one command button. I hope you get the general idea with this code. If you need more help then tell me and I will make some thing and send it to you.

   -Xer

0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464292
OK, suppose you want the user input caption and execute program path for a button into textboxs, with button number in text1, caption in text2, path in text3. Then when user click the button, it will execute the appropriate program.

Since the info to save is not big, I suggest you use registry to store these data for those command button. And they could retrive the caption setting when form/application load next time.

Here's an example to use SaveSetting to save info to registry, GetSetting to retrieve from registry.

The parameter of these two functions(check them in VB help):
SaveSetting Application, Section, Key, Value of Key
ValueOfKey = GetSetting(Application, Section, Key,[Default])

Assume your app. named MyProgram, you want to store your info in two keys:Caption and Path. Code of example:

-------------------------------------------------------------
Private Const cAppName As String = "MyProgram"
Private Const cKeyCaption As String = "Caption"
Private Const cKeyPath As String = "ProgPath"

Private Sub Command4_Click()
   
    If Len(Text1.Text) = 0 Or _
       Len(Text2.Text) = 0 Or _
       Len(Text3.Text) = 0 Then
        MsgBox "Not enough info!"
        Exit Sub
    End If
   
  SaveSetting cAppName, "Command" & Val(Text1.Text), _
              cKeyCaption, Text2.Text
  SaveSetting cAppName, "Command" & Val(Text1.Text), cKeyPath, _
              Text3.Text
   
    Select Case Val(Text1.Text)
        Case 1
            Command1.Caption = Text2.Text
        Case 2
            Command2.Caption = Text2.Text
        Case 3
            Command3.Cancel = Text2.Text
    End Select
   
End Sub

Private Sub Command1_Click()
    Dim sPath As String
    sPath = GetSetting(cAppName, "Command1", cKeyPath)
    If Len(sPath) <> 0 Then
        Shell sPath, vbNormalFocus
    Else
        MsgBox "Path not set yet!"
    End If
End Sub

Private Sub Command2_Click()
    Dim sPath As String
    sPath = GetSetting(cAppName, "Command2", cKeyPath)
    If Len(sPath) <> 0 Then
        Shell sPath, vbNormalFocus
    Else
        MsgBox "Path not set yet!"
    End If

End Sub

Private Sub Command3_Click()
    Dim sPath As String
    sPath = GetSetting(cAppName, "Command3", cKeyPath)
    If Len(sPath) <> 0 Then
        Shell sPath, vbNormalFocus
    Else
        MsgBox "Path not set yet!"
    End If

End Sub

Private Sub Form_Load()
    Dim sCaption As String
   
    sCaption = GetSetting(cAppName, "Command1", cKeyCaption, "")
    If Len(sCaption) Then Command1.Caption = sCaption
   
    sCaption = GetSetting(cAppName, "Command2", cKeyCaption, "")
    If Len(sCaption) Then Command2.Caption = sCaption
   
    sCaption = GetSetting(cAppName, "Command3", cKeyCaption, "")
    If Len(sCaption) Then Command3.Caption = sCaption
   
End Sub
-------------------------------------------------------------

Hope this help.


0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Expert Comment

by:yowkee
ID: 1464293
ralphy,

  The answer is being locked when I proposed my answer. So I post as comment, if it solve your question, please let me lock the answer.
  Regards.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1464294
ralphy,
Whether using INI or not depend on how do you change the captions.
If your captions (or other infor) stay the same during a run, but you may need to change it from one run to another, INI is OK.  However, If your caption need to change to whenever the user change the content of the text box (text2), then INI is not a good choice.
You can have it applied automatically to  the button by doing this:
1. In the text2's gotfocus event, check if text1 has the button number, if not, set focus to text1,
2. in the change event of text2, add the code:

Dim lInt as Integer
On error goto handler
lInt = cInt(Text1.text)

Select case lInt
   Case 1
          Command1.Caption = Text2.text
   Case 2
          Command2.Caption = Text2.text

   Case 3
          Command3.Caption = Text2.text

   Case else
  Exit sub
Handler:
    err.clear
End Select

If you use anarray for the command, it would be even easier.

Have any questions, let me know
Regards
Dalin
0
 

Author Comment

by:ralphy
ID: 1464295
xer:
   That is the method I was using for one button, but my question was how to do multiple buttons, maybe your system would work, but your explanation wasn't precise enough. I got a comment added from Yowkee, where all I did was cut & paste his code and the project worked perfectly. I think he deserves the points.
  Thank-You
  Ralphy
0
 
LVL 4

Accepted Solution

by:
yowkee earned 300 total points
ID: 1464296
Have a nice day, Ralphy.

Answer as my comment.

 
0
 
LVL 1

Expert Comment

by:xer_soft
ID: 1464297
Fare is fare. Have a nice day.
0
 

Author Comment

by:ralphy
ID: 1464298
Thanks for your answer, it works fine. The reason that I mentioned an ini file was that I want the application to work in windows 3.1 as well as 95.(it is a 16 bit application).
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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

15 Experts available now in Live!

Get 1:1 Help Now