I. Implementation Method:
1. Create a project/form (the form name is ini. FRM), and add three command button controls to the form, command1, command2, and command3
Command1.caption = "write"
Command2.caption = "read"
Command3.caption = "end"
2. Code:
Private declare function getprivateprofilestring lib "Kernel32" alias "inline" (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 declare function getprivateprofileint lib "Kernel32" alias "getprivateprofileinta "(_
Byval lpapplicationname as string ,_
Byval lpkeyname as string ,_
Byval ndefault as long ,_
Byval lpfilename as string) as long
Private sub commandementclick ()
Dim A as long
'Write Information
'Modify the value of the keyword in each field in the ABC. ini file
'If this file does not exist, it will be automatically created. If the return value of the function is 0, the modification is unsuccessful.
A = writeprivateprofilestring ("system time", "Operation Date", STR $ (date), app. Path & "/ABC. ini ")
A = writeprivateprofilestring ("system time", "this operation time", STR $ (time), app. Path & "/ABC. ini ")
A = writeprivateprofilestring ("form position and size", "TOP", STR $ (form1.top), app. Path & "/ABC. ini ")
A = writeprivateprofilestring ("form position and size", "height", STR $ (form1.height), app. Path & "/ABC. ini ")
A = writeprivateprofilestring ("form position and size", "width", STR $ (form1.width), app. Path & "/ABC. ini ")
A = writeprivateprofilestring ("form position and size", "Left", STR $ (form1.left), app. Path & "/ABC. ini ")
If a = 0 then msgbox ("An error occurred while writing the file ")
End sub
Private sub command2_click ()
Dim A as long
Dim t as string
Dim X as integer
'Read information
Form1.cls 'form1 clear screen
T = space $ (1000) 'pre-define the string width of the read value
'Read the start value in the tip Field in the ABC. ini file and print it out.
'If the return value of the function is 0, an error occurred while reading the data.
A = getprivateprofilestring ("system time", "current operation time", "", T, 1000, app. Path & "/ABC. ini ")
Print left $ (T, Len (trim $ (t)-1)
If a = 0 then msgbox "the required field cannot be found": Exit sub
X = getprivateprofileint ("form position and size", "height", X, app. Path & "/ABC. ini ")
Print "Height =" & X
X = getprivateprofileint ("form position and size", "width", X, app. Path & "/ABC. ini ")
Print "width =" & X
X = getprivateprofileint ("form position and size", "Left", X, app. Path & "/ABC. ini ")
Print "Left =" & X
X = getprivateprofileint ("form position and size", "TOP", X, app. Path & "/ABC. ini ")
Print "Top =" & X
If a = 0 then msgbox "the required field cannot be found": Exit sub
A = getprivateprofilestring ("system time", "Operation Date", "", T, 1000, app. Path & "/ABC. ini ")
Print left $ (T, Len (trim $ (t)-1)
End sub
Private sub command3_click ()
Call commandementclick
End
End sub
Private sub form_load ()
Dim A as long
Dim t as string
Dim X as integer
'Read information
X = 0
T = space $ (1000) 'pre-define the string width of the read value
'Read the start value in the tip Field in the ABC. ini file and print it out.
'If the return value of the function is 0, an error occurred while reading the data.
X = getprivateprofileint ("form position and size", "height", X, app. Path & "/ABC. ini ")
Form1.height = x
X = getprivateprofileint ("form position and size", "width", X, app. Path & "/ABC. ini ")
Form1.width = x
X = getprivateprofileint ("form position and size", "Left", X, app. Path & "/ABC. ini ")
Form1.left = x
X = getprivateprofileint ("form position and size", "TOP", X, app. Path & "/ABC. ini ")
Form1.top = x
End sub
Private sub form_queryunload (cancel as integer, unloadmode as integer)
Select case unloadmode
Case 0:
Call commandementclick
Case 1:
Call commandementclick
Case 2:
Call commandementclick
End select
End sub
Ii. Description:
Note that the specified data type is the same as the function parameter type.