garymcgowan

asked on

# Converting Access 2003 to .Net C#

I'm converting an Access 2003 program to .Net C#. I'm new to .Net and C#. The conversion was going good until I tried to convert the Control Source for a field.

Any help in converting this into C# would be appreciated.

=Val((Sqr([txtTradingDays]))*180-225) Mod 360

Thanks,

Gary

Any help in converting this into C# would be appreciated.

=Val((Sqr([txtTradingDays]

Thanks,

Gary

SOLUTION

membership

This solution is only available to members.

To access this solution, you must be a member of Experts Exchange.

ASKER

Thanks santhimurthyd for your reply. Your code "int value = ((Math.Pow( Convert.ToInt32(txtTradingDays) , 2) * 180 ) - 225) % 360;" throws the following exception:

Error1 Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)

If I make these changes I get no errors:

Double value = ((Math.Pow( Convert.ToDouble(txtTradingDays) , 2) * 180 ) - 225) % 360;"

I try to put value in a text field with this code:

txtTradingDaysRemainder.Text = value.ToString;

and I get this error:

Error1 Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method?

Any additional ideas will be appreciated.

Gary

Error1 Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)

If I make these changes I get no errors:

Double value = ((Math.Pow( Convert.ToDouble(txtTradin

I try to put value in a text field with this code:

txtTradingDaysRemainder.Te

and I get this error:

Error1 Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method?

Any additional ideas will be appreciated.

Gary

ASKER

Thanks for your reply gustav. Your code throws several exceptions that I cannot figure out. Any additional ideas will be appreciated.

Gary

Gary

First, type ToString() as a method():

txtTradingDaysRemainder.Text = value.ToString();

Then, as Math returns a double:

int value = Convert.ToInt32(Math.Floor((Math.Sqrt(Convert.ToInt32(txtTradingDays)) * 180 - 225))) % 360;

or perhaps:

int value = (int)Math.Floor((Math.Sqrt(Convert.ToInt32(txtTradingDays)) * 180 - 225)) % 360;

If txtTradingDays contains a non-numeric string, an exception will be raised. If so, you will need to wrap in a normal Try .. Catch construct which should return 0 (zero) for non-numeric values.

/gustav

txtTradingDaysRemainder.Te

Then, as Math returns a double:

int value = Convert.ToInt32(Math.Floor

or perhaps:

int value = (int)Math.Floor((Math.Sqrt

If txtTradingDays contains a non-numeric string, an exception will be raised. If so, you will need to wrap in a normal Try .. Catch construct which should return 0 (zero) for non-numeric values.

/gustav

ASKER

Thanks gustav. I was able to get this to work with the following code:

int thisvalue1 = int.Parse(txtTradingDays.Text);

double thisvalue2 = Math.Sqrt(thisvalue1) * 180 - 225;

double thisvalue3 = thisvalue2 % 360;

txtTradingDaysRemainder.Text = thisvalue3.ToString();

Couldn't get it to work in a single line of code. I am going to split the points between you and santhimurthyd. Between the two of you I was able to figure out what I was doing wrong.

Thanks for your help.

Gary

P.S.

If you know how to get my code to work in a single line I would appreciate seeing it.

int thisvalue1 = int.Parse(txtTradingDays.T

double thisvalue2 = Math.Sqrt(thisvalue1) * 180 - 225;

double thisvalue3 = thisvalue2 % 360;

txtTradingDaysRemainder.Te

Couldn't get it to work in a single line of code. I am going to split the points between you and santhimurthyd. Between the two of you I was able to figure out what I was doing wrong.

Thanks for your help.

Gary

P.S.

If you know how to get my code to work in a single line I would appreciate seeing it.

ASKER CERTIFIED SOLUTION

membership

This solution is only available to members.

To access this solution, you must be a member of Experts Exchange.

=Math.Floor((Math.Sqrt(txt

/gustav