The first thing to do is to declare the Windows 32-bit functions:
Step one) Create a new module in the project. This is done by clicking on insert and then module.
Step two) Under decleration in the new module you must write the following two lines:
Declare Function writeprivateprofilestring Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As Any, ByVal lpString As String, ByVal lpfilename As String) As Long
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
The next step is two create 2 command buttons and 2 textboxes on your form. Name one button OKand the other CANCEL also put the same in their respective caption area's
Now, go to the Private Sub Form_Load() procedure and type in the following:
Dim sSpaces as String ' This will hold the input that the program will retrieve
Dim sSpaces2 as String
Dim szReturn as String ' This will be the defaul value if the string is not found
sSpaces = space(75) ' This tells the computer how long the longest string can be. If you want, you can change the number 75 to any number you wish
sSpaces2 = space(75)
getprivateprofilestring "YourString.Something", "Message1", szreturn, sSpaces, Len(sSpaces), "CONTROL.INI"
getprivateprofilestring "YourString.Something", "Message2", szreturn, sSpaces2, Len(sSpaces2), "CONTROL.INI"
Text1.Text = sSpaces ' The text box will now display whatever was last entered
Text2.Text = sSpaces2
End Sub
Now, before we move on let me explain what the GetPrivateProfileString does exactly. The part that say "YourString.Something" is the header that goes above the imput in the ini file. In a screen saver the file may be "Screen Saver.Stuff". The part that says "Message1" is the field that the input is stored. In this case the field may hold a message, thus we gave it the name of Message1 or Message2. szReturn was nothing but some default value. sSpaces is the value that the field message contains. Len(sSpaces) tells the computer the length of the value. "CONTROL.INI" tells the computer what file the information is stored in.
The CONTROL.INI file may now have something like this in it
[YourString.Something]
Message1=
Message2=
All we have written so far is the From_Load event. Primarily the code that was written tells the program to search for two strings in the CONTROL.INI file and display them on two different textboxes. The next procedure will allow us to copy information to the CONTROL.INI when the user presses the ok button when they are finished
Before we procede to the OK button lets first add code to the CANCEL button so that the user can end the program if the want without making any changes.
Private Sub Cancel_Click()
end 'End the program
End Sub
Now here is the code for when the user presses the OK button
Private Sub OK_Click()
Dim i1 as long
Dim i2 as long
Dim sValue1 as String
Dim sValue2 as String
sValue1=text1.text 'sValue1 gets whatever is in textbox 1
sValue2=text2.text 'sValue2 gets whatever is in textbox 2
i = writeprivateprofilestring("YourString.Something", "Message", svalue, "CONTROL.INI") 'Similar to the Form_Load procedure except we are putting new information in
i2 = writeprivateprofilestring("YourString.Something", "Message2", svalue2, "CONTROL.INI")
end 'This ends the program
End Sub
Now, that wasn't too bad, a bit of coding but hey if you understood all of this then your on your way. The reason I made two sValue's and two sSpaces's was to show you that the program can read-in or write-out more than one value at a time. Well, now hopefully you understand. If you have any question or still need help or want the original full source code to this program, you can contact me personally at: mheller@computer.net
