Link to home
Start Free TrialLog in
Avatar of RAMCIT
RAMCIT

asked on

Assigning F Keys. It says vbKeyF1 is Not Declared in Public Class

Below is the code I'm using.  It tells me that vbKeyF1x is Not Declared.  I'm working within a Public Class for VB.NET.  Why must I declare it and what do I declare it as?  Is there another way?

Private Sub cboDefaultRemarks_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
        Dim CurrentComments As String

        CurrentComments = txtDispRemarks.Text()

        Dim F1 As String
        Dim F2 As String
        Dim F3 As String
        Dim F4 As String
        Dim F5 As String
        Dim F6 As String
        Dim F7 As String
        Dim F8 As String
        Dim F9 As String
        Dim F10 As String
        Dim F11 As String
        Dim F12 As String

        F1 = "Advised of $50.00 and be with vehicle"
        F2 = "Advised of $75.00 and be with vehicle"
        F3 = "Advised of $100.00 and be with vehicle"
        F4 = "Advised covered in full and be with vehicle"
        F5 = "Advised covered to NQR and be with vehicle"
        F6 = "Advised covered for 40 mile tie back and be with vehicle"
        F7 = "Advised covered for 2 gallons of gas and be with vehicle"
        F8 = "Advised covered for 3 gallons of gas and be with vehicle"
        F9 = "This is a cash call-customer pays for the service"
        F10 = ""
        F11 = ""
        F12 = ""

        Select Case KeyCode
            Case vbKeyF1 : txtDispRemarks.Text = CurrentComments & vbCrLf & F1
            Case vbKeyF2 : txtDispRemarks.Text = CurrentComments & vbCrLf & F2
            Case vbKeyF3 : txtDispRemarks.Text = CurrentComments & vbCrLf & F3
            Case vbKeyF4 : txtDispRemarks.Text = CurrentComments & vbCrLf & F4
            Case vbKeyF5 : txtDispRemarks.Text = CurrentComments & vbCrLf & F5
            Case vbKeyF6 : txtDispRemarks.Text = CurrentComments & vbCrLf & F6
            Case vbKeyF7 : txtDispRemarks.Text = CurrentComments & vbCrLf & F7
            Case vbKeyF8 : txtDispRemarks.Text = CurrentComments & vbCrLf & F8
            Case vbKeyF9 : txtDispRemarks.Text = CurrentComments & vbCrLf & F9
            Case vbKeyF10 : txtDispRemarks.Text = CurrentComments & vbCrLf & F10
            Case vbKeyF11 : txtDispRemarks.Text = CurrentComments & vbCrLf & F11
            Case vbKeyF12 : txtDispRemarks.Text = CurrentComments & vbCrLf & F12
        End Select
    End Sub
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

vbKeyF1 is a VB6 constant.  In VB.Net use Keys.XX instead:

        Select Case KeyCode
            Case Keys.F1 : txtDispRemarks.Text = CurrentComments & vbCrLf & F1
            Case Keys.F2 : txtDispRemarks.Text = CurrentComments & vbCrLf & F2
            Case Keys.F3 : txtDispRemarks.Text = CurrentComments & vbCrLf & F3
            Case Keys.F4 : txtDispRemarks.Text = CurrentComments & vbCrLf & F4
            Case Keys.F5 : txtDispRemarks.Text = CurrentComments & vbCrLf & F5
            Case Keys.F6 : txtDispRemarks.Text = CurrentComments & vbCrLf & F6
            Case Keys.F7 : txtDispRemarks.Text = CurrentComments & vbCrLf & F7
            Case Keys.F8 : txtDispRemarks.Text = CurrentComments & vbCrLf & F8
            Case Keys.F9 : txtDispRemarks.Text = CurrentComments & vbCrLf & F9
            Case Keys.F10 : txtDispRemarks.Text = CurrentComments & vbCrLf & F10
            Case Keys.F11 : txtDispRemarks.Text = CurrentComments & vbCrLf & F11
            Case Keys.F12 : txtDispRemarks.Text = CurrentComments & vbCrLf & F12
        End Select
Avatar of RAMCIT
RAMCIT

ASKER

Thanks.  I'm trying to use this on a combobox where if the user hits F1 it will take that sting and place it into the textbox.  But I think I'm using the wrong event type.  Is it supposed to cboDispRemarks_KeyDown or something else?
VB.NET uses event handling.

Private Sub Handle_cboDispRemarks_Key_down_events(ByVal sender As Object, ByVal e As KeyEventArgs) Handles cboDispRemarks.KeyDown

End Sub

is this what you wanted?
Avatar of RAMCIT

ASKER

Yes, except it says that "Handles clause requires a WithEvents variable.
How did you get cboDefaultRemarks onto your form then?  If you did not add it via the IDE to your form then you need to use AddHandler() in your Load() event:

    AddHandler cboDefaultRemarks.KeyDown, AddressOf Me.cboDefaultRemarks_KeyDown

Avatar of RAMCIT

ASKER

Okay, I figured out why I was getting that error.  It's because I copied your code in above and you confused txtDispRemarks with cboDefaultRemarks.  Below is the code I now have and it doesn't error.  BUT, it doesn't work.  When I click on that combobox, and hit one of the F-Keys, nothing happens.

Any advice?  Thanks for your help.



Private Sub Handle_cboDefaultRemarks_Key_down_events(ByVal sender As Object, ByVal e As KeyEventArgs) Handles cboDefaultRemarks.KeyDown
        Dim CurrentComments As String
        Dim KeyCode As Integer

        CurrentComments = txtDispRemarks.Text()

        Dim F1 As String
        Dim F2 As String
        Dim F3 As String
        Dim F4 As String
        Dim F5 As String
        Dim F6 As String
        Dim F7 As String
        Dim F8 As String
        Dim F9 As String
        Dim F10 As String
        Dim F11 As String
        Dim F12 As String

        F1 = "Advised of $50.00 and be with vehicle"
        F2 = "Advised of $75.00 and be with vehicle"
        F3 = "Advised of $100.00 and be with vehicle"
        F4 = "Advised covered in full and be with vehicle"
        F5 = "Advised covered to NQR and be with vehicle"
        F6 = "Advised covered for 40 mile tie back and be with vehicle"
        F7 = "Advised covered for 2 gallons of gas and be with vehicle"
        F8 = "Advised covered for 3 gallons of gas and be with vehicle"
        F9 = "This is a cash call-customer pays for the service"
        F10 = ""
        F11 = ""
        F12 = ""

        Select Case KeyCode
            Case Keys.F1 : txtDispRemarks.Text = CurrentComments & vbCrLf & F1
            Case Keys.F2 : txtDispRemarks.Text = CurrentComments & vbCrLf & F2
            Case Keys.F3 : txtDispRemarks.Text = CurrentComments & vbCrLf & F3
            Case Keys.F4 : txtDispRemarks.Text = CurrentComments & vbCrLf & F4
            Case Keys.F5 : txtDispRemarks.Text = CurrentComments & vbCrLf & F5
            Case Keys.F6 : txtDispRemarks.Text = CurrentComments & vbCrLf & F6
            Case Keys.F7 : txtDispRemarks.Text = CurrentComments & vbCrLf & F7
            Case Keys.F8 : txtDispRemarks.Text = CurrentComments & vbCrLf & F8
            Case Keys.F9 : txtDispRemarks.Text = CurrentComments & vbCrLf & F9
            Case Keys.F10 : txtDispRemarks.Text = CurrentComments & vbCrLf & F10
            Case Keys.F11 : txtDispRemarks.Text = CurrentComments & vbCrLf & F11
            Case Keys.F12 : txtDispRemarks.Text = CurrentComments & vbCrLf & F12
        End Select
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There's something simple missing / wrong here:
Remove " Dim KeyCode As Integer"
Replace "Select Case Keycode" with
"Select Case e.Keycode" <---

The problem is that you're accessing "KeyCode" without initialising it beforehand. You really don't need this variable, instead just access the event data itself (e as KeyEventArgs).

Cheers
John

PS - also beware that the F-Keys have functions attached to them that might still be fired (i.e. F1=Help, etc.)
Is there an echo in here?

Is there an echo in here?

;)
Avatar of RAMCIT

ASKER

Idle Mind you are a genius.  Thank you so much.  I'll give you all the points.  Is there a way to stop F4 from dropping down the combobox.  It must be programmed automatically to extend the drop down box.
"Great minds think alike" :) (oops, I'm new here, hope I'm not intruding :), sorry for taking so long to type, looks like we were thinking along the same lines.. wow, speed matters here.)

I'm not sure if you can supress the F4 to extend the dropdown, at least not so easy. If this is important, you might consider coding your own dropdown-class... "e" is now readonly (i.e. in VB6 you could have removed the keycode from being processed after your event).

You can also use modifiers which should not interact with windows-functions (i.e. CTRL + F1).

Maybe Idle_Mind has the right clue :)

John
Hmm, how about this in the Form-Initialisation:

cboDefaultRemarks.Key(vbKeyF4) = 0

?
Oops, I take it all back :o - That's for the eXontrol eXComboBox (a 3rd Party control to replace the combo box), you might want to take a look though: http://www.exontrol.com/excombobox.jsp - I use it alot...

John
If you want to keep F4 from opening the combobox, you need to inherit the control and override the WndProc method there to handle the message.... not as simple as a workaround with a 3rd party control :)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasswndproctopic.asp
To disable the dropdown on F4, change this line:

               Case Keys.F4 : txtDispRemarks.Text = CurrentComments & vbCrLf & F4

to:

                Case Keys.F4
                    txtDispRemarks.Text = CurrentComments & vbCrLf & F4
                    e.Handled = True

~IM
softplus,

Please don't feel as if you were "intruding".  There has been many a time when I was beaten out by a faster typer or a shorter submission.  You gave good info and there is nothing wrong with that.  =)

Inheriting the control and subclassing it would work as well but "e.Handled = True" works in this case.

~IM
ah, the easy way :). This is fun, I just need more hours in the day!

John