在VB6中遍历树视图
我在窗体上有一个treeview控件,看起来像: 我想迭代树视图并将树视图的内容写入ini文件。因此,给定树的ini文件如下所示:在VB6中遍历树视图,vb6,treeview,Vb6,Treeview,我在窗体上有一个treeview控件,看起来像: 我想迭代树视图并将树视图的内容写入ini文件。因此,给定树的ini文件如下所示: [EnvironmentSystem] UpdateRate=50.0 InclinationAngle=20.7 Latitude=34.0 [Reflection] NumReflectionLevel=5 NumSunLightLevel=5 NumWeatherLevel=3 TextureNameFormat=Reflection%01d%01d%02
[EnvironmentSystem]
UpdateRate=50.0
InclinationAngle=20.7
Latitude=34.0
[Reflection]
NumReflectionLevel=5
NumSunLightLevel=5
NumWeatherLevel=3
TextureNameFormat=Reflection%01d%01d%02d.tga
[CloudsClear]
MaxClouds=48
MaxCloudParticles=51
3DCloudMaterial=CloudMaterial
3DCloudHorizontalSize=1400.0
3DCloudVerticalSize=600.0
3DCloudSizeDeviation=0.6
3DCloudParticleDensity=2.4
ParticleSize=300.0
ParticleSizeDeviation=0.3
MinBaseAltitude=400.0
MaxBaseAltitude=2450.0
UseBottomRow=TRUE
以下是我编写的代码:
Private Sub TvSaveToIniBtn_Click()
Dim nodx As Node
Dim i As Long
Dim sectionCount As Integer
sectionCount = TreeView1.Nodes(1).Children
Set nodx = TreeView1.Nodes(1).Child.FirstSibling
For i = 1 To sectionCount
SaveNodesToIni (nodx.Text)
Set nodx = nodx.Next
Next
End Sub
Sub SaveNodesToIni(sName As Variant)
Dim tvn As Node
Set tvn = TreeView1.Nodes(sName)
Dim chil As Integer
Dim a As Integer
Dim ret As Integer
Dim keyValuePair() As String
Dim nElements As Integer
chil = tvn.Children: If chil = 0 Then Exit Sub ' if no children the exit
Set tvn = tvn.Child.FirstSibling
For a = 1 To chil
keyValuePair = Split(tvn.Text, "=")
nElements = UBound(keyValuePair) - LBound(keyValuePair) + 1
If nElements > 0 Then
ret = WritePrivateProfileString(sName, keyValuePair(0), keyValuePair(1), "C:\\MyPrograms\\config.ini")
End If
Set tvn = tvn.Next
Next
端接头
它没有给出正确的输出,它卡在反射的第二部分,无法读取第三部分。代码有问题。您正在将节点文本传递给
SaveNodesToIni
方法,然后将其用作从树中选择适当节点的索引。节点键是否与文本相同?