Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Need help with the syntax for a loop.



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> Visual Basic Forum
View previous topic :: View next topic  
Author Message
banksidepoet



Joined: 25 May 2008
Posts: 2

PostPosted: Sun May 25, 2008 7:09 am    Post subject: Need help with the syntax for a loop. Reply with quote

Hi, Can anyone help me with this syntax.

I have am ASP.NET form which lists products for sale. Each item has a textbox which invites the buyer to enter the number of that item she would like to buy (with a default of 0).

I have created a VB code behind file which processes the form and sends the data to PayPal.

The problem is that PayPal will (understandably) not accept "0" as an input for quantity. So, I need to strip the items that the user doesn't want any of before I send the items. The problem is further complicated because PayPal needs the items in the cart to be consecutively numbered so, I need to skip the "0" items but NOT the item count.

Here's the code. I've come up with a simple For... Next loop which skips creating POST code for "0" items but which does not increment the value of "i" if it skips (so maintaining the "consecutive" nature of the count).

1. Dim i As Integer
2. For i = 1 to 2

3. If TextBox1.Text >= 1 Then
ppForm.Append("<input type=" + """" + "hidden" + """" + " name=" + """" + "item_name_1" + """" + " value=" + """" + product1 + """" + ">")
4. i += 1
5. EndIf

6. If TextBox2.Text >= 1 Then
7. ppForm.Append("<input type=" + """" + "hidden" + """" + " name=" + """" + "item_name_2" + """" + " value=" + """" + product2 + """" + ">")
8. i += 1
9. EndIf

10. Next i

Basically, the code retrieves the value of TextBox1 (how many of item 1 the buyer wants). If it is not 0, the code to send the details to PayPal is created and the item is the "first" item in the Cart. If it is 0, the code is not generated but "i" remains 1, so when it looks for the next quantity (TextBox2.Text) I can use the value of i to say to PayPal, "this" is the first item in the Cart.

But the code above will only work if I can replace "item_name_1" and "item_name_2" with "item_name_i".

What is the syntax to do this? I've tried all manner of concatenations and quotes but keep getting a malformed string error. I'm new to VB and not sure what the """"'s do. (The POST code I'm using was recommended to me by a much cleverer guy!)

I'd appreciate help if anyone's able.
Back to top
View user's profile Send private message
banksidepoet



Joined: 25 May 2008
Posts: 2

PostPosted: Sun May 25, 2008 9:50 am    Post subject: Re: Need help with the syntax for a loop. Reply with quote

Got a response from MSDN VB Forum:

Dim Count As Integer = 1
While Count < 2

If TextBox1.Text >= 1 Then
Dim item As String = "item_name_" & Count
Dim amount As String = "amount_" & Count
Dim quantity As String = "quantity_" & Count
ppForm.Append("<input type=" + """" + "hidden" + """" + " name=" + """" + item + """" + " value=" + """" + product1 + """" + ">")
ppForm.Append("<input type=" + """" + "hidden" + """" + " name=" + """" + amount + """" + " value=" + """" + price1 + """" + ">")
ppForm.Append("<input type=" + """" + "hidden" + """" + " name=" + """" + quantity + """" + " value=" + """" + number1 + """" + ">")
Count += 1
End If

If TextBox2.Text >= 1 Then
Dim item As String = "item_name_" & Count
Dim amount As String = "amount_" & Count
Dim quantity As String = "quantity_" & Count
ppForm.Append("<input type=" + """" + "hidden" + """" + " name=" + """" + item + """" + " value=" + """" + product2 + """" + ">")
ppForm.Append("<input type=" + """" + "hidden" + """" + " name=" + """" + amount + """" + " value=" + """" + price2 + """" + ">")
ppForm.Append("<input type=" + """" + "hidden" + """" + " name=" + """" + quantity + """" + " value=" + """" + number2 + """" + ">")
Count += 1
End If

End While

Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> Visual Basic Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap