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,

CodePudding user response:

refer to the second floor Chen8013 response:
super 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,


No, an error, type do not match,

CodePudding user response:

reference 1st floor chewinggum response:
there are a lot of mature ini, speaking, reading and writing module, search the land is
You can refer to the following
https://blog.csdn.net/zgqtxwd/article/details/2355572


The method in the article I tried to write "" is not the original field without any change, write 0 & amp; If all the key value is 0, the effect of the short of deleting key1

CodePudding user response:

reference qq_36117428 reply: 3/f
Quote: refer to the second floor Chen8013 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,


No, an error, type mismatch,

API function: WritePrivateProfileString, the second parameter, type should be declared as String, not Any,

CodePudding user response:

Tomorrow I try, statement as "Any", string, complains?

CodePudding user response:

Key value item is empty when you write clear="" is not Null

CodePudding user response:

'read and write configuration files used API
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 Long
Public 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

The Public Function INIRead (iAppName As String, iKeyName As String, iFileName As String) As String
On the Error Resume Next
Dim iStr $
IStr=String (255, CRH (0))
INIRead=Left (iStr, GetPrivateProfileString (iAppName, ByVal iKeyName, "", iStr, Len (iStr), iFileName))
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • API
  • Related