如何基于变量创建增量编号

时间:2015-11-25 18:58:33

标签: vbscript asp-classic

我有一个经典的ASP网页表单,将用于订购。由于我不知道将订购哪些项目,因此我使用语句仅在订购数量为>时将每个项目的代码生成为XML文件。我遇到的问题是发送给它的供应商想要添加到每个项目的行号。

我已尝试使用varchar,然后在可能的订购商品列表末尾添加For i=1 To VariableName。使用的变量名称是计算订购总项目的字段。我还尝试了 for while循环,指向以下是订购商品代码的示例:

Next

如您所见,我有一个我需要填充的LineNumber属性。 Do While循环似乎不喜欢以变量结尾。它无限期地悬挂在表格上,似乎陷入了永久性的循环中。我发现的所有例子都是连续生成增量数字,而不是我正在尝试执行的过程附近。

1 个答案:

答案 0 :(得分:0)

从零开始,紧接着每个strQty#> 0,将i递增1(i = i + 1)。没有循环或其他类似的东西

e.g。

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