• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1081
  • Last Modified:

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
0
RAMCIT
Asked:
RAMCIT
  • 6
  • 6
  • 4
  • +1
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
RAMCITAuthor Commented:
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?
0
 
kurtnelleCommented:
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?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
RAMCITAuthor Commented:
Yes, except it says that "Handles clause requires a WithEvents variable.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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

0
 
RAMCITAuthor Commented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Delete this line:

    Dim KeyCode As Integer

and change this line:

    Select Case KeyCode

to:

    Select Case e.KeyCode

~IM
0
 
softplusCommented:
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.)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Is there an echo in here?

Is there an echo in here?

;)
0
 
RAMCITAuthor Commented:
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.
0
 
softplusCommented:
"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
0
 
softplusCommented:
Hmm, how about this in the Form-Initialisation:

cboDefaultRemarks.Key(vbKeyF4) = 0

?
0
 
softplusCommented:
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
0
 
softplusCommented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
softplusCommented:
ah, the easy way :). This is fun, I just need more hours in the day!

John
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 6
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now