Solved

ini file

Posted on 1998-06-25
12
372 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
[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
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

751 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