下面的命令可以实现添加文件,并记录文件名到text2内,
但我还想能够随时删除text2的内容,随时添加
可是我点了cls按钮后,却不能再添加了?
谁能帮忙给改改,或者有更好的代码和建议?
Private Sub CmdAdd_Click()
With CommonDialog1
.InitDir = App.Path & "\data\0606"
.DialogTitle = "打开"
.CancelError = False
'ToDo: 设置 common dialog 控件的标志和属性
.Filter = "所有文件 (*.*)|*.*"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
End With
Dim i As Long, n As Long
n = Text2.UBound
If n > 4 Then End '最多添加6个附件
For i = 0 To n
If Len(Text2(i).Text) = 0 Then
Exit For
End If
Next '检查有没有空白文件
If i > n Then
Load Text2(i)
Text2(i).Visible = True
Text2(i).Move Text2(i - 1).Left, Text2(i - 1).Top + Text2(i - 1).Height + 90
Load Cmdcls(i)
Cmdcls(i).Visible = True
Cmdcls(i).Move Cmdcls(i - 1).Left, Cmdcls(i - 1).Top + Cmdcls(i - 1).Height + 50
End If
FileNumber = i
End SubPrivate Sub Cmdcls_Click(Index As Integer)
Text2(Index).Text = ""
End Sub
但我还想能够随时删除text2的内容,随时添加
可是我点了cls按钮后,却不能再添加了?
谁能帮忙给改改,或者有更好的代码和建议?
Private Sub CmdAdd_Click()
With CommonDialog1
.InitDir = App.Path & "\data\0606"
.DialogTitle = "打开"
.CancelError = False
'ToDo: 设置 common dialog 控件的标志和属性
.Filter = "所有文件 (*.*)|*.*"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
End With
Dim i As Long, n As Long
n = Text2.UBound
If n > 4 Then End '最多添加6个附件
For i = 0 To n
If Len(Text2(i).Text) = 0 Then
Exit For
End If
Next '检查有没有空白文件
If i > n Then
Load Text2(i)
Text2(i).Visible = True
Text2(i).Move Text2(i - 1).Left, Text2(i - 1).Top + Text2(i - 1).Height + 90
Load Cmdcls(i)
Cmdcls(i).Visible = True
Cmdcls(i).Move Cmdcls(i - 1).Left, Cmdcls(i - 1).Top + Cmdcls(i - 1).Height + 50
End If
FileNumber = i
End SubPrivate Sub Cmdcls_Click(Index As Integer)
Text2(Index).Text = ""
End Sub
Private Sub CmdAdd_Click()
With CommonDialog1
.InitDir = App.Path & "\data\0606"
.DialogTitle = "打开"
.CancelError = False
'ToDo: 设置 common dialog 控件的标志和属性
.Filter = "所有文件 (*.*) |*.*"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
End With
Dim i As Long, n As Long
n = Text2.UBound
If n = 5 Then MsgBox "注意,最多添加6个文件"
If n > 5 Then Exit Sub '最多添加6个附件 Load Text2(Text2.Count)
Load cmdCls(cmdCls.Count)
Text2(Text2.Count - 1).Text = CommonDialog1.filename
Text2(Text2.Count - 1).Top = Text2(Text2.Count - 2).Top + Text2(0).Height
Text2(Text2.Count - 1).Left = Text2(0).Left
Text2(Text2.Count - 1).Visible = True
cmdCls(cmdCls.Count - 1).Top = cmdCls(cmdCls.Count - 2).Top + cmdCls(0).Height
cmdCls(cmdCls.Count - 1).Left = cmdCls(0).Left
cmdCls(cmdCls.Count - 1).Visible = True
End SubPrivate Sub Cmdcls_Click(Index As Integer)
Text2(Index).Text = ""
For i = Index To Text2.Count - 2
Text2(i).Text = Text2(i + 1).Text
Next
Unload Text2(Text2.Count - 1)
Unload cmdCls(cmdCls.Count - 1)
End Sub
Private Sub CmdAdd_Click()
With CommonDialog1
.InitDir = App.Path & "\data\0606"
.DialogTitle = "打开"
.CancelError = False
'ToDo: 设置 common dialog 控件的标志和属性
.Filter = "所有文件 (*.*) ¦*.*"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
End With
Dim i As Long, n As Long
n = Text2.UBound
If n > 4 Then End '最多添加6个附件
For i = 0 To n
If Len(Text2(i).Text) = 0 Then
Text2(i) = CommonDialog1.FileName
GoTo lbl1
Else
End If
Next '检查有没有空白文件
If i > n Then
Load Text2(i)
Text2(i).Visible = True
Text2(i).Move Text2(i - 1).Left, Text2(i - 1).Top + Text2(i - 1).Height + 90
If i = Cmdcls.UBound + 1 Then
Load Cmdcls(i)
Cmdcls(i).Visible = True
Cmdcls(i).Move Cmdcls(i - 1).Left, Cmdcls(i - 1).Top + Cmdcls(i - 1).Height + 50
End If
End If
lbl1: FileNumber = i
If n = 4 Then MsgBox "注意,最多添加6个文件"
End Sub Private Sub Cmdcls_Click(Index As Integer)
Select Case Index
Case 0
Text2(0).Text = ""
Case 1
Text2(1).Text = ""
Case 2
Text2(2).Text = ""
Case 3
Text2(3).Text = ""
Case 4
Text2(4).Text = ""
Case 5
Text2(5).Text = ""
End Select End Sub