views:

59

answers:

3

Hello,

I am having trouble incrementing the indexes of my list item properties. Here is the code.

        Dim i As Integer = 0

        For x As Integer = 1 To list.Count / 19
            database.ExecuteCommand("INSERT INTO Contacts VALUES ('" + _
                                    list.Item(i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "', '" + _
                                    list.Item(++i) + "')")
        Next

The ++i does not increment at all in the parameters.

Thanks

A: 

you need to use your loop variable (x) and increase the index in that manner.

I'm doing this in C# but I'm sure you will understand.

string sql = "INSERT INTO Contact VALUES ('";

for(int i = 1; i < list.Count ; i++)
{
   sql += list.Item(i) + "', '";

}
sql = sql.Remove(sql.Length -1);
sql += ")";

Database.ExecuteCommand(sql);
TheGeekYouNeed
Thanks, that helped out a lot.
Daniel
A: 

VB.Net does not have an increment operator.

ho1
A: 

Add this Function

Function GetIncrementValue(byval x as integer) as integer x=x+1 End function

Your Code will be......

Dim i As Integer = 0

    For x As Integer = 1 To list.Count / 19
        database.ExecuteCommand("INSERT INTO Contacts VALUES ('" + _
                                list.Item(i) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "', '" + _
                                list.Item(GetIncrementValue(i)) + "')")
    Next

Enjoy....

Manish kosta