|
-
Oct 14th, 2007, 02:46 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2.0] Switch with Case Range
Is there a way in C# to have a range for a case statement. You can do this in VB, but how can you in C#:
Code:
Select Case e.KeyChar
Case Chr(8)
Case "0"c To "9"c
Dim val As Int64 = CType(MyBase.Text & e.KeyChar, Int64)
If val < _minRange Then
MyBase.Text = _minRange.ToString
e.Handled = True
End If
If val > _maxRange Then
If Me.SelectionLength = 0 Then
MyBase.Text = _maxRange.ToString
e.Handled = True
End If
End If
Case Else
Beep()
e.Handled = True
End Select
If your problem is solved, please use the Mark Thread As Resolved under Thread Tools!
Show Appreciation. Rate Posts!
-
Oct 14th, 2007, 07:08 PM
#2
Re: [2.0] Switch with Case Range
No, but the if/else equivalent is pretty trivial anyway (via Instant C#):
Code:
//INSTANT C# NOTE: The following VB 'Select Case' included range-type or non-constant 'Case' expressions and was converted to C# 'if-else' logic:
// Select Case e.KeyChar
//ORIGINAL LINE: Case Chr(8)
if (e.KeyChar == '\b')
{
}
//ORIGINAL LINE: Case "0"c To "9"c
else if (e.KeyChar >= '0' && e.KeyChar <= '9')
{
Int64 val = System.Convert.ToInt64(base.Text + e.KeyChar);
if (val < _minRange)
{
base.Text = _minRange.ToString();
e.Handled = true;
}
if (val > _maxRange)
{
if (this.SelectionLength == 0)
{
base.Text = _maxRange.ToString();
e.Handled = true;
}
}
}
//ORIGINAL LINE: Case Else
else
{
Microsoft.VisualBasic.Interaction.Beep();
e.Handled = true;
}
-
Oct 14th, 2007, 08:05 PM
#3
Thread Starter
Fanatic Member
Re: [2.0] Switch with Case Range
Darn, I was hoping to use a switch here, but alright. Thanks!
If your problem is solved, please use the Mark Thread As Resolved under Thread Tools!
Show Appreciation. Rate Posts!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|