我在下面创建了一个类型行,并在其中创建了一维数组:
Public Type file_sizes
fName As String
fsize As Integer
End Type
Global file_array(1000) As file_sizes
我有一个包含一些合同号和文件名的excel。
我想构建另一个具有如下结构的数组:
Public Type ctr_file_sizes
ctr_id As String
fName As String
fsize As Integer
End Type
我的任务是查看数组file_array
,找出字段fsize
中给定文件名的值是什么。
发布于 2021-04-05 22:03:20
我不确定我为什么会看到ctr_file_sizes
的存在。似乎你想要的信息都是file_sizes
类型的。
我建议你用字典
Option Explicit
Dim files As New Dictionary
Sub populateFiles()
Dim i
For i = 1 To 1000 'iterate over your files however you please
files.Add "file name", 3456
Next
'then to get a specific file's size
Dim sizeYouWant As Long
sizeYouWant = files("file name")
End Sub
您需要引用Microsoft Scripting Runtime
发布于 2021-04-05 22:02:16
你想做这样的事情吗?
Option Explicit
Public Type file_sizes
fName As String
fsize As Integer
End Type
Public Type ctr_file_sizes
ctr_id As String
fName As String
fsize As Integer
End Type
Global file_array(1000) As file_sizes
Sub Testit()
Dim i As Long
Dim arrCtr() As ctr_file_sizes
' some Testdata
file_array(0).fName = "Given file Name"
file_array(0).fsize = 1024
file_array(1).fName = "Other file Name"
file_array(1).fsize = 1048
Dim fileName As String
fileName = "Given file Name"
Dim hit As Long
For i = LBound(file_array) To UBound(file_array)
If file_array(i).fName = fileName Then
ReDim Preserve arrCtr(hit)
arrCtr(hit).fName = file_array(i).fName
arrCtr(hit).fsize = file_array(i).fsize
arrCtr(hit).ctr_id = i ' or whatever ctr_id is good for
hit = hit + 1
End If
Next i
End Sub
https://stackoverflow.com/questions/66954029
复制相似问题