以前做測試用的代碼﹐寫的很亂﹐懶得改了。別問我﹐我什么都8知道。
Dim aa
Dim al
Dim u As Integer
Dim father
If Text1.Text = "" Then
u = MsgBox("請輸入序列號﹗", vbExclamation, "輸入錯誤﹗")
Text2.Text = ""
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
u = MsgBox("請輸入名稱﹗", vbExclamation, "輸入錯誤﹗")
Text2.SetFocus
Exit Sub
End If
aa = use
If aa = 0 Then
Exit Sub
End If
If TreeView1.Nodes.Count > 0 Then
For i = TreeView1.Nodes.Count To 1 Step -1
If TreeView1.Nodes(i).Key = Text1.Text & "j" Then
u = MsgBox("已有此代號﹐請重新輸入!", vbExclamation, "輸入錯誤﹗")
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Exit Sub
End If
Next
End If
father = Getkey()
If Int(Val(Text1.Text)) = Val(Text1.Text) Then
Set nodx = TreeView1.Nodes.Add(, , father & "j", Text2.Text, 1)
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Else
If TreeView1.Nodes.Count = 0 Then
u = MsgBox("沒有父節點﹗", vbInformation, "查找出錯﹗")
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Else
al = 0
For i = 1 To TreeView1.Nodes.Count
If father & "j" = TreeView1.Nodes(i).Key Then
Set nodx = TreeView1.Nodes.Add(father & "j", tvwChild, Text1.Text & "j", Text2.Text, 3)
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
al = 1
Exit For
End If
Next i
If al = 0 Then
u = MsgBox("沒有父節點﹗", vbInformation, "查找出錯﹗")
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End If
End If
End If
Public Function Getkey()
Dim d
Dim e As String
d = InStrRev(Form1.Text1.Text, ".", , 0)
If d = 0 Then
e = Left(Form1.Text1.Text, Len(Form1.Text1.Text))
Else
e = Left(Form1.Text1.Text, d - 1)
End If
Getkey = e
End Function