|
-
Sep 5th, 2007, 04:46 PM
#1
Thread Starter
Hyperactive Member
Conversion Help!
Hello all!
Can someone please help me convert this to VB??? My C# is very weak!
Code:
protected void btnContinueShopping2_Click(object sender, EventArgs e)
{
/*
if (ViewState["ReturnURL"].ToString() == "")
{
Response.Redirect(AppLogic.GetCartContinueShoppingURL(SkinID, ThisCustomer.LocaleSetting));
}
else
{
Response.Redirect(ViewState["ReturnURL"].ToString());
}
* */
IDataReader rs = DB.GetRS("Select pv.VariantID, pv.Sizes, pv.Colors from ProductVariant pv join product p on pv.ProductID = p.ProductID where p.TrackInventoryBySizeAndColor=1 and (sizes not like '' or colors not like '')");
while (rs.Read())
{
string sizes = DB.RSField(rs, "sizes");
string colors = DB.RSField(rs, "colors");
if (sizes.Length > 0 && colors.Length > 0)
{
String[] colorarray = colors.Split(',');
String[] sizearray = sizes.Split(',');
int i = 0;
while (i < colorarray.Length)
{
//Clean Price Modifiers
if (colorarray[i].ToString().IndexOf('[') != -1)
{
colorarray[i] = colorarray[i].ToString().Substring(0, colorarray[i].ToString().IndexOf('[') - 1);
}
int x = 0;
while (x < sizearray.Length)
{
//Clean Price Modifiers
if (sizearray[x].ToString().IndexOf('[') != -1)
{
sizearray[x] = sizearray[x].ToString().Substring(0, sizearray[x].ToString().IndexOf('[') - 1);
}
DB.ExecuteSQL("insert Inventory(VariantID,Color,Size,Quan) values(" + DB.SQuote(DB.RSFieldInt(rs, "VariantID").ToString()) + "," + DB.SQuote(colorarray[i].ToString()) + "," + DB.SQuote(sizearray[x].ToString()) + ",100)");
x = x + 1;
}
i = i + 1;
}
}
else if (sizes.Length > 0 && colors.Length == 0)
{
String[] sizearray = sizes.Split(',');
int i = 0;
while (i < sizearray.Length)
{
//Clean Price Modifiers
if (sizearray[i].ToString().IndexOf('[') != -1)
{
sizearray[i] = sizearray[i].ToString().Substring(0, sizearray[i].ToString().IndexOf('[') - 1);
}
DB.ExecuteSQL("insert Inventory(VariantID,Size,Quan) values(" + DB.SQuote(DB.RSFieldInt(rs, "VariantID").ToString()) + "," + DB.SQuote(sizearray[i].ToString()) + ",100)");
i = i + 1;
}
}
else if (colors.Length > 0 && sizes.Length == 0)
{
String[] colorarray = colors.Split(',');
int i = 0;
while (i < colorarray.Length)
{
//Clean Price Modifiers
if (colorarray[i].ToString().IndexOf('[') != -1)
{
colorarray[i] = colorarray[i].ToString().Substring(0, colorarray[i].ToString().IndexOf('[') - 1);
}
DB.ExecuteSQL("insert Inventory(VariantID,Color,Quan) values(" + DB.SQuote(DB.RSFieldInt(rs, "VariantID").ToString()) + "," + DB.SQuote(colorarray[i].ToString()) + ",100)");
i = i + 1;
}
}
}
rs.Close();
rs.Dispose();
}
-
Sep 6th, 2007, 01:06 AM
#2
Re: Conversion Help!
I assume you mean VB.NET? Not VB6?
And we would basically need the whole code file. Because some of the variables in there are not declared in that particular function.
-
Sep 6th, 2007, 02:03 AM
#3
Re: Conversion Help!
I don't usually do this, but I was bored:
Code:
Protected Sub btnContinueShopping2_Click(sender As Object, e As EventArgs)
Dim rs As IDataReader = DB.GetRS("Select pv.VariantID, pv.Sizes, pv.Colors from ProductVariant pv join product p on pv.ProductID = p.ProductID where p.TrackInventoryBySizeAndColor=1 and (sizes not like '' or colors not like '')")
While rs.Read()
Dim sizes As String = DB.RSField(rs, "sizes")
Dim colors As String = DB.RSField(rs, "colors")
If sizes.Length > 0 AndAlso colors.Length > 0 Then
Dim colorarray As String() = colors.Split(","c)
Dim sizearray As String() = sizes.Split(","c)
Dim i As Integer = 0
While i < colorarray.Length
' Clean Price Modifiers
If (colorarray(i).IndexOf("["c) <> -1) Then
colorarray(i) = colorarray(i).Substring(0, colorarray(i).IndexOf("["c) - 1)
End If
Dim x As Integer = 0
While (x < sizearray.Length)
' Clean Price Modifiers
If (sizearray(x).IndexOf("["c) <> -1) Then
sizearray(x) = sizearray(x).Substring(0, sizearray(x).IndexOf("["c) - 1)
End If
DB.ExecuteSQL("insert Inventory(VariantID,Color,Size,Quan) values(" + DB.SQuote(DB.RSFieldInt(rs, "VariantID").ToString()) + "," + DB.SQuote(colorarray(i)) + "," + DB.SQuote(sizearray(x)) + ",100)")
x += 1
End While
i += 1
End While
Else If sizes.Length > 0 AndAlso colors.Length = 0
Dim sizearray As String() = sizes.Split(","c)
Dim i As Integer = 0
While i < sizearray.Length
' Clean Price Modifiers
If (sizearray(i).IndexOf("["c) <> -1) Then
sizearray(i) = sizearray(i).Substring(0, sizearray(i).IndexOf("["c) - 1)
End If
DB.ExecuteSQL("insert Inventory(VariantID,Size,Quan) values(" + DB.SQuote(DB.RSFieldInt(rs, "VariantID").ToString()) + "," + DB.SQuote(sizearray(i)) + ",100)")
i += 1
End While
Else If (colors.Length > 0 AndAlso sizes.Length = 0)
Dim colorarray As String() = colors.Split(","c)
Dim i As Integer = 0
While i < colorarray.Length
' Clean Price Modifiers
If (colorarray(i).IndexOf("["c) <> -1) Then
colorarray(i) = colorarray(i).Substring(0, colorarray(i).IndexOf("["c) - 1)
End If
DB.ExecuteSQL("insert Inventory(VariantID,Color,Quan) values(" + DB.SQuote(DB.RSFieldInt(rs, "VariantID").ToString()) + "," + DB.SQuote(colorarray(i)) + ",100)")
i += 1
End While
End If
End While
rs.Close()
rs.Dispose()
End Sub
That's an almost 1:1 conversion, save for a couple of insignificant changes (removed some redundant ToString calls on strings).
Looking at the code, you could probably condense it a lot; the logic looks like it has some redundancy. But I'll leave that to you.
Also, you might want to consider using a Using...End Using block rather than manually calling the Close and Dispose methods on your recordset object. Using blocks make the cleanup calls implicit, so as long as you open with a Using statement instead of Dim there is no chance of you forgetting to dispose of objects properly.
Look for a utility called 'InstantVB' by a member of ours, David Anton, for automated syntax conversions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|