VB set up and read. ini file

Source: Internet
Author: User
Tags ini

Although after entering the Win95, the general read-write INI file was replaced by the read and write registry, but we can still read and write the INI file through the Win31 traditional way, to save the current program related settings, and the next time the program is executed to read back. It is currently recommended that GetSetting SaveSetting be used in registry, not in the current way. The setup of the stored program

' Please put 3 textbox in form, a Commandbox
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 Command1_Click ()
Dim success as Long
Success = WritePrivateProfileString ("MyApp", "Text1", Text1.Text, "C:\aa.ini")
' Three one section Name
' Two items in. ini
' The contents of the three three items
' The name of the three four. ini file
Success = WritePrivateProfileString ("MyApp", "Text2", Text2.text, "C:\aa.ini")
Success = WritePrivateProfileString ("MyApp2", "Text3", Text3.text, "C:\aa.ini")
End Sub
Private Sub Form_Load ()
DIM ret as Long
Dim Buff as String
Buff = String (255, 0)
ret = getprivateprofilestring ("Myapp", "Text1", "Text1", Buff, 256, "C:\aa.ini")
' If there is no text1 in the. ini MyApp, the value of three three is used
Text1.Text = Buff
Buff = String (255, 0)
ret = getprivateprofilestring ("Myapp", "Text2", "Text2", Buff, 256, "C:\aa.ini")
Text2.text = Buff
Buff = String (255, 0)
ret = getprivateprofilestring ("Myapp2", "Text3", "Text3", Buff, 256, "C:\aa.ini")
Text3.text = Buff
End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.