I'm getting stumped by what I hope is a simple problem. I'm trying to embed a simple formula incrementing a variable to act as a "line number" for an XML document. Writing literal XML in visual basic. Here's what the code looks like:
<%= From d In orderData
Select <ItemOut quantity=<%= d.OrderQuantity %> lineNumber=<%= i %>>
<ItemID>
<SupplierPartID><%= d.VendorPartNo %></SupplierPartID>
</ItemID>
<ItemDetail>
<UnitPrice>
<Money currency="USD"><%= d.PricePerPackage %></Money>
</UnitPrice>
<Description xml:lang="en"><%= d.Description %></Description>
<UnitOfMeasure><%= d.OrderUOM %></UnitOfMeasure>
</ItemDetail>
<%= i = i + 1 %>
</ItemOut>
%>
I was expecting each iteration of d in OrderData to tick i + 1, however, it is simply returning "false". See the output XML here:
<ItemOut quantity="1" lineNumber="1">
<ItemID>
<SupplierPartID>99999</SupplierPartID>
</ItemID>
<ItemDetail>
<UnitPrice>
<Money currency="USD">0.00</Money>
</UnitPrice>
<Description xml:lang="en">Tub and Tile Caulk Biscuit</Description>
<UnitOfMeasure>cs</UnitOfMeasure>
</ItemDetail>false</ItemOut>
<ItemOut quantity="1" lineNumber="1">
<ItemID>
<SupplierPartID>999999</SupplierPartID>
</ItemID>
<ItemDetail>
<UnitPrice>
<Money currency="USD">0.00</Money>
</UnitPrice>
<Description xml:lang="en">Tub and Tile Caulk Almond</Description>
<UnitOfMeasure>cs</UnitOfMeasure>
</ItemDetail>false</ItemOut>
Is it possible to do this sort of thing? I even tried making a call to a function instead:
lineNumber=<%= incrementI(i) %>>
But that also results in "false" as the output. What am I missing here? Thank you for your help in advance!
Visual Studio 2013
Edit-- Here's the function I'm referring to:
Private Function incrementI(i As Integer)
Return i = i + 1
End Function
If you define
IncrementIto accept its parameter by reference rather than by value, you can write this:Which produces this XML:
As pointed out in the comments, Visual Basic uses
=for both assignment and equality. If you use it in a context where an expression is required, you'll get an equality comparison that returnsTrueorFalse.If you turn on
Option Strictand define the function return type, then the compiler would have helped you see that your function hadn't fixed matters:When Option Strict is on, the above produces the error