You are on page 1of 3

Visual Basic 6 Tutorial - made by Spiro_dt Volume.1 Quote 1.Intro 2.Starting with simple hello world 3.

Declaring variables 4.Combinations with Math 5.Loops 6.If ,else 7.Making a simple program for Shutdown pc using shell command(implement cmd commands) 8.Timer 9.Last words 10.About 1.Hello People this is my first tutorial about programming language. I 've choose this language cause it is very easy and very useful ,in this programming language you can make anything you can imagine... Someone will say it is a waste of time to learn vb but they are totally wrong in comparative with more high - level languages like c/ c++ and some other languages vb is easy to learn and you don't need to waste many time to learn it just to make something small and useful but enough talking lets start 2.Starting with simple hello world (litle bit more advanced) First you need to create one button on the form then double click on the button and you will be automatically redirected to the button code Private Sub Command1_Click() End Sub The here you will need to write the next code MsgBox "Hello World", vbInformation, "My first Hello world Program" please don't copy paste write it cause when you write it you will learn it now the code should look like this Code: Private Sub Command1_Click() MsgBox "Hello World", vbInformation, "My first Hello world Program" End Sub "Hello World" - is the text in the msgbox vbInformation - is the Picture in the message box "My first Hello world Program" - is the title of the message box 3.Declaring Variables What is Variable ? Varibale is information in programm that changes or can be changed ... Tips of Variables ( I will mention only the most recently use tips) String - this is text variable Integer - This is number varible Boolean - this is True or False varible example: We will declare 3 variables one string ,Integer ,and bolean Code: Dim var1 as string Dim var2 as integer Dim Var3 as boolean var1 = "spiro_dt" var2 = 18 var3 = true 4.Combinations With Math In Visual Basic you can do many things with math here are some example but firs you need to remember that every time you use math your variables must be declared in numeric type (integer,longinteger....) Code: Private sub spiro_math() Dim num1,num2,num3,rez as integer rez = num1+(num3*num1-)/num3*num2 msgbox(rez) end sub 5.Loops

Loops are the most useful thing in every programming language they save a lot of time and can be used for anything The best and the easiest loop is For I loop the code look like this Code: For I = 1 to 10 MsgBox("Hello World") Next this code MsgBox("Hello World") will be repeated 10 times this is very useful instead writing 10 times MsgBox("Hello World") you could do it with loop also you can add math in loops and do something like this for example simple counter Code: For I = 1 To 10 MsgBox (I) Next Or Code: For I = 1 to 10 Msgbox(I+10-3) next 6. If ,Else and more logical stuffs This functions are best for comparative between anything variables ,constants, functions results almost anything also boolean comparations here is some example code that will help you to understand how this functions work also I forgot to mention the Inputbox code it is similar to mesage box but this is for input Code: Dim Age As Integer Dim text As String Dim isit As Boolean Age = 18 text = InputBox("Enter the name") isit = True If Age = 18 Then MsgBox ("First thing passed") If text = "spiro" Then MsgBox ("Second thing passed") isit = True MsgBox ("every thing passed") Else isit = False MsgBox ("you have done something wrong") End If End If 7.Making a simple program for ping using shell command(implement cmd commands) Now this command is one of the most power full command in vb6 cauze with this command you can put a batch code in your programs here is an example : make one button on the form and double click on it will automatically redirect you to the code of the button Private Sub Command1_Click() End Sub then you should add this in the empty space between Private Sub Command1_Click() and End Sub Shell("shutdown -r -t 20") - this will shut down your pc for 20 seconds now the code should look like this Code: Private Sub Command1_Click() Shell("shutdown -r -t 20") End Sub you can also add as many and other batch commands in the shell() 8. Timers Timers are also great they help a lot they mostly are used to check something every second,or minute here is one example: First put one button on the form double click and in the code write this Timer1.Enabled = True Timer1.Interval = 100 - this is for the interval of the timer milliseconds so the code for the button should look like this Code: Private Sub Command1_Click() Timer1.Enabled = True Timer1.Interval = 100

End Sub also add one text box to the form and from the general components tab select the textbox and add to the form then also add timer and double click on it and should bring you to code that will look like this Code: Private Sub Timer1_Timer() End Sub now add this code to timer and the timer code should look like this Code: Private Sub Timer1_Timer() If Text1.Text = "spiro" Then MsgBox ("yep the text is spiro") Timer1.Enabled = False End If End Sub that is all about this timer so you can run it.. 9. Last Words Now this was my first tutorial for vb6 but sure isn't my last one I hope you will like it and please tell me if I had some erros in code or just ask anything you didn't understand.. I am glad if I helped you in some way.. 10. About Author : spiro_dt License: open source (anyone can copy it but if you change it please put my credit on)

You might also like