To code the combo box’s KeyPress procedure: Completed cboAllowances_KeyPress procedure

Burke, Brendan J 141 Reputation points
2022-03-22T21:11:46.54+00:00

185803-6-33.jpg

185782-key-press-procedure.jpg

In the second image on lines 146 through 153 that is the whole procedure sub and the If statement starting on line 149 and ending on line 152 is written as it is supposed to be. I just need help getting rid of the errors. I just need the rest of the parameter in the parenthesis on 146 to make the error go away. What is written in figure 6-33 is correct I just need to fix the error. (Visual Basic in Visual Studio 2019 Code.)

Code Below

     Private Sub cboAllowances_KeyPress(Sender As Object, e   
            ' Accept only numbers and the Backspace Key.  
      
            If (e.KeyChar < "0" OrElse e.KeyChar > "9") _  
                AndAlso e.KeyChar <> ControlChars.Back Then  
                e.Handled = True  
            End If  
        End Sub  
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,729 questions
{count} votes

Accepted answer
  1. LesHay 7,126 Reputation points
    2022-03-22T21:37:31.87+00:00

    Hi
    However, it would appear that you are working from some sort of clipped text. There is some parts of the code missing.

    Try this: (note a large part of the line was missing)

        Private Sub cbAllowances_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cbAllowances.KeyPress
    
            ' rest of code here ................
    
        End Sub
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.