i am developing a project in vb6.0 and i want to open a child form in mdi form with function keys and want to close child form with escape key.Plz reply me with source code

Recommended Answers

All 4 Replies

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
Unload Me
End If
End Sub

First make sure to set child forms KeyPreview property to TRUE. This will ensure that your Esc key event will be captured by the form.

In the MDI form write something like:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim oFrm As *child_form_name, for exmple Form2*

If KeyCode = vbKeyFx (where x is a numer from 1 to 12) then 
    Set oFrm = New Form2 '...(actualy *child_form_name*)...
    oFrm.Show vbModal,Me

    '...If you unload the form from within it self then you don't need this line, but if you just Hide it then you must:

    Unload oFrm

    '...Finaly release the object...

    Set oFrm=Nothing

End If

End Sub

The Escape key press code stated above is correct except that it is general better idea to unload the form in the calling process.

You can also use vbKeyEscape constant instead of 27.

.hi!! Good day.

language: Visual Basic 6.0

I want to know the code for the functions keys as a command for my program (Student Details)..F1 as Add, F2 as Edit, F3 as Save, F4 as Cancel, Del for Delete and Esc as Exit..and a code for running my program on other PC.
Thanks a lot!! :)

Well, I'm not sure if I understud your question correctly.

Function keys are not different then other keys. You can pretty much use the same aproach as above mentioned except that you test against vbKeyF1,vbKeyF2... vbKeyDelete and vbKeyEscape.

If you organize your interface in a way that is allows menus too then you can easly attach these keys to menus.

As for running your program on other PC you must use COM+ (formerly DCOM). It is a fairly complex technology you can start your study on Microsoft COM+ MSDN.

Basically it is invoked with the command CreateObject ("object-name","remote-pc-name-or-IP-address). But you have to work alot before you get to this command :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.