[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

code conversion from vb.net to c#

Posted on 2007-11-13
7
Medium Priority
?
184 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
[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
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:Joel Coehoorn
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 18

Expert Comment

by:Joel Coehoorn
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:
Joel Coehoorn earned 2000 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:Joel Coehoorn
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

649 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