Home > Software engineering > The key value in VB6.0 by use of how to remove the ini file and fields?
The key value in VB6.0 by use of how to remove the ini file and fields?
Time:11-20
Known to have ini file ABC. Ini The file content is: [section1] Key1=value1 Key2=value2 (section2) Key1=value1 Key2=value2 A delete code, run after achieve the following results: [section1] Key2=value2 (section2) Key1=value1 Key2=value2
, every brother please don't simply write a 0 & amp; Or "", I want to delete key1=value1, not just delete value1 And I try to write a null, an error 94, invalid use null,
His part of the code is as follows, yellow is an error:
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal Filename As String) As an Integer
Public Sub writeini (Filename $, SectionName $, KeyName $, Str $) HandleIo=WritePrivateProfileString (SectionName $, KeyName $, Str $, Filename $) End Sub
Private Sub Form_Unload (cancel As Integer) Dim StrPath $ Dim As Integer I Dim num As Integer StrPath=App. Path & amp; "\ configDB ini" Num=Val (ReadIni (StrPath, "Number", "diagnose_num")) If the current item. ListCount & lt; Num Then For I=0 To the current item. ListCount - 1 Call writeini (StrPath, "diagnose", "diagnose" & amp; I, the current item. The List (I)) Next I For I=the current item. ListCount To num 1 If the current item. The List (I)="" Then Call writeini (StrPath, "diagnose", "diagnose" & amp; I, Null) The Else The Exit For End the If Next I The Else For I=0 To the current item. ListCount - 1 Call writeini (StrPath, "diagnose", "diagnose" & amp; I, the current item. The List (I)) Next I End the If Cancel=0 End Sub
O great god reply!!!!!!
CodePudding user response:
There are a lot of mature ini, speaking, reading and writing module, search everywhere is You can refer to the following https://blog.csdn.net/zgqtxwd/article/details/2355572
CodePudding user response:
Very simple ah, Such as this will delete [section1] Key1, under the section with your "expectations",
Private Sub Command1_Click () Dim StrPath $
StrPath=App. Path & amp; "\ configDB ini" Call WritePrivateProfileString (" section1 ", "key1", ByVal 0, StrPath) End Sub
Note: StrPath value, must want to operate ini file path consistent with you, If "unsuccessful", debugging and running, you'd better set breakpoints confirm, or "write dead path" experiment first, Enrolled into exe code, use the app. The path relative paths,