Connecting Tech Pros Worldwide Forums | Help | Site Map

.net 2005 convert from VB to c++

Galil
Guest
 
Posts: n/a
#1: Sep 25 '07
I have a subroutine I need to convert from vb.net 2005 to visual C++
( .net 2005)
The function only allows specific characters to be typed into a
textbox. the backspace and 0 -9.

Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case Asc(e.KeyChar) <-- Is this function available in C
+
+?
Case 8, 48 To 57
e.Handled = False
Case Else
e.Handled = True
End Select
End Sub

Could someone convert this into C++?
or is there a way to call this subroutine in C++?
I am very new to programming so please be specific. (#include
statements, etc.)
Thank you


Mattias Sjögren
Guest
 
Posts: n/a
#2: Sep 25 '07

re: .net 2005 convert from VB to c++


>The function only allows specific characters to be typed into a
Quote:
>textbox. the backspace and 0 -9.
>
>Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As
>System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case Asc(e.KeyChar) <-- Is this function available in C
>+
>+?
Case 8, 48 To 57
e.Handled = False
Case Else
e.Handled = True
End Select
End Sub
This code doesn't handle strings that gets pasted into the textbox.

Quote:
>
>Could someone convert this into C++?
Are you using Windows Forms? MFC? plain Windows APIs?


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
 
Posts: n/a
#3: Sep 25 '07

re: .net 2005 convert from VB to c++


Here is a conversion to C++/CLI (with Instant C++):

private:
//TODO: INSTANT C++ TODO TASK: Insert the following converted event handlers
at the end of the 'InitializeComponent' method for forms or into a
constructor for other classes:
TextBox1->KeyPress += gcnew
System::Windows::Forms::KeyPressEventHandler(this, &textbox1_KeyPress);

void textbox1_KeyPress(System::Object ^sender,
System::Windows::Forms::KeyPressEventArgs ^e)
{
if ((System::Convert::ToInt32(e->KeyChar) == 8) ||
(System::Convert::ToInt32(e->KeyChar) >= 48 &&
System::Convert::ToInt32(e->KeyChar) <= 57))
{
e->Handled = false;
}
else
{
e->Handled = true;
}
}

--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter


"Galil" wrote:
Quote:
I have a subroutine I need to convert from vb.net 2005 to visual C++
( .net 2005)
The function only allows specific characters to be typed into a
textbox. the backspace and 0 -9.
>
Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case Asc(e.KeyChar) <-- Is this function available in C
+
+?
Case 8, 48 To 57
e.Handled = False
Case Else
e.Handled = True
End Select
End Sub
>
Could someone convert this into C++?
or is there a way to call this subroutine in C++?
I am very new to programming so please be specific. (#include
statements, etc.)
Thank you
>
>
Closed Thread