VB6 Tutorial 04: First Program

Posted On 2018-03-21 by VB6Boy
Keywords: visual,basic,vb6,visualbasic,tutorial,basic,beginner,first,program
Tags: VB6 Tutorials Windows
Views: 67

Title Uploaded Size
vb60401_FirstProgram.zip 3/25/2018 8:28:09 AM 1,177


Looking for the more of the VB6 Tutorial? Here is the tutorial index.

This lesson will walk you through building your first Visual Basic 6 (VB6) program.

  1. Start a .exe project.
  2. Place a CommandButton on the form from ToolBox.
    New Form
  3. Click on Form and edit the caption property of the form. Write "My First VB Program".
  4. Edit the caption property of the CommandButton from the Properties Window. Write "Print".
    Control Properties
  5. Double-Click the CommandButton to open the Code Window. Write the following code.
    code window

    QuickHint:

    Write code between the two lines 'Private Sub Command1_Click()' and 'End Sub'. These two lines will be created automatically after double-clicking the CommandButton.

Explanation

'Sub' means Sub-Routine or Sub-Procedure or Function. 'Command1_Click()' is the sub-procedure name where 'Command1' is a control and 'Click' is an event. '( )' this sign indicates that 'Command1_Click()' is a function. 'Private' is the Scope. You will learn about scope in the next chapters. 'Print' is a Method.

You could also write Form1.print, where Form1 is an object and print is its method. 'End Sub' indicates the end of the sub-procedure. You will later learn about sub-procedures.

Now you are done !

Press F5 to run the program or click the start icon button from the toolbar. The code will be executed and the string "Welcome to www.fortypoundhead.com" will be displayed on the form as shown in the picture below.

program running

Writing comments

Comments are the lines of text that are not executed but used for the advantage of the programmers. Comments are written so that the other programmers can easily understand your program and you can better understand the code in case that it becomes complex or large. When you write comments, it becomes easy to maintain the code of your application. Commenting is a part of Documentation and it is a good practice to write comments.

How to write comments ?

Comments are written using the apostrophe ( ' ). That means if you write anything after apostrophe that becomes your comment and text color of the comments becomes green. See the picture below.

writing comments

Looking for the more of the VB6 Tutorial? Here is the tutorial index.


About the Author

VB6Boy has posted a total of 71 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:23.20.165.182

Before you can post, you need to prove you are human. If you log in, this test goes away.




Code Links