Solved

Convertion question

Posted on 2011-02-25
13
307 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
Comment Utility
What is the error message you are getting?
0
 

Author Comment

by:avi7
Comment Utility
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
Comment Utility
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
 
LVL 9

Expert Comment

by:rawinnlnx9
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Assisted Solution

by:ALaRiva
ALaRiva earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Should I use something like this Convert.ToInt32(ddlAcct1.SelectedValue)  
0
 
LVL 33

Expert Comment

by:Todd Gerbert
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now