List Box

>> Dec 10, 2010

Open new project, add two list box controls to form1 and draw two list box as you wish on form1.

Double click on the form to open the code window. Add the following code to the load event:

Private sub form_load()

List1.additem "RAM"
List1.additem "HARDDISK"
List1.additem "CD"
List1.additem "MOUSE"
List1.additem "KEYBOARD"

END SUB

-> now, Add the below code to the Double click event of list1:

Private sub list1_dblclick()

List2.Additem list1.text
list1.removeitem list1.listindex

End Sub

-> now, Add the below code to the Double click event of list2:

Private sub list2_dblclick()

List1.additem List2.Text
List2.RemoveItem List2.ListIndex

End Sub

NOw, Run The form and test result

Read more...

How to connect with DB

>> Dec 5, 2010

How to connect with DB(Database)
For beginners, we will take database as access database for understand simple project, how to connect acess database with simple saving method.

Step_1 : make a simple access file with name XYZ, and make table name Cname, there we will make only two field. first field name we choose C_Name and second for address. save in D:/ drive, its not important you save the file in D:/ drive, important is you have to give path of saved database in code.

save access file and come on visual basic plateform, now open new project select two text box and draw with proper label as we learned before. now we will enter the code for connection


See right side picture there is used controls are lables, textboxes and command buttons. draw label name to navigate fields, make textboxes blank.
Label captions, textboxes modify by control properties, which is disply on right side of program windows, as we see in let topic , right side three windows will be opened in defult setting,
first will be project explorer, in project explorer you can see and add-remove form, project, module, class module etc... it is naviagator of project, simple image its like a windows explorer which you can see all windows sitmap.
second windows will be desply in defult setting is control properties, you can see the picture, there is i made some colourfull label through control properties.
third will be form layout window, this tool is very usefull for child form setting, mostly usefull for alignment of child form, we will discuss on this tool later.
Now, lets see which coding will be used for this project.
first declare connection, but remember that delcaration only on top of the coding windows, you can identify your declared code is on top of the coding windwos through to two combo boxes in first should be appear (general) and second combo should for declarations),
now type as below:
Dim CN as new connection
Dim RS as new recordset
-----------------------------------------------------------------------------------
Now type code for command windows, just double click on command button, code windwos will be disply against you just type as below, but remember that might when you click on command button, if your command button name is not changed you can see the code like
private sub commandbutton1_click()
end sub
-- but here i modified name as cmdclick OK! now type the code between both lines as below.
Private Sub cmdclick_Click()
Set CN = New ADODB.Connection
Set RS = New Recordset

CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\xyz.mdb;"

If TextBox1.Text = "" Then
MsgBox "Please Enter Customer's Name.", vbInformation, "INFORMATION"
TextBox1.SetFocus
ElseIf TextBox2.Text = "" Then

MsgBox "Please Enter Customer's Address.", vbInformation, "INFORMATION"
TextBox2.SetFocus
End If

RS.Open "select * from Cname", CN, adOpenKeyset, adLockPessimistic

If RS.EOF = False Then
RS.AddNew
RS(1).Value = TextBox1.Value
RS(2).Value = TextBox2.Value

RS.Update
RS.Close
End If

CN.Close

TextBox1.SetFocus
TextBox1.Text = ""
TextBox2.Text = ""

End Sub

------------------------------------
Now, run project and enter data, result you will get in acess files, your entered data you can see and modify in acess file.

Read more...

Massage box

>> Nov 30, 2010



You can see picture in right side, how to disply massage box in project, here you can see below simple code you have to enter in source code windows as under:




Private Sub Command1_Click()

MsgBox "Hey! you can see massage box", vbInformation,"Massage"

End Sub




Now, run the project and click on command button you can see the massage on screen



Type of massage


  • VbAbortRetryIgnore
  • VBapplicationmodule
  • VbCritical
  • VBdefaultbutton
  • VbExclamation
  • vbInformation
  • vbMsgBoxHelpButton
  • vbMsgBoxRight
  • vbMsgBoxRtlReading
  • vbMsgBoxSetForeground
  • vbOKCancel
  • vbOKOnly
  • vbQuestion
  • vbRetryCancel
  • vbSystemModal
  • vbYesNo
  • vbYesNoCancel

To better understand download sample source code CLICK HERE

Read more...

File Extension

It is very important to understand file extension, most beginners having a truble for file extension, so here i am giving some extention of visual basic concern files. Each file type has 3 letter extension designated as under:

  • Visual basic project - .vbp
  • Form - .frm
  • Module - .mod
  • Class - .cls
  • Visual basic group - .vbg
  • Desiner file - .dsr
  • Basic file - .bsr
  • Executable file - .Exe ( Application)
  • User defined control - .ctl
  • Resource file - .res

Read more...

Calculation

>> Nov 28, 2010


Let's start little project, how to calculate of two text box, put the two text box on the form and also insert one label under two text boxes, command button too.
right click on command button, now you can see properties of command button,click on last option"properties", now you can see control properies of command button, might it can be open as defult when you open first time visual basic. Go to control properies and type in forth option "caption"- "calculate" now you can see there command button caption will be cange.
you can see top of right side picture, you can set like that.
Now, you can change some text box's value by control properties, click on text box1 and go to text, type there 10 or any numner value and same follow in text box2. make any name of label, here i will given name of label is "total" and against text i put value = "0" , you can also give any instruction on top of form like " Please input numberic value in text boxes", change the colour and font bold for atraction.
Now, double click on command button, now you can see like this
Private Sub Command1_Click()

End Sub

- Enter the code

Private Sub Command1_Click()
Total = Val(Text1.Text) + Val(Text2.Text)

End Sub

Mark there TOTAL is label name means - label(total) caption will be (equal to) value text box 1 plus text box 2
Now, RUN the program -- You can run button in toolbar as like play button like ">"this.
enter numbric values in both textbox an click on calcuate button, you can see label valued will be automatically change there.
Cang! you almost done!

Read more...

My first Visual Basic Project

>> Nov 26, 2010

VISUAL BASIC


is a high level programming language which evolved from the earlier DOS version called BASIC. BASIC means Beginners' All-purpose Symbolic Instruction Code. It is a very easy programming language to learn. The code look a lot like English Language. Different software companies produced different versions of BASIC, such as Microsoft QBASIC, QUICKBASIC, GWBASIC ,IBM BASICA and so on. However, people prefer to use Microsoft Visual Basic today, as it is a well developed programming language and supporting resources are available everywhere. Now, there are many versions of VB exist in the market, the most popular one and still widely used by many VB programmers is none other than Visual Basic 6. We also have VB.net, VB2005, VB2008 and the latest VB2010. Both Vb2008 and VB2010 are fully object oriented programming (OOP) language

For your referance download simple project = DOWNLOAD


Read more...