Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

ini file

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
ralphy
Asked:
ralphy
  • 7
  • 2
  • 2
  • +1
1 Solution
 
yowkeeCommented:
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
 
yowkeeCommented:
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
 
yowkeeCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
yowkeeCommented:
Sorry, I don't know what happen... It just appear three posting.
Sorry if I accidentally cause this and make your unconvinient.
0
 
xer_softCommented:
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
 
yowkeeCommented:
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
 
yowkeeCommented:
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
 
DalinCommented:
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
 
ralphyAuthor Commented:
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
 
yowkeeCommented:
Have a nice day, Ralphy.

Answer as my comment.

 
0
 
xer_softCommented:
Fare is fare. Have a nice day.
0
 
ralphyAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now