如何根据变量创建增量数字
How to create an incremental number based on a variable
我有一个经典的 ASP Web 表单将用于订购。因为我不知道要订购哪些商品,所以我使用语句仅在订购数量 > 0 时将每个商品的代码生成到 XML 文件。我 运行 遇到的问题是要将其发送给的供应商希望将行号添加到每个项目。
我试过使用 For i=1 To VariableName
,然后在可能订购的项目列表的末尾使用 Next
。使用的变量名称是一个计算订购商品总数的字段。我还尝试了 for while 循环,指向 Here is a sample of the code for items ordered:
If strQty1 <> "" then
If strQty1 > 0 then
strXML = strXML & " <ItemOut quantity=" & chr(34) & strQty1 & chr(34) & " lineNumber=" & chr(34) & i & chr(34) & ">" & strCR
strXML = strXML & " <ItemID>" & strCR
strXML = strXML & " <SupplierPartID>S1K0R205B</SupplierPartID>" & strCR
strXML = strXML & " </ItemID>" & strCR
strXML = strXML & " <ItemDetail>" & strCR
strXML = strXML & " <UnitPrice>" & strCR
strXML = strXML & " <Money currency=" & chr(34) & "USD" & chr(34) & ">9.78</Money>" & strCR
strXML = strXML & " </UnitPrice>" & strCR
strXML = strXML & " <Description/>" & strCR
strXML = strXML & " <UnitOfMeasure>EA</UnitOfMeasure>" & strCR
strXML = strXML & " </ItemDetail>" & strCR
strXML = strXML & " </ItemOut>" & strCR
End If
End If
If strQty2 <> "" then
If strQty2 > 0 then
strXML = strXML & " <ItemOut quantity=" & chr(34) & strQty2 & chr(34) & " lineNumber=" & chr(34) & i & chr(34) & ">" & strCR
strXML = strXML & " <ItemID>" & strCR
strXML = strXML & " <SupplierPartID>A4216070B16</SupplierPartID>" & strCR
strXML = strXML & " </ItemID>" & strCR
strXML = strXML & " <ItemDetail>" & strCR
strXML = strXML & " <UnitPrice>" & strCR
strXML = strXML & " <Money currency=" & chr(34) & "USD" & chr(34) & ">3.96</Money>" & strCR
strXML = strXML & " </UnitPrice>" & strCR
strXML = strXML & " <Description/>" & strCR
strXML = strXML & " <UnitOfMeasure>BX</UnitOfMeasure>" & strCR
strXML = strXML & " </ItemDetail>" & strCR
strXML = strXML & " </ItemOut>" & strCR
End If
End If
如您所见,我有一个需要填充的 LineNumber 属性。 Do While 循环似乎不喜欢以变量结尾。它无限期地挂起表格,似乎陷入了永久循环。我发现的所有示例都是用于连续生成增量数字,而不是在我尝试执行的过程附近的任何地方。
从零开始 i,在每个 strQty# > 0 之后,将 i 递增 1 ( i = i +1 )。没有循环或类似的东西
例如
i = 0 ' Initiate the variable
If strQty1 <> "" then
If strQty1 > 0 then
i = i + 1 ' Increment it
strXML = strXML & " <ItemOut quantity=" & chr(34) & strQty1 & chr(34) & " lineNumber=" & chr(34) & i & chr(34) & ">" & strCR
strXML = strXML & " <ItemID>" & strCR
strXML = strXML & " <SupplierPartID>S1K0R205B</SupplierPartID>" & strCR
strXML = strXML & " </ItemID>" & strCR
strXML = strXML & " <ItemDetail>" & strCR
strXML = strXML & " <UnitPrice>" & strCR
strXML = strXML & " <Money currency=" & chr(34) & "USD" & chr(34) & ">9.78</Money>" & strCR
strXML = strXML & " </UnitPrice>" & strCR
strXML = strXML & " <Description/>" & strCR
strXML = strXML & " <UnitOfMeasure>EA</UnitOfMeasure>" & strCR
strXML = strXML & " </ItemDetail>" & strCR
strXML = strXML & " </ItemOut>" & strCR
End If
End If
If strQty2 <> "" then
If strQty2 > 0 then
i = i + 1 ' Increment it
strXML = strXML & " <ItemOut quantity=" & chr(34) & strQty2 & chr(34) & " lineNumber=" & chr(34) & i & chr(34) & ">" & strCR
strXML = strXML & " <ItemID>" & strCR
strXML = strXML & " <SupplierPartID>A4216070B16</SupplierPartID>" & strCR
strXML = strXML & " </ItemID>" & strCR
strXML = strXML & " <ItemDetail>" & strCR
strXML = strXML & " <UnitPrice>" & strCR
strXML = strXML & " <Money currency=" & chr(34) & "USD" & chr(34) & ">3.96</Money>" & strCR
strXML = strXML & " </UnitPrice>" & strCR
strXML = strXML & " <Description/>" & strCR
strXML = strXML & " <UnitOfMeasure>BX</UnitOfMeasure>" & strCR
strXML = strXML & " </ItemDetail>" & strCR
strXML = strXML & " </ItemOut>" & strCR
End If
End If
我有一个经典的 ASP Web 表单将用于订购。因为我不知道要订购哪些商品,所以我使用语句仅在订购数量 > 0 时将每个商品的代码生成到 XML 文件。我 运行 遇到的问题是要将其发送给的供应商希望将行号添加到每个项目。
我试过使用 For i=1 To VariableName
,然后在可能订购的项目列表的末尾使用 Next
。使用的变量名称是一个计算订购商品总数的字段。我还尝试了 for while 循环,指向 Here is a sample of the code for items ordered:
If strQty1 <> "" then
If strQty1 > 0 then
strXML = strXML & " <ItemOut quantity=" & chr(34) & strQty1 & chr(34) & " lineNumber=" & chr(34) & i & chr(34) & ">" & strCR
strXML = strXML & " <ItemID>" & strCR
strXML = strXML & " <SupplierPartID>S1K0R205B</SupplierPartID>" & strCR
strXML = strXML & " </ItemID>" & strCR
strXML = strXML & " <ItemDetail>" & strCR
strXML = strXML & " <UnitPrice>" & strCR
strXML = strXML & " <Money currency=" & chr(34) & "USD" & chr(34) & ">9.78</Money>" & strCR
strXML = strXML & " </UnitPrice>" & strCR
strXML = strXML & " <Description/>" & strCR
strXML = strXML & " <UnitOfMeasure>EA</UnitOfMeasure>" & strCR
strXML = strXML & " </ItemDetail>" & strCR
strXML = strXML & " </ItemOut>" & strCR
End If
End If
If strQty2 <> "" then
If strQty2 > 0 then
strXML = strXML & " <ItemOut quantity=" & chr(34) & strQty2 & chr(34) & " lineNumber=" & chr(34) & i & chr(34) & ">" & strCR
strXML = strXML & " <ItemID>" & strCR
strXML = strXML & " <SupplierPartID>A4216070B16</SupplierPartID>" & strCR
strXML = strXML & " </ItemID>" & strCR
strXML = strXML & " <ItemDetail>" & strCR
strXML = strXML & " <UnitPrice>" & strCR
strXML = strXML & " <Money currency=" & chr(34) & "USD" & chr(34) & ">3.96</Money>" & strCR
strXML = strXML & " </UnitPrice>" & strCR
strXML = strXML & " <Description/>" & strCR
strXML = strXML & " <UnitOfMeasure>BX</UnitOfMeasure>" & strCR
strXML = strXML & " </ItemDetail>" & strCR
strXML = strXML & " </ItemOut>" & strCR
End If
End If
如您所见,我有一个需要填充的 LineNumber 属性。 Do While 循环似乎不喜欢以变量结尾。它无限期地挂起表格,似乎陷入了永久循环。我发现的所有示例都是用于连续生成增量数字,而不是在我尝试执行的过程附近的任何地方。
从零开始 i,在每个 strQty# > 0 之后,将 i 递增 1 ( i = i +1 )。没有循环或类似的东西
例如
i = 0 ' Initiate the variable
If strQty1 <> "" then
If strQty1 > 0 then
i = i + 1 ' Increment it
strXML = strXML & " <ItemOut quantity=" & chr(34) & strQty1 & chr(34) & " lineNumber=" & chr(34) & i & chr(34) & ">" & strCR
strXML = strXML & " <ItemID>" & strCR
strXML = strXML & " <SupplierPartID>S1K0R205B</SupplierPartID>" & strCR
strXML = strXML & " </ItemID>" & strCR
strXML = strXML & " <ItemDetail>" & strCR
strXML = strXML & " <UnitPrice>" & strCR
strXML = strXML & " <Money currency=" & chr(34) & "USD" & chr(34) & ">9.78</Money>" & strCR
strXML = strXML & " </UnitPrice>" & strCR
strXML = strXML & " <Description/>" & strCR
strXML = strXML & " <UnitOfMeasure>EA</UnitOfMeasure>" & strCR
strXML = strXML & " </ItemDetail>" & strCR
strXML = strXML & " </ItemOut>" & strCR
End If
End If
If strQty2 <> "" then
If strQty2 > 0 then
i = i + 1 ' Increment it
strXML = strXML & " <ItemOut quantity=" & chr(34) & strQty2 & chr(34) & " lineNumber=" & chr(34) & i & chr(34) & ">" & strCR
strXML = strXML & " <ItemID>" & strCR
strXML = strXML & " <SupplierPartID>A4216070B16</SupplierPartID>" & strCR
strXML = strXML & " </ItemID>" & strCR
strXML = strXML & " <ItemDetail>" & strCR
strXML = strXML & " <UnitPrice>" & strCR
strXML = strXML & " <Money currency=" & chr(34) & "USD" & chr(34) & ">3.96</Money>" & strCR
strXML = strXML & " </UnitPrice>" & strCR
strXML = strXML & " <Description/>" & strCR
strXML = strXML & " <UnitOfMeasure>BX</UnitOfMeasure>" & strCR
strXML = strXML & " </ItemDetail>" & strCR
strXML = strXML & " </ItemOut>" & strCR
End If
End If