Visual Basic Programming Tutorial 1

11
Intro Before u start using vb6 or 8 u need to know a few fundamentals of its lay out, page 1 will get u familiar with what u will need to know at the beginning in order to do the tutorials, the tutorials will be in vb6 at first from here we will progress to vb8, dotnet,java and asp.net one step at a time though. I want to make it clear I do not claim to be a pro programmer or anything like that I am self taught and the reason for these tutorials is because when I was first starting out I wished I had tutorials to follow to make the learning easier so hopefully these help someone or u know of someone who wants to get into programming but doesn’t know were to start. I Want to warn you in the beginning you going to be saying . . . huh,erm ,ahh, oooo, wtf??! Many times but just keep on reading try to understand and in the end you will persevere, there will be more than one tutorial in this lesson because honestly not many people manage through the first tutorial of anything there first time so if you u get stuck move on to the 2 nd and 3 rd get familiar with the interface and the rest will come to you naturally, my girlfriend said something to me which makes so much sense but I never realized it until she pointed it out she said programming is easier than language its self and she couldn’t be more right. Programming is basic and simple hopefully as time passes u will realize this yourself, Lets get started! Application (Project) is made up of: Forms - Windows that you create for user interface Controls - Graphical features drawn on forms to allow user interaction (text boxes, labels, scroll bars, command buttons, etc.) (Forms and Controls are objects.) Properties - Every characteristic of a form or control is specified by a property. Example properties include names, captions, size, color, position, and contents. Visual Basic applies default properties. You can change properties at design time or run time. Methods - Built-in procedure that can be invoked to impart some action to a particular object. Event Procedures - Code related to some object. This is the code that is executed when a certain event occurs. General Procedures – Code not related to objects. This code must be invoked by the application. Modules - Collection of general procedures, variable declarations, and constant definitions used by application.

description

I encourage you to download this booklet edit it see if you can improve it but more importantly share it with you family and friends!Go to http://www.fightingforfreedom.co.za for free video tutorials available for download . . . Coming Soon!!!!!!!!!!!If you have any other questions on how and what to do with Visual Basic all you have to do is message me with a request and il see if i can help you:P

Transcript of Visual Basic Programming Tutorial 1

Page 1: Visual Basic Programming Tutorial 1

Intro

Before u start using vb6 or 8 u need to know a few fundamentals of its lay out, page 1

will get u familiar with what u will need to know at the beginning in order to do the

tutorials, the tutorials will be in vb6 at first from here we will progress to vb8, dotnet,java

and asp.net one step at a time though. I want to make it clear I do not claim to be a pro

programmer or anything like that I am self taught and the reason for these tutorials is

because when I was first starting out I wished I had tutorials to follow to make the

learning easier so hopefully these help someone or u know of someone who wants to get

into programming but doesn’t know were to start.

I Want to warn you in the beginning you going to be saying . . . huh,erm ,ahh, oooo,

wtf??! Many times but just keep on reading try to understand and in the end you will

persevere, there will be more than one tutorial in this lesson because honestly not many

people manage through the first tutorial of anything there first time so if you u get stuck

move on to the 2nd

and 3rd get familiar with the interface and the rest will come to you

naturally, my girlfriend said something to me which makes so much sense but I never

realized it until she pointed it out she said programming is easier than language its self

and she couldn’t be more right. Programming is basic and simple hopefully as time

passes u will realize this yourself,

Lets get started!

• Application (Project) is made up of:

• Forms - Windows that you create for user interface

• Controls - Graphical features drawn on forms to allow user interaction

(text boxes, labels, scroll bars, command buttons, etc.) (Forms and

Controls are objects.)

• Properties - Every characteristic of a form or control is specified by a

property. Example properties include names, captions, size, color,

position, and contents. Visual Basic applies default properties. You

can change properties at design time or run time.

• Methods - Built-in procedure that can be invoked to impart some action

to a particular object.

• Event Procedures - Code related to some object. This is the code that

is executed when a certain event occurs.

• General Procedures – Code

not related to objects. This code must be

invoked by the application.

• Modules - Collection of general procedures, variable declarations, and

constant definitions used by application.

Page 2: Visual Basic Programming Tutorial 1

• Steps in Developing Application

There are three primary steps involved in building a Visual Basic application:

Draw the user interface Assign properties to controls

Attach code to controls

• Drawing the User Interface and Setting Properties

Visual Basic operates in three modes.

1. Design mode - used to build application

2. Run mode - used to run the application

3. Break mode - application halted and debugger is available

• We focus here on the design mode.

Six windows appear when you start Visual Basic.

The Main Window consists of the title bar, menu bar, and toolbar.

The title bar indicates the project name, the current Visual Basic

operating mode, and the current form. The menu bar has dropdown

menus from which you control the operation of the Visual

Basic environment. The toolbar has buttons that provide shortcuts

to some of the menu options. The main window also shows the

location of the current form relative to the upper left corner of the

screen and the width and length of the current form.

Page 3: Visual Basic Programming Tutorial 1

LAYOUT

Lesson 1: Menu Editor

Page 4: Visual Basic Programming Tutorial 1

(Your form this is the graphical foundation of your program)

Click on your form to select it then on the tool bar about click the menu editor icon

you will see this screen:

I wont get into to much detail here just the necessity’s in the Caption Tab type in About

and below that in the name Tab type in nmeAbout. Now the best why for me to explain

what we have done is that the name you wrote in the caption will appear on the form this

is for the user of the application to navigate around the program for example if he wanted

to know about the program he is using e.g. the version he or she would click there about

button. There still isn’t any coding though this will come shortly once the tabs have been

completed click the next button and type in the following:

Caption: Donate

Name: nmeDonate

Next Button

Page 5: Visual Basic Programming Tutorial 1

Caption: Register

Name: nmeRegister

Next Button

Caption: Contact

Name: nmeContact

Next Button

Caption: Help

Name: nmeHelp

Next Button

Then finally click ok and your form should look like this:

Now for the fun part the Coding double click on the about on your form and you will see

the following:

Notice the name of the button being nmeAbout we name them like this so we don’t get

confused the all the labels or buttons in the application. Now between Private Sub and

End Sub type the following code: msgbox “MP3 player v1.0 beta” then close the coding

box and on the top tool bar click the start icon this will test your application do this

and then click on the About button and it should give u the following message:

Page 6: Visual Basic Programming Tutorial 1

And that’s it all you would do know is full in the missing code for

Donate,Register,Contact And Help. Once again here are some examples.

Code stays the same:

Msgbox “Thanku for Donating”

Msgbox “Thanku for Registering”

Msgbox “ Contact me at [email protected]

Msgbox “ For help E-mail me at [email protected]

And of cause u can type in what ever you want inbetween the inverted commas.

Lesson 2: Components

the next lesson will make use of components in this case the windows media player

component, right click on your toolbox(the toolbar on your left) click on components add

look for the windows media player:

Page 7: Visual Basic Programming Tutorial 1

Select it and click apply u will see it is now available in your toolbox:

Click it and drag it into your form and position it like so:

Next we will add 1 command button

Page 8: Visual Basic Programming Tutorial 1

1 textbox

1 label

All can be found in your toolbox

First place the command button it will call its self by default command1 in the properties

box scroll until you find the captions field :

Rename it to Play adds the textbox and clear the text field in the properties box

Then add a label and in its caption field type in URL

Your form should now look like this:

It is up to you to design the layout of your program this is very important u want its as

user friendly as possible, this is how mine is designed it doesn’t have to look the same

just as long as you know were to put the button, textbox and label your can resize them as

you like.

Now the coding this is very simple

Page 9: Visual Basic Programming Tutorial 1

Double click the play button and once again between the Private Sub and End Sub type

the following code:

This code is pretty self explanatory don’t u think?? You don’t have to type in the green

text as that is the explanation of the code we just used

Lesson 3: Winsock

The next lesson is the easiest of them all providing you managed to do the 2 pervious

exercises, we need to once again add a component this one is the Microsoft winsock

control

Now add a button and a textbox next to it rename the caption of the button to IP Address

and clear the textbox and your form should look like this :

Page 10: Visual Basic Programming Tutorial 1

(don’t forget to add the component to ur form)

Now double click the button and add your code :

And that’s it try out these 3 tutorials and try familiarize yourself with vb6 on even add

the first lesson to the last 2 once your are don with each lesson make your you save your

projects if want to compile them to exe’s go file>make an.exe

Lesson 4

Once again a nice and easy one the will put what u have learn so far together, add a text

box to your form and resize It like mine then double click anywhere on the form not the

textbox and you should see this:

Page 11: Visual Basic Programming Tutorial 1

Notice the code Text1.text = now is in the form load section and not the textbox area

This basically means when your run your application the form will load the code and you

will have the following :

You by now should have learn how to make 3 working applications and how to add a

menu editor to each as a practice exercise why don’t u try adding the timer to each of

those applications if your unsuccessful don’t worry ill show you how to do that in the

next tutorial and more.