我是一个在程序中调用的类来进行一些计算。现在有必要多次调用此类,因为我需要对所有数据库表行成员进行此计算。我有For... Next
,但它的工作不正确,每次只返回最后一次调用计算金额到数据库,代码部分是这样的:
For j As Integer = 0 To symbols.Rows.Count - 1
Dim spread As Double
Dim digits As Integer = symbols.Rows(j)("Digits")
Dim symbolgroupconditionrow = symbolsgroupcondition.Select("ID = '" & symbols.Rows(j)("SymbolGroupID") & "'")
Select Case digits
Case 0
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 1)
Case 1
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.1)
Case 2
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.01)
Case 3
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.001)
Case 4
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.0001)
Case 5
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.00001)
End Select
Dim qclient As New Quotereader
qclient.GetWord("iqlink", symbols.Rows(j)("Symbol"), "last", spread)
Next j
对象Quotereader
在我之前导入的类文件中,现在我的问题是,有没有办法以几个名称“Dim new”一个对象为例:
Dim qclient(10) As New Quotereader
For I = 0 to 9
qclient(I).GetWord("iqlink", symbols.Rows(j)("Symbol"), "last", spread)
Next I
或其他任何方式?
答案 0 :(得分:1)
我想如果我正确理解了这个问题,你如何将10个新对象初始化为该数组?如果是这种情况,您可以使用linq。
Dim qclient = Enumerable.Range(0,10).ToList().Select(fuhction(i) New QuoteReader()).ToArray()
这样做是创建一个从0到10的11个整数的列表,为列表中的每个数字创建一个QuoteReader实例,然后返回一个QuoteReaders数组。我不确定这是不是你想要的,但我希望它有所帮助。
答案 1 :(得分:1)
我已经更改了下面的代码,一切正常。
Dim j As Integer = 0
Dim qclient = Enumerable.Range(0, 9).Select((Function(i) New Quotereader))
For Each cl As Quotereader In qclient
Dim spread As Double
Dim digits As Integer = symbols.Rows(j)("Digits")
Dim symbolgroupconditionrow = symbolsgroupcondition.Select("ID = '" & symbols.Rows(j)("SymbolGroupID") & "'")
Select Case digits
Case 0
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 1)
Case 1
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.1)
Case 2
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.01)
Case 3
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.001)
Case 4
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.0001)
Case 5
spread = ((symbols.Rows(j)("Spread") + symbolgroupconditionrow(0)("SpreadTopup")) * 0.00001)
End Select
cl.GetWord("iqlink", symbols.Rows(j)("Symbol") + ".FXCM", "last", spread)
j = j + 1
Next
感谢jcwrequests的善意建议。