Solved

code conversion from vb.net to c#

Posted on 2007-11-13
7
177 Views
Last Modified: 2013-11-26
Here is the vb.net 1.1 code, I want to convert it to c#2.0 , I don't know vb.net.
Please help me.It's extremely urgent.Thanks a million in advance.I'd be grateful to u.

Private Sub GetPaymentHoldIndicator(ByVal sAcctNo As String)
        Dim bRetVal As Boolean = False
        Dim sPymtHoldInd As String = "N"
        Dim sPymtScore As String = ""
        Dim sPymtStartDt As String = ""
        Dim sPymtStopDt As String = ""
        Dim oConn As New tsysConnect
        Dim oCIFS As New TSYS2.TS2.CIFS     'Inquire Payment & Fraud Scores

        Try
            oCIFS.RequestedAccount = sAcctNo
            bRetVal = oConn.PerformInquire(oCIFS)

            If bRetVal Then
                sPymtScore = oCIFS.Payment_Score.Trim
                sPymtStartDt = oCIFS.Payment_Score_Start_Date.Trim
                sPymtStopDt = oCIFS.Payment_Score_Stop_Date.Trim

                If Not IsNumeric(sPymtScore) Then Exit Sub

                If CLng(sPymtScore) > 0 Then                                                                    ' If Payment Score is not "000"
                    If CLng(sPymtScore) <> 999 And CLng(sPymtScore) <> 213 And CLng(sPymtScore) <> 217 Then     ' Exception Case - Ignore
                        If Not IsDate(sPymtStartDt) Then Exit Sub
                        If Not IsDate(sPymtStopDt) Then Exit Sub

                        ' If current date falls between start date and stop date
                        If CDate(sPymtStartDt) <= DateTime.Today Then
                            If CDate(sPymtStopDt) >= DateTime.Today Then
                                sPymtHoldInd = "Y"
                            End If
                        End If
                    End If
                End If

                If sPymtHoldInd = "Y" Then
                    lbPymtHoldInd.Visible = True
                    lPymtHldInd.Visible = False
                    lPymtHoldInd.Text = sPymtHoldInd
                    lPymtScore.Text = sPymtScore
                    lPymtStartDt.Text = sPymtStartDt
                    lPymtStopDt.Text = sPymtStopDt
                Else
                    lbPymtHoldInd.Visible = False
                    lPymtHldInd.Visible = True
                    lPymtHldInd.Text = sPymtHoldInd
                End If
            End If
        Catch ex As Exception
            Dim oError As New Blast2.Errors
            oError.LogToEvent(ex.ToString)
            Throw New Exception(ex.ToString())
        End Try
    End Sub
0
Comment
Question by:amukta
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:jcoehoorn
Comment Utility
I may have missed something here or there, but since you have some 3rd party components I can't test it against the compiler.  However,  this should get you 90% or more:


void GetPaymentHoldIndicator(string sAcctNo)
{
        bool RetVal = false;
        string PymtHoldInd = "N";
        string PymtScore;
        string PymtStartDt;
        string PymtStopDt;
        tsysConnect oConn = new tsysConnect();
        TSYS2.TS2.CIFS oCIFS = new TSYS2.TS2.CIFS();    //Inquire Payment & Fraud Scores

        try
        {
            oCIFS.RequestedAccount = sAcctNo;
            RetVal = oConn.PerformInquire(oCIFS);

            if (RetVal)
            {
                PymtScore  = oCIFS.Payment_Score.Trim();
                PymtStartDt = oCIFS.Payment_Score_Start_Date.Trim();
                PymtStopDt = oCIFS.Payment_Score_Stop_Date.Trim();

                int z;
                if (!int.TryParse(PymtScore,out z)) return;

                if (Convert.ToInt64(PymtScore) > 0)                             // If Payment Score is not "000"
                {
                    if (Convert.ToInt64(PymtScore) != 999 && Convert.ToInt64(PymtScore) != 213 && Convert.ToInt64(PymtScore) != 217 )  // Exception Case - Ignore
                    {
                        DateTime Start, Stop;
                        if (!DateTime.TryParse(PymtStartDt,out Start)) return;
                        if (!DateTime.TryParse(PymtStopDt,out Stop)) return;

                        // If current date falls between start date and stop date
                        if ( Start <= DateTime.Today &&Stop >= DateTime.Today)
                                PymtHoldInd = "Y";
                       
                    }
                }

                if (PymtHoldInd == "Y")
                {
                    lbPymtHoldInd.Visible = true;
                    lPymtHldInd.Visible = false;
                    lPymtHoldInd.Text = PymtHoldInd;
                    lPymtScore.Text = PymtScore;
                    lPymtStartDt.Text = PymtStartDt;
                    lPymtStopDt.Text = PymtStopDt;
                }
                else
                {
                    lbPymtHoldInd.Visible = false;
                    lPymtHldInd.Visible = true;
                    lPymtHldInd.Text = PymtHoldInd;
               }
            }
        }
        catch (Exception ex )
        {
            Blast2.Errors oError = new Blast2.Errors();
            oError.LogToEvent(ex.ToString());
            throw new Exception(ex.ToString(), ex);
        }
    }
0
 

Author Comment

by:amukta
Comment Utility
Hi!
Thank you very much!
Instead of
 DateTime Start;
if (!DateTime.TryParse(PymtStartDt,out Start)) return;
                       Can I use
Try{
if(PymtStartDt==DateTime.Parse(PymtStartDt)
}
catch{
return;
}
 ;
and similarly for
DateTime Start;
if (!DateTime.TryParse(PymtStopDt,out Stop)) return
and also for
 int z;
  if (!int.TryParse(PymtScore,out z)) return;
Can I do this s done above?
Please let me know ASAP!
IT'S EXTREMELY URGENT!

THANKS A MILLION IN ADVANCE!
0
 

Author Comment

by:amukta
Comment Utility
Hi!
Thank you very much!
Instead of
 DateTime Start;
if (!DateTime.TryParse(PymtStartDt,out Start)) return;
                       Can I use
Try{
if(PymtStartDt==DateTime.Parse(PymtStartDt)
}
catch{
return;
}
 ;
and similarly for
DateTime Start;
if (!DateTime.TryParse(PymtStopDt,out Stop)) return
and also for
 int z;
  if (!int.TryParse(PymtScore,out z)) return;
Can I do this as done above?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 18

Expert Comment

by:jcoehoorn
Comment Utility
Looking at this line:
    if(PymtStartDt==DateTime.Parse(PymtStartDt)
You're missing a parentheses at the end, and you're comparing a string type to a datetime type, so you might not get the results you expect.  Also, looking back at the original code it converted PymtScore to a number no fewer than five times, and I should have used a long anyway.  You could simplify that whole section like this:

    long score=0;
    try {
        score = long.Parse(PymtScore);

        // If Payment Score is not "000"
        if (score > 0 && score != 999 && score != 213 && score != 217) //exception cases
        {
             // If current date falls between start date and stop date
            if ( DateTime.Parse(PymtStartDt) <= DateTime.Today && DateTime.Parse(PymtStopDt) >= DateTime.Today)
                    PymtHoldInd = "Y";
        }
    }
    catch {
        return;
    }







0
 

Author Comment

by:amukta
Comment Utility
DateTime Start;
if (!DateTime.TryParse(PymtStartDt,out Start)) return;
  Can I use
Try{
if(PymtStartDt==DateTime.Parse(PymtStartDt).ToString())
}
catch{
return;
}
 ;
and similarly for
DateTime Stop;
if (!DateTime.TryParse(PymtStopDt,out Stop)) return
can i use
try{
if(PymtStopDt==DateTime.Parse(PymtStopDt).ToString())
}
catch{
return;}
and instead of
int z;
  if (!int.TryParse(PymtScore,out z)) return;

Can I use
try{
if(PymtScore==double.Parse(PymtScore))
}
catch{
return;}


Can I do this as done above?
Please let me know.

I didn't undertstand y we need to change the code to the latest oen u've sen tme
Thanks
0
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 500 total points
Comment Utility
The new code means you only have to convert PymtScore to a numeric type one time instead of five, you only need one try/catch block instead of three, and get's rid of an extra layer of nesting your {} braces.

Now let's look again at this line:
  if(PymtStartDt==DateTime.Parse(PymtStartDt).ToString())

It still won't work, because the .ToString() method is not guaranteed to generate the same string as PymtStartDt.  In fact, by specifying different format options I could create many different versions of the string that all represent that same date.  For example, if PymtStartDt is "11/15/2007" you could tell .ToString() to output "November 15, 2007" instead, as just one example.  What will be used by default depends on the datetime settings in the control panel of the computer where the code runs.  Here's a version that would work:

    DateTime.Parse(PymtStartDt)

No if() statement, no comparison.  It will work because if PymtStartDt cannot be converted to a datetime an exception will be thrown for the enclosing try/catch block.  This will also work for PymtStopDt and PymtScore, though in the case of the latter I would use long.Parse() rather than double.Parse(), since that more closely matches the original.
0
 
LVL 18

Expert Comment

by:jcoehoorn
Comment Utility
One more thing I thought of:
I can only presume your initial reluctance to use TryParse() results either because you're using .Net 1.1, which doesn't have TryParse(), or because you want the code to match the original vb.  Since you were reluctant to go with my 2nd version, which meets the first hypothesis, I'm inclined to believe it's the latter.  In that case, this being C#, I'd put the try/catch all on one line like this so it more closely resembles the vb line for line:
try {DateTime.Parse(PymtStartDt)} catch {return;}
try {DateTime.Parse(PymtStopDt} catch {return;}
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

763 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

7 Experts available now in Live!

Get 1:1 Help Now