2

我已经为此苦苦挣扎了一天。我有一个填充了 x 项的列表框。可能是 1 - x

我需要获取列表框中的所有项目并将它们格式化为我提交到 oracle 数据库的字符串。我在 SQL 端使用 INLIST,因此我的字符串中最多只能有 100 个项目。

因此,例如,如果我要在列表框中有 547 个项目,我将遍历所有 547 个项目,但每隔 100 个我将提交到数据库,将我的结果返回到我的集合类,最后完成 47 个。

这是我到目前为止所拥有的。有一些尝试在代码中解决我的问题,所以如果它令人困惑,我会尝试解释。

Public Function SearchBMS()
On Error GoTo HandleError

    Dim rst As ADODB.Recordset
    Dim sESN As String
    Dim i As Integer
    Dim x As Integer
    Dim maxrec As Integer
    Dim itemcnt As Integer
    Dim iBlockCount As Integer

    With frmEngineCampaignSearch.lstbxESNNumbers
        itemcnt = .ListCount - 2
        'iBlockCount = GetBlockCount(itemcnt)
            x = 0
            maxrec = 100
            Debug.Assert itemcnt = 200

            For i = 0 To itemcnt
                For x = i To maxrec
                    MsgBox "test", vbOKOnly
                i = i + 100
                Next x
                    If i = itemcnt Then ' if I = last item than we put the closing parenthesis on our string
                        sESN = sESN & "'" & .list(i) & "'"
                    Else
                        sESN = sESN & "'" & .list(i) & "' , " ' otherwise there are more items so we seperate by comma
                    End If

                    If itemcnt <= 100 Then
                        Set rst = Nothing
                        'Set rst = rstGetCustomerInfo(sESN)
                        'LoadRSTToCollection rst
                    elseif

                    While x = maxrec
                        MsgBox "submit first 100", vbOKOnly
                        'Set rst = Nothing
                        'Set rst = rstGetCustomerInfo(sESN)
                        'LoadRSTToCollection rst
                        sESN = gC_sEMPTY_STRING
                        maxrec = maxrec + 100
                    Wend
                    x = x + 1

            Next i
    End With
HandleError:
If Err.Number > 0 Then
MsgBox Err.Number & ": " & Err.Description

End If

此函数用于获取我必须执行提交的次数,但我遇到了如何在 for 循环中使用它的障碍

Public Function GetBlockCount(ByRef lItemCnt As Long) As Integer
Dim x As Double
If lItemCnt <= 100 Then
    GetBlockCount = 1
    Exit Function
ElseIf lItemCnt > 100 Then
    x = Round(lItemCnt / 100)
    If lItemCnt Mod 100 > 0 Then
        x = x + 1
    Else
    GetBlockCount = x
    Exit Function
    End If
End If
End Function

任何帮助将非常感激。

4

1 回答 1

0

我认为您需要将其清理干净并使其更具可读性。然后看看它,解决方案会更清晰。

这是它应该是什么样子的简单骨架:

I = 100
Txt = Get100Requests(I)
Do While Txt <> ""
  'use txt
  I = I + 100
  Txt = Get100Requests(I)
Loop

Function Get100Requests(FromItem As Integer) As String
  If FromItem => frmEngineCampaignSearch.lstbxESNNumbers.ListCount Then Exit Function
  Dim I As Integer
  I + FromItem
  Do While I < FromItem + 99 And I < frmEngineCampaignSearch.lstbxESNNumbers.ListCount
    Get100Requests = Get100Requests & "'" & frmEngineCampaignSearch.lstbxESNNumbers.list(i) & "', " 
    I = I + 1
  Loop
  Get100Requests = Left(Get100Requests, Len(Get100Requests)-2)
Exit Function
于 2013-08-15T18:42:44.453 回答