Solved

code conversion from vb.net to c#

Posted on 2007-11-13
7
178 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
ID: 20275778
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
ID: 20288414
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
ID: 20288417
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20289243
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
ID: 20290731
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
ID: 20291654
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
ID: 20292465
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

17 Experts available now in Live!

Get 1:1 Help Now