VB6.0 beginners' ten programming tips

xiaoxiao2021-03-06  88

1. If a line is too long, can you change it?

The VB program code is allowed to write, as long as the last character of each wrap is added to the wrap character "_". E.g:

Sub picmove () frm.picture2.left = frm.picture1.left _ 'plus wrapfi frm.picture1.width End Sub

2, how to empty the existing picture when design?

Use the Picture property in the property window in the Properties window, press Del to clear the picture.

3, how do Visual Basic notes a longer program code?

The symbol of the VB comment program code is "'", as long as "'" is added in front of a single line, you can comment. However, if the program code is long, a line of comments feel unbearable. The VB itself provides this feature. Under the "Toolbar" of the main menu "View" option, select the Edit, VB interface, a row of tool buttons, two buttons after the hand-shaped button are used for "Settings Comment Block "And" Release Notes Block ".

4, how to achieve the function of a small prompt window in one movement of the mouse?

Each control in VB has a tooltiptext property, just plus a line of programs.

For example: label1.tooltiptext = "This is a prompt!".

5, how to get the current software running disk directory and command line parameters? There is a system object called app in VB. App.path is the current software running directory. The command line parameter is stored in a system variable, called Command. The program statement is as follows:

Label1.caption = app.path label2.caption = Command $

6, I want to change the shape displayed in the mouse, how to do it?

The system controls provided by VB generally have MousePointer and Mouseicon properties. We can look for our favorite * .ico, *. Cur files, the procedures implemented are as follows:

Screen.mousepointer = 99 'User Mouse Type Screen.Mouseicon = LoadPicture ("c: /abc/1.ico")' Read the mouse icon file

7, how to set the program's error exit?

The ON ERROR statement is used for the error outlet processing of the program. There are two types of general treatment methods:

1) I have encountered an error to go to a row program to execute, and ON Error Goto Someline.

E.g:

ON Error Goto Err_Line ... label1.caption = "correctly" Err_Line: ... Label1.caption = "Error!"

2) Ignore the current error after encounter an error, continue to execute, on Error ResMe next.

E.g:

On Error ResMe next ... label1.caption = "No matter what you want" ...

8. How to get the keyboard input and judgment the ASCII value of the key?

Set the keypreview property of the form to TRUE, then write program code in the Form_KeyPress event as follows:

Private Sub Form_KeyPress (Keyascii As Integer) Me.caption = Str (Keyascii) 'gets the keyboard input character ... End Sub

9, I hope that the form is running on the center of the screen, how to achieve it?

The VB system object Screen records the height and width of the current display mode, which can utilize this value to set the location of the form.

Sub Centerform (frM as form) 'defined process frm.move (screen.width - frm.width) / 2, (Screen.Height - frm.height) / 2 end sub private sub form_load () centerform me' calling process End Sub10 Many software have the mouse in the text box TextBox, and how is the functionality of all text?

PRIVATE SUB TEXT1_GOTFOCUS () text1.selstart = 0 text1.sellength = len (text1.text) 'Procedure calling End Sub

转载请注明原文地址:https://www.9cbs.com/read-122246.html

New Post(0)