Solved

Convertion question

Posted on 2011-02-25
13
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

623 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