从文本框/列表框创建数组 [英] Creating an array from textbox/listbox

查看:24
本文介绍了从文本框/列表框创建数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将自己归类为编程初学者.我有一个用户表单,它首先查找用户提供的数字.示例 12345、12346、12347.搜索输入到文本框中的数字,然后将其作为有效数字添加到列表框中.用户输入所有需要的数字后,他们应该能够点击更改并相应地更新记录.

I classify myself as a beginner in programing. I have a userform that first looks up a number presented by the user. Example 12345, 12346,12347. The number entered into the textbox is searched for and then added to the listbox as a valid number. After the user enters all the numbers needed, they should be able to click change and update the records accordingly.

Private Sub Change_Click()
Dim i As Long

For i = LBound(RunArray) To UBound(RunArray)
    ' Code to update each record, still working on it.
Next

End Sub

Private Sub RunNumber_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,     ByVal Shift As Integer)
Dim RunArray() As String
Dim RunCount As Integer
RunCount = 0

If KeyCode = 13 Then
    With Sheets("Sheet1").Range("A:A")
        Set RunFind = .Find(What:=RunNumber, _
                     After:=.Cells(.Cells.count), _
                     LookIn:=xlValues, _
                     LookAt:=xlWhole, _
                     SearchOrder:=xlByRows, _
                     SearchDirection:=xlNext, _
                     MatchCase:=False)
        If Not RunFind Is Nothing Then
            ReDim Preserve RunArray(RunCount)
            RunArray(RunCount) = RunNumber.Value
            RunNumberList.AddItem RunNumber.Value
            RunNumber.Value = ""
            RunCount = RunCount + 1
        Else
            MsgBox "The Run Number you entered was not found, Please the number and try again."
            RunNumber.Value = ""
        End If
    End With
End If

End Sub

推荐答案

Private Sub CreateArrayFromListbox()
  Dim nIndex As Integer
  Dim vArray() As Variant

  ' dimension the array first instead of using 'preserve' in the loop
  ReDim vArray(ListBox1.ListCount - 1)
  
  For nIndex = 0 To ListBox1.ListCount - 1
    vArray(nIndex) = ListBox1.List(nIndex)
  Next
End Sub

这篇关于从文本框/列表框创建数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆