Click here to Skip to main content
11,486,649 members (69,437 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VB
Hi guys,

I'm having to translate some old VB code into C#, and I'm a bit stumped on this one set of statements. I don't need to know what the output string would be, just which route the code would take through this statement (and why!).

            Select Case True
              Case Not IsNumeric(strValue)
                strValue = Format$(Now, "dd-mmm-yyyy")
              Case CDbl(strValue) = 0
                strValue = Format$(Now, "dd-mmm-yyyy")
              Case Else
                strValue = Format$(DateSerial(Left(strValue, 2), Mid(strValue, 3, 2), Right(strValue, 2)), "dd-mmm-yyyy")
            End Select

The first two Case statements both return the same value regardless, so it makes no sense to me how I should really be translating this into C#. Any ideas?

Many thanks.
Posted 28-Dec-12 5:26am
Edited 28-Dec-12 5:30am
v4

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

if (!IsNumeric(strValue)){
    strValue = Format$(Now, "dd-mmm-yyyy")
} else if (strValue == 0){
    strValue = Format$(Now, "dd-mmm-yyyy")
} else {
    strValue = Format$(DateSerial(Left(strValue, 2), Mid(strValue, 3, 2), Right(strValue, 2)), "dd-mmm-yyyy")
}

Of course i didn't find the C# equivalent but you get the idea of how the code flows now.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,888
1 OriginalGriff 8,147
2 Sascha Lefèvre 3,254
3 Maciej Los 2,886
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100