Conversion C++ to VB.net

bitong

New member
Joined
Sep 5, 2007
Messages
4
Programming Experience
Beginner
Did i convert this to vb.net correctly?

unsigned long int x, y, z;
cout<<"Enter a number: ";
cin>>y;
for (x = y;x>0;x=x/10){
z = x % 10;
cout<<z;
}

Dim x, y, z as Integer
Console.WriteLine("Enter a number: ")
y = console.ReadLine()
For x = 0 To y Step x=x/10
z = x Mod 10
console.WriteLine("{0}",z)
Next
 
I'm afraid not. A C language FOR loop does NOT simply specify a value to increment the counter by. It actually specifies an action that can be anything at all, involving the counter or not. This:
VB.NET:
for (x = y;x>0;[U]x=x/10[/U])
is NOT saying that 'x' gets incremented by specific value after each iteration. It's saying that 'x' gets divided by 10 after each iteration. That's not possible in a VB.NET FOR loop, which requires that the counter be incremented by a set integer value. That loop would have to be implemented in VB as a DO or a WHILE loop, e.g.
VB.NET:
x = y

Do While x > 0
    z = x Mod 10
    Console.WriteLine(z)
    x = x / 10
Loop
 
Back
Top