Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convertion question

Posted on 2011-02-25
13
Medium Priority
?
318 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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 500 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

782 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