Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello, everybody. I have been studying the syntax of VB.NET not for a long time and I'm trying to convert into this new language the most important functions I used to implement in VB6.

 

Can anybody tell me the equivalent of the VB6 "SendKeys" statement under VB.NET? In other words, do you know how to simulate the pressure of the keyboard keys?

 

An example in VB6 could be

 

If KeyAscii = 13 Then SendKeys "{Tab}"

 

Do you know how to "translate" the statement above into VB.NET?

 

Thanks in advance for your help.

Pasquale Esposito

Perugia - Italy

http://www.geocities.com/espositosoftware

Posted

PROBLEM SOLVED, at least partially. I still need to know the equivalent of

 

KeyAscii = 0

 

that, in VB6, allows you to cancel the pressure of a keyboard key.

 

Any suggestions?

 

Hello, everybody. I have been studying the syntax of VB.NET not for a long time and I'm trying to convert into this new language the most important functions I used to implement in VB6.

 

Can anybody tell me the equivalent of the VB6 "SendKeys" statement under VB.NET? In other words, do you know how to simulate the pressure of the keyboard keys?

 

An example in VB6 could be

 

If KeyAscii = 13 Then SendKeys "{Tab}"

 

Do you know how to "translate" the statement above into VB.NET?

 

Thanks in advance for your help.

Pasquale Esposito

Perugia - Italy

http://www.geocities.com/espositosoftware

Posted

Thanks, PlausiblyDamp, you have solved my problem. I just wanted to prevent the users from pressing any keys different from numbers, giving them the possibility of using Backspace to make corrections and the Tab or Enter key to move the focus to another object.

This is the code I have written:

 


Private Sub txtNumbersOnly_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoloNumeri.KeyPress

       'The user can press Enter.
       If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
           e.Handled = False
           MsgBox("You pressed Enter.")
           Exit Sub
       End If

       'The user can press Backspace to make corrections.
       If e.KeyChar = Microsoft.VisualBasic.ChrW(8) Then
           e.Handled = False
           Exit Sub
       End If

       'The user can press Tab.
       If e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
           e.Handled = False
           Exit Sub
       End If

       'The user is not allowed to type in letters.
       If e.KeyChar <> "1" And e.KeyChar <> "2" And e.KeyChar <> "3" And e.KeyChar <> "4" And e.KeyChar <> "5" And e.KeyChar <> "6" And e.KeyChar <> "7" And e.KeyChar <> "8" And e.KeyChar <> "9" And e.KeyChar <> "0" Then
           e.Handled = True
           MessageBox.Show("Please use only numbers.", "Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
           Exit Sub
       End If

   End Sub

 

My only doubt is this: does the statement Microsoft.VisualBasic.ChrW(8) etc. refer to a DLL that could not be supported by implementations of the .NET platform for different operating systems? (I'm thinking about the Mono Project)

 

Is there any other statement I could use instead of Microsoft.VisualBasic.ChrW(8) to refer to the Enter key, Backspace and Tab?

 

TIA

Pasquale Esposito

Perugia - Italy

http://www.geocities.com/espositosoftware

Posted

I use Select Case in KeyPresses myself, looks better and easier to understand. Btw, Chr() is the function I use for getting Chars, here's what I got:

 

Private Sub txtNumbersOnly_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoloNumeri.KeyPress

   Select Case e.KeyChar

       'The user can press Enter.
       Case Chr(13)
           e.Handled = False
           MsgBox("You pressed Enter.")
           Exit Sub

       'The user can press Backspace to make corrections.
      Case Chr(8)
           e.Handled = False
           Exit Sub
       End If

       'The user can press Tab.
       Case Chr(9)
           e.Handled = False
           Exit Sub
   End Select

       'The user is not allowed to type in letters.
       If e.KeyChar <> "1" And e.KeyChar <> "2" And e.KeyChar <> "3" And e.KeyChar <> "4" And e.KeyChar <> "5" And e.KeyChar <> "6" And e.KeyChar <> "7" And e.KeyChar <> "8" And e.KeyChar <> "9" And e.KeyChar <> "0" Then
           e.Handled = True
           MessageBox.Show("Please use only numbers.", "Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
           Exit Sub
       End If

   End Sub

Posted

Thanks, Darc. You're right, it looks better and easier than the code I used.

 

I use Select Case in KeyPresses myself, looks better and easier to understand. Btw, Chr() is the function I use for getting Chars, here's what I got:

 

Private Sub txtNumbersOnly_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoloNumeri.KeyPress

   Select Case e.KeyChar

       'The user can press Enter.
       Case Chr(13)
           e.Handled = False
           MsgBox("You pressed Enter.")
           Exit Sub

       'The user can press Backspace to make corrections.
      Case Chr(8)
           e.Handled = False
           Exit Sub
       End If

       'The user can press Tab.
       Case Chr(9)
           e.Handled = False
           Exit Sub
   End Select

       'The user is not allowed to type in letters.
       If e.KeyChar <> "1" And e.KeyChar <> "2" And e.KeyChar <> "3" And e.KeyChar <> "4" And e.KeyChar <> "5" And e.KeyChar <> "6" And e.KeyChar <> "7" And e.KeyChar <> "8" And e.KeyChar <> "9" And e.KeyChar <> "0" Then
           e.Handled = True
           MessageBox.Show("Please use only numbers.", "Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
           Exit Sub
       End If

   End Sub

Pasquale Esposito

Perugia - Italy

http://www.geocities.com/espositosoftware

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...