Solved

Convertion question

Posted on 2011-02-25
13
310 Views
Last Modified: 2012-05-11
Hi, I am trying to convert the following code but I am getting some error message. Does it look right? Please advise.

VB:
If lblRec1.Text <> "" And ddlAcct1.SelectedValue <> "" Then Call UpdateCustAccount(lblRec1.Text, IIf(ddlAcct1.SelectedValue = "", 0, ddlAcct1.SelectedValue))

C#
if (lblRec1.Text != "" && ddlAcct1.SelectedValue != ""){ UpdateCustAccount (lblRec1.Text,(ddlAcct1.SelectedValue == "") ? 0 : ddlAcct1.SelectedValue);}
0
Comment
Question by:avi7
  • 6
  • 3
  • 2
  • +1
13 Comments
 
LVL 10

Expert Comment

by:ALaRiva
ID: 34984859
What is the error message you are getting?
0
 

Author Comment

by:avi7
ID: 34984898
The error is:
Error The best overloaded method match for 'UpdateCustAccount (int, int)' has some invalid argument
For this part of the code:      
{ UpdateCustAccount (lblRec1.Text,(ddlAcct1.SelectedValue == "") ? 0 : ddlAcct1.SelectedValue);}
0
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 250 total points
ID: 34984913
If I convert the C# to VB this is what I get:

if (lblRec1.Text != "" && ddlAcct1.SelectedValue != ""){ UpdateCustAccount (lblRec1.Text,(ddlAcct1.SelectedValue == "") ? 0 : ddlAcct1.SelectedValue);}
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34984919
If I convert the C# to VB this is what I get:

If lblRec1.Text <> "" AndAlso ddlAcct1.SelectedValue <> "" Then
	UpdateCustAccount (lblRec1.Text,If(ddlAcct1.SelectedValue = "", 0, ddlAcct1.SelectedValue))
End If

Open in new window

0
 

Author Comment

by:avi7
ID: 34984929
Sorry for convision by I am trying to convet from VB to C# and it's where I have problem.. So you are saying that my C# code is correct?
0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34984945
I get errors converting the VB to C# you posted. When I take your C# and converted it to VB I got no errors.  So that's how I approached your problem. I first took your C# as it is and converted it to VB. Then I took the VB and covnerted it back to C# and got the same code.
0
 

Author Comment

by:avi7
ID: 34984957
So what are you saying do I have a problem or not?
0
 
LVL 10

Assisted Solution

by:ALaRiva
ALaRiva earned 125 total points
ID: 34985001
The problem is that it's reading one of your values as NOT an [int] datatype.

Try parsing the return of your x?0:y return as an INT.

hth
0
 

Author Comment

by:avi7
ID: 34985028
Can you please show me on my code example since I am doing something here but I am not sure if it's correct. Thanks!
0
 

Author Comment

by:avi7
ID: 34985056
Here is something else that might help to see what I am trying to do:
private void UpdateCustAccount (int strRecID, int strAcct)
0
 
LVL 33

Assisted Solution

by:Todd Gerbert
Todd Gerbert earned 125 total points
ID: 34985104
The UpdateCustAccount method expects to parameters, both int's (aka Int32, or Integer in VB).  You're trying to pass strings to this method.
0
 

Author Comment

by:avi7
ID: 34985577
Should I use something like this Convert.ToInt32(ddlAcct1.SelectedValue)  
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 34985777
Yes,  or Int32.Parse or Int32.TryParse. I think you have another question open on that topic, which has some good comments.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question