Click here to Skip to main content
15,122,406 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have problem to convert vb code to c#, I am working in project accounting system so i need to convert this code to c# in order to get report
Dim numRef As Integer
    numRef = CInt(AddressOf Me.gCurrentX) = CInt(Math.Round(CDbl((CSng(numRef) + Me.gCurrentW))))

What I have tried:

I have tried this but it is wrong
int.Parse(new System.EventHandler(this.gCurrentY)) = int.Parse(Math.Round(double.Parse((float.Parse(numRef) + this.gCurrentH))));
Richard MacCutchan 24-Sep-21 3:18am
Why are you calling Parse three times? You only need to parse the initial string into whatever number type it is supposed to be.
Sni.DelWoods 24-Sep-21 5:21am
Please rewrite the VB code in a readable form to make clear what it does, e.g.
Dim gCurrentX = AddressOf Me.gCurrentX 'Why do you need AdressOf here??
Dim gCurrentY = Me.gCurrentW
Dim numRef As Integer = CInt(gCurretX)

I understand the multiple C# converions, VB returns a double on Int * Double, C# returns Int.
After that you should have one removed most of the conversions in the VB code. After that you can convert it to C#..
DerekT-P 3-Oct-21 15:05pm
Both versions are pretty pointless. VB will always return 0 (you're doing a comparison and assigning the true/false result to an integer; the comparison will fail since you're comparing the address of a property to.. we don't know what. But converting an address to an integer will fail anyway). C# may make some kind of assignment but as there's no variable on the left the result will be lost anyway. (assuming you fix any actual syntax errors). The VB code refers to properties gCurrentX and gCurrentW, whilst the C# refers to gCurrentY and gCurrentH. And since we don't know what me/this refers to, we've got no idea what these properties are.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900