首页 > 解决方案 > 尝试从用户表单中的文本框中删除文本(文本 = Label.Caption),但一次只能输入一个,因为可以输入多个

问题描述

Private Sub Option_Remove_device_Click()

 If Uf_Device_selection.Option_Add_device.Value = True Then
      Sheets("Sheet1").range("B2") = "Add"
     Else
      Sheets("Sheet1").range("B2") = "Remove"
    End If

End Sub

…</p>

    Private Sub Label_01_Click()
    If Uf_Device_selection.Option_Add_device.Value = True Then
        Text_Device_list = Label_01.Caption + " , " + Text_Device_list.Value
    Else
       Text_Device_list.Text = LCase(Trim(Label_01.Caption)) ''''this is the section i am stuck on '''
    End If

End Sub

…</p>

Private Sub Label_02_Click()
    If Uf_Device_selection.Option_Add_device.Value = True Then

    Text_Device_list = Label_02.Caption + " , " + Text_Device_list.Value
Else
     Text_Device_list.Text = LCase(Trim(Label_02.Caption))''''this is the section i am stuck on '''
End If

End Sub

使用修剪时,它会删除除标签之外的所有内容。我点击的标题,我只需要它以相反的方式工作。例如

文本框显示:
Label_02.Caption , Label_02.Caption , Label_02.Caption, Label_01.Caption, Label_02.Caption
现在我想通过单击 Label_02 从文本框中删除一个 Label_02.Caption

非常感谢您的任何帮助

标签: vbatext

解决方案


Private Sub La02_Click()
If Uf_Device_selection.Option_Add_device.Value = True Then

    Text_Device_list = La02.Caption + " , " + Text_Device_list.Value
Else
    Text_Device_list = Replace(Text_Device_list.Value, La02.Caption + " , ", "", 1, 1)
End If

结束子

所以我只需要使用一个替换函数,它为我整理了这段代码。Now when the remove option is selected then you can remove one (La.Caption) at a time.


推荐阅读