我可以根据其他variablesdynamic创buildvariables吗?

我正在使用VBA模块来处理报价项目列表。 我目前的错误是试图从报价清单中堆放全部或部分的东西,我想弄清楚如何跟踪它们。

项目列表没有一致的项目数量; 一个可能是一个单一的项目,另一个可能是一百个。

该系统将货物分为四大类(pipe,板,横梁和其他),以便select使用哪种计算器逻辑。

有没有办法创buildvariables来跟踪个别订单项? 例如,部署一个伪代码点:

Public Qty & "_" & Class & "-" & ClassCount As Integer 

有什么办法可以做出类似的工作,还是有更好的方法来做到这一点?

我在课上有点粗略,我应该开始更多地看他们,因为他们非常强大 – 这个链接会给你更多的信息: http : //www.cpearson.com/excel/classes.aspx

在Jasons的基础上扩大评论这是build立这个class级的一种方式,我相信有一个更好的方法来做到这一点:
添加一个类模块到你的项目中,并命名模块cls_Quote
将此代码添加到类模块中:

 Option Explicit Private sQuote As String Private lQuantity As Long Private lAnotherValue As Long Public Property Let Quote(Value As String) sQuote = Value End Property Public Property Get Quote() As String Quote = sQuote End Property Public Property Let Quantity(Value As Long) lQuantity = Value End Property Public Property Get Quantity() As Long Quantity = lQuantity End Property Public Property Let AnotherValue(Value As Long) lAnotherValue = Value End Property 

在一个正常的模块添加这个代码:

 Option Explicit Private MyQuotes As Collection Public Sub Test() Dim MyNewQuote As cls_Quote Dim x As Long Dim vIQuote As Variant Dim FinalSum As Long Set MyQuotes = New Collection For x = 1 To 10 Set MyNewQuote = New cls_Quote With MyNewQuote .Quantity = x .Quote = "Pipes" .AnotherValue = x * 5 End With MyQuotes.Add MyNewQuote Next x For Each vIQuote In MyQuotes If vIQuote.Quote = "Pipes" Then FinalSum = FinalSum + vIQuote.Quantity End If Next vIQuote MsgBox "Total sum of Pipes is: " & FinalSum End Sub 

注意:在For x循环中,我每次创build一个新类的实例。

现在只需要等待有更多课程编程经验的人员展示一个更好的方法就可以了。 🙂