Example of using VB to read and write INI files

Source: Internet
Author: User
Public declare function writeprivateprofilestring lib "Kernel32" alias "writeprivateprofilestringa" (byval lpapplicationname as string, byval lpkeyname as any, byval lpstring as any, byval lpfilename as string) as longpublic declare function getprivateprofilestring lib "Kernel32" alias "Expiration" (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 longprivate const mc_strinifilename as string = "myini. ini "Public sub writeini (appname as string, keyname as string, valuenew as string) 'dim X as long dim strinifile as string if right (App. path, 1) = "\" then strinifile = app. path & mc_strinifilename else strinifile = app. path & "\" & mc_strinifilename end if x = writeprivateprofilestring (appname, keyname, valuenew, strinifile) debug. print xend subpublic function getini (appname as string, keyname as string) as string 'dim strdefault as string dim lngbufflen as long dim strresu as string dim X as long dim strinifile as string if right (App. path, 1) = "\" then strinifile = app. path & mc_strinifilename else strinifile = app. path & "\" & mc_strinifilename end if strresu = string (1025, vbnullchar): lngbufflen = 1025 strdefault = "" X = getprivateprofilestring (appname, keyname, strdefault, strresu, lbufflen, Len, strinifile) debug. print x debug. print strresu getini = left (strresu, x) end Function

Version 5.00 begin VB. form form1 caption = "form1" clientheight = 2085 clientleft = 60 clienttop = 345 clientwidth = 4680 linktopic = "form1" scaleheight = 2085 scalewidth = 4680 startupposition = 3' window default begin VB. textbox text3 Height = 495 left = 1560 tabindex = 4 Top = 1440 width = 1215 end begin VB. textbox text2 Height = 495 left = 1560 tabindex = 3 Top = 720 width = 1215 end begin VB. textbox text1 Height = 495 left = 1560 tabindex = 2 Top = 0 width = 1215 end begin VB. commandbutton command2 caption = "read key value" Height = 495 left = 3240 tabindex = 1 Top = 1440 width = 1215 end begin VB. commandbutton command1 caption = "write key value" Height = 495 left = 3240 tabindex = 0 Top = 720 width = 1215 end begin VB. label label3 caption = "value" Height = 495 left = 120 tabindex = 7 Top = 1440 width = 1215 end begin VB. label label2 caption = "key name" Height = 495 left = 120 tabindex = 6 Top = 720 width = 1215 end begin VB. label label1 caption = "segment name" Height = 495 left = 120 tabindex = 5 Top = 0 width = 1215 endendattribute vb_name = "form1" attribute vb_globalnamespace = falseattribute vb_creatable = falseattribute plaintext = trueattribute vb_exposed = falseprivate sub commandementclick () 'writeini text1.text, text2.text, text3.text end subprivate sub command2_click () 'text3.text = getini (text1.text, text2.text) 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.