A absolute classic operation in VB. INI document

zhaozj2021-02-08  263

A absolute classic operation in VB. INI document

(There is a need for the source program, please leave an email address in the message)

Program interface:

Source program:

ClassiniFile.Cls content:

Option expedition

'--------------------------' This defines a ClassiniFile class' a absolute classic in VB operation. Ini files Source Code 'Program: China Qingdao · Xujiao' 2002.6.16'e-mail: Goj2000@163.com'HomePage: http://www.gojclub.com '

'Private mer That Holds a reason to'the path of ing company

Private Strini As String

'Windows API DeclaresPrivate 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 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 function makepath (byval strdrv as string) AS String

'Makes An Ini File: Guarantees A Sub Dir Do WHILE RIGHT $ (strDRV, 1) = "/" StrDRV = Left $ (strDrv, len (strDRV) - 1) loop do while left $ (strdir, 1) = "/ "StrDir = MID $ (strdir, 2) loop 'return the path makepath = strDRV &" / "& strdirend function

Private sub createini (strDrv as string, strdir as string) 'make a new ini file strini = makepath (strDrv, strdir) end sub

Public Sub WriteIniKey (strSection As String, strKey As String, strValue As String) 'Write to strINI WritePrivateProfileString strSection, strKey, strValue, strINIEnd SubPublic Function GetIniKey (strSection As String, strKey As String) As String Dim strTmp As String Dim lngRet As String Dim I As Integer Dim strTmp2 As String strTmp = String $ (1024, Chr (32)) lngRet = GetPrivateProfileString (strSection, strKey, "", strTmp, Len (strTmp), strINI) strTmp = Trim (strTmp) strTmp2 = "" For i = 1 to Len (stratmp) IF ASC (MID (Strtmp, I, 1)) <> 0 Then Strtmp2 = StrtMP2 MID (Strtmp, I, 1) end if next i startmp = start mp2 getinikey = startMPEND FUNCTION

Public property let inifilename (Byval new_inipath as string "sets the new iNi path strini = new_inipathend protety

Public property get inifilename () AS string 'returns the current ini path inifilename = Striniend Property. INIFLENAME = STRINIEND PROPERTY

'********************************* Clear keyword "key" (SUB) ** **************************************************************** PUBLIC FUNCTION DeliniKey SectionName As String, Byval Keyword As String) DIM RETVAL AS INTEGER RETVAL = WritePrivateProfileString (SectionName, Keyword, 0 & Strini) End Function

'If you are cleared, you will write a key to one "". "" '************************************ Clear Section "Segment" (SUB) *** ****************************************************** Public Function Delinisec (BYVAL Sectionname AS String) 'Clear Section Dim Retval AS Integer Retval = WritePrivateProfileString (SectionName, 0 &, "", STRINI) End Function

The content in Form1:

Option expedition

'An absolute classic operation in VB.INI file General Class Sample Sample Program' Program: China Qingdao · Xujiao '2002.6.16'e-mail: Goj2000@163.com'HomePage: http: // www. GojClub.com 'Defines a .ini type variable Dim demoini as new classinifile

Private Sub Form_Load () 'Putting the Control Text1.Text = "Test the" List1.clear' Definition .INI file name, and write some initial data demoini.iniFileName = app.path & "/demoini.ini" demoini. WriteiniKey "System", "Startup Path", app.path demoini.writeinikey "system", "executable program file name", app.exename 'display Save to .ini files in data CALL CMDREAD_CLICKEND SUB

'Exit Private Sub Cmdexit_Click () unload mend Sub

'Read the data already existing in the .ini file and display Private Sub Cmdread_Click () DIM Teststr AS String List1.clear teststr = demoini.getinikey (System "," Startup Path ") List1.addItem system system - Startup path: & Teststr Teststr = Demoini.GetiniKey ("System", "User File Name") List1.AddItem system - Execute program file name: "& teststr Teststr = Demoini.GetiniKey (" User Custom ", User Data ") List1.addItem" User Custom - User Data: "& TestStrend Sub

'Save User Custom Data to .ini file Private Sub Cmdsave_click () demoini.writeinikey "User Custom", "User Data", Text1.Text' Shows Data Save to .ini file CALL CMDREAD_CLICKEND SUB

'Clear user custom segment and segment data private subddelete_click () demoini.delinikey "User Custom", "User Data" Demoini.DeliniseC "User Custom"' Display Save Data in .ini file Call Cmdread_Clickend Sub

转载请注明原文地址:https://www.9cbs.com/read-2308.html

New Post(0)