Vous êtes sur la page 1sur 79

 Kshitij Divakar Student’s Guide to Visual Basic 6.

Visual Basic: Basics


fotqvy csfld%
fotqvy csfld ekbdzkslkW¶V dEiuh }kjk dkWe izksxzkfeax ekWMy ds vk/kkj ij fodflr dh xbZ r`rh; ih<+h
dh bosUV Mªkbou izksxzkfeax ySaxq,st o ,lksfl,sVsM vkbZ- Mh- bZ- gS A ;g foUMkst ds xzkfQdy ;wtj bUVjQsl ij
vk/kkfjr lkW¶Vos;j ;k ,Iyhds’ku fodflr djus ds fy, jSfiM ,Iyhds’ku MoyiesaV ,Uok;jesaV gS ] ftldk
vFkZ vfr’kh?kz ,Iyhds’ku ds fodkl ifjos’k ls gS A blds vfrfjDr fotqvy csfld esa fodflr ,Iyhds’kUl dks
MkVkcsl ls tksM+us ds fy, Mh-,-vks- ] vkj- Mh- vks- rFkk ,- Mh- vks- dh lqfo/kk,sa miyC/k gksrh gS A
fotqvy csfld dh O;qRifr “csfld” uked yksdfiz; izksxzkfeax ySaxq,st ls gh gqbZ gS A fotqvy csfld esa
izksxzkfeax dh lqfo/kkvksa o fo’ks”krkvksa dh lQyrk ds dkj.k blds mi;ksx ,Iyhds’ku izksxzkEl esa Hkh djus ds fy,
fotqvy csfld QkWj ,sIyhds’kUl ftls laf{kIr esa fo-fc-,s- ds uke ls tkuk tkrk gS] dk Hkh fodkl fd;k x;k A
blds vfrfjDr bldh bUVjusV ij dke esa vkus okys osc ist fMtkbfuax esa Hkh mi;ksx ds fy, fo-fc- LdzhIV uke
ls LdzhfIVax ySaxq,st dk Hkh fodkl fd;k x;k A

fotqvy csfld dk mn~Hko o bfrgkl%


fotqvy csfld dk lcls igyk otZu fotqvy csfld 1-0 lu~ 1991 esa ykWap fd;k x;k A ;wtj bUVjQsl
fMtkbu djus ds fy, Mªsx o MªkWi djus dh i)fr ;k vo/kkj.kk dh O;qRifr ,yu dwij o mlds lg;ksxh;ksa }kjk
fodflr izksVksVkbZi QkWeZ tujsVj ls gqbZ ] ftls VªkbZikWM uke fn;k x;k Fkk A ekbdzkslkW¶V dEiuh us ,yu dwij o
mlds lg;ksfx;ksa ls VªkbZikWM dks foUMkst 3-0 ds fy, ,d izksxzkesacy QkWeZ tujsVj ds #i esa fodflr djus ds
fy, dkWUVªsDV fd;k] ftldks dksM use #ch fn;k x;k A
VªkbZikWM esa fdlh Hkh izdkj dh izksxzkfeax ySaxq,st dk lekos’k ugha Fkk vr% ekbdzkslkW¶V us csfld izksxzkfeax
ySaxq,st ls fotqvy csfld fodflr djus ds fy, #ch ds lkFk lekosf’kr djus dk fu’p; fd;k A
#ch ds izksxzkescy bUVjQsl tujsVj us fotqvy csfld dk fotqvy Hkkx miyC/k djk;k ftls ekbdzkslkW¶V ds
v/kwjs NksM+ fn;s x;s vkesxk MkVkcsl flLVe ds fy, fMtkbu fd;s x;s ,EcsMsM csfld bZatu ds lkFk dEckbZu ;k
tksM+ fn;k x;k A

fotqvy csfld ds fodkl pj.k


1. fotqvy csfld 1-0] ebZ 1991 (foUMkst) esa ,VykUVk] T;ksftZvk esa foUMkst+ oYMZ VªsM ‘kks esa ykWap fd;k x;k
2. fotqvy csfld 1-0] flrEcj 1992 (MkWt)
3. fotqvy csfld 2-0] uoEcj 1992-
4. fotqvy csfld 3-0] lu~ 1993 ds xzh”e esa-
5. fotqvy csfld 4-0] dks vxLr 1995-
6. fotqvy csfld 5-0] Qjojh 1997-
7. fotqvy csfld 6-0] lu~ 1998 ds e/; esa-

Page - 1  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

fotqvy csfld dh MsfjosfVo ySaxq,stst%

fotqvy csfld dh lqfo/kkvksa] ‘kfDr;ksa o fo’ks”krkvksa dh yksdzfiz;rk o lQyrk ds dkj.k dqN vU; ySaxq,t s st
dk fodkl fd;k x;k ftudh O;qRifr fotqvy csfld ls gh gksus ds dkj.k fotqvy csfld dh MsfjosfVo ySaxq,stst
dgk tkrk gS A
1- fotqvy csfld QkWj ,Iyhds’kUl %& ekbdzkslkW¶V vkWfQl] vkWVks&dsM] oMZ&ijQsDV 2002 rFkk vkdZ th-
vkbZ-,l- tSlh vU; dbZ ,Iyhds’kUl esa fotqvy csfld QkWj ,sIyhds’kUl dks ‘kkfey fd;k tkrk gS A
;|fi fotqvy csfld QkWj ,Iyhds’kUl o fotqvy csfld 6 ds bEIyhesUV ;k iz;ksx esa ekewyh QdZ t#j
gksrk gS ] ysfdu fQj Hkh eksVs rkSj ij nksukssa leku ySaxq,stst gh gS A rFkk nksuksa ds fy, ,d gh ju&VkbZe
ykbczsjh dk mi;ksx fd;k tkrk gS A
2- fo-fc-fLdzIV %& fo-fc-fLdzIV ,fDVo loZj istst ds fy, fMQkWYV ySaxq,st gS A bldk mi;ksx foUMkst
fLdzfIVax o DykbUV lkbM osc ist fLdzfIVax ds fy, Hkh fd;k tk ldrk gS A gkykafd ;g Hkh fotqvy
csfld 6 ls flUVsDlst ls leku gS ysfdu ;g ,d vyx ySaxq,st gS rFkk bldk ,DthD;w’ku fo-fc-
ju&VkbZe ds ctk; fo-fc- fLdzIV MkWV Mh-,y-,y- }kjk fd;k tkrk gS A
3- fotqvy csfld MkWV usV% ;g fotqvy csfld 6 dh ekbdzkslkW¶V }kjk MsthXusVsM lDlsj gS A rFkk
ekbdzkslkW¶V MkWV usV IysVQkWeZ dk ,d Hkkx gS A fotqvy csfld MkWV usV dks MkWVusV QzseodZ ds }kjk
dEikby o ju fd;k tkrk gS A ;g fotqvy csfld dks cSdokMZ liksVZ ugha djrh gS A vFkkZr~ blesa fodflr
dh xbZ ,Iyhds’kUl dks fotqvys csfld 6 esa ugha pyk;k ;k liksVZ fd;k tkrk gS A

fotqvy csfld ds ,Mh’kUl %&

fotqvy csfld ds ,d ySaxq,st gS] ysfdu blds fuEu rhu ,sMh’kUl esamiyC/k gS &
1- fotqvy csfld & yfuZax ,Mh’ku
2- fotqvy csfld & izksQs’kuy ,Mh’ku
3- fotqvy csfld & ,UVjizkbZt ,Mh’ku

fotqvy csfld & yfuZax,Mh’ku %&

;g fotqvy csfld dk bUVªksMDVjh ,Mh’ku gS ftlesa foUMkst dh ,Iyhds’kUl dks vklkuh ls fodflr fd;k tk
ldrk gS A blesa fdlh Hkh foUMkst vk/kkfjr ,Iyhds’ku dks fodflr djus ds fy, vko’;d lHkh VwYl miYkC/k
gksrs gS A

fotqvy csfld & izksQs’kuy ,Mh’ku %&


;g ,Mh’ku dEI;wVj ;k lkW¶Vos;j izksQs’kuYl ds fy, gS] rFkk ,fDVo ,Dl dUVªksy ds fodkl o bUVjusV
dUVªksYl tSls ,MokULM lqfo/kk,sa ‘kkfey gksrh gS A

Page - 2  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

fotqvy csfld & ,UVjizkbZt ,Mh’ku %&


;g fotqvy csfld dks lcls ,Mokal ,Mh’ku gS] tks fd mu izksxzkelZ ds fy, gS tks Vhe ,Uok;jesaV esa fMfLVªC;wVsM
,Iyhds’kUl dks fodkl djrs gS A blesa izksQs’kuy ,Mh’ku dh lqfo/kkvksa ds lkFk&lkFk fotqvy lkslZ lsQ o
vkWVkses’ku o dEiksuUV eSustj tSls VwYl ‘kkfey gksrs gS A

fotqvy csfld izkstsDV~l %&


fotqvy csfld 6 ,UVjizkbZt ,Mh’ku eas fuEu izdkj ds izkstsDV~l fodflr fd;s tkus dh lqfo/kk miyC/k
gksrh gS A

Standard EXE:
bl izdkj ds izkstsDV esa standard controls dk set gksrk gS rFkk bls Windows dh csfld
,Iyhds’kUl fodflr dh tk ldrh gS ;k fdlh cM+s izkstsDV dk fodkl izkjEHk fd;k tk ldrk gS A

ActiveX EXE:
bl izkstsDV dh lgk;rk ls ActiveX Executable Component fodflr fd;k tk ldrk gS ftls
nwljh ,Iyhds’ku esa Hkh mi;ksx esa ysdj Execute djk;k tk ldrk gS A

ActiveX DLL:
bl izdkj ds izkstsDV esa Dynamic Link Library Files cukbZ tk ldrh gS rFkk buesa Controls o
Class Codes dks j[kk tk ldrk gS ftUgsa nwljs izkstsDV~l ;k ,Iyhds’ku esa Hkh mi;ksx es fy, tk ldrk gS A

ActiveX Control:
bl izkstDV esa izksxzkej Lo;a ds ActiveX Controls fodflr dj ldrk gS ftudk mi;ksx og fdlh
Hkh ,Iyhds’ku ds fodkl esa dj ldrk gS A bldk mi;ksx lkekU;r;k rc fd;k tkrk gS tc fotqvy csfld }kjk
miyC/k Standard Controls fdlh fof’k”V izdkj dh lqfo/kk tks izksxzkej pkgrk gS ] miyC/k ugha djk ikrk A

ActiveX Documents EXE:


bl izkstsDV dk mi;ksx fotqvy csfld esa fdlh bUVjusV vk/kkfjr ,Iyhds’ku ds fy, fd;k tkrk gS A

ActiveX Documents DLL:


bl izkstsDV dk mi;ksx fotqvy csfld esa bl izdkj dh ,Iyhds’kUl dks fodflr djus esa fd;k tkrk gS]
ftUgs bUVjusV ls Install o Execute fd;k tk ldsa A

Page - 3  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

VB Application Wizard:
bl izkstsDV dh lgk;rk ls fdlh Hkh ,Iyhds’ku dk fodkl djus ds fy, mldk Basic Structure
‘kh?kzrk ls cuk;k tk ldrk gS A ysfdu bls Modify djus o Coding djus ds fy, fotqvy csfld dk mPp
Lrjh; Kku gksuk vko’;d gksrk gS A vr% u;s izksxzkelZ dks bldk mi;ksx rc rd ugha djuk pkfg, tc rd fd os
fotqvy csfld ds izksxzkfeax o ,Iyhds’ku MoyiesaV dks Hkyh a izdkj ls ugha le> ysrs gS A

VB Wizard Manager:
bldk mi;ksx izksxzkej }kjk Lo;a dh fotkMZ fMtkbu o fodflr djus esa fd;k tkrk gS A ,d fotkMZ dbZ
foUMkst dh ,d J`a[kyk gksrh gS ftlesa ;wtj ls bUQksesZ’ku ,df=r dh tkrh gS rFkk ;wtj }kjk tc lHkh foUMkst esa
MkVk dk buiqV dj nsrk gS mlds i'pkr~ fotkMZ vkWVksesVsM izkslsflax dj fjtYV tujsV djrh gS A bldk mi;ksx
lkekU;r;k lWk¶Vos;lZ ds bULVkWys’ku esa] ;k fdlh ,Iyhds’ku ds fodkl esa fd;k tk ldrk gS A
Data Project:
bl izdkj dk izkstsDV Database Components dks Tools ;k Controls dks igys ls gh Toolbox
esa yksM djds LVkVZ gksrk gS A bldk mi;ksx Database dh lqfo/kkvksa dk ,Iyhds’ku fodkl esa mi;ksx djus ds
fy, fd;k tkrk gS A lkFk gh ;g Project Explorer Window esa Database ActiveX designers dks
‘kkfey dj ysrk gS A ActiveX designer MkVkcslst dks Access o Modify djus ds fy, mi;ksx esa fy, tkus
okys Visual Tools gksrs gS A

DHTML Application:
;g izkstsDV Web/HTML based applications cukus ds mi;ksx esa fy, tk ldrk gS] ftUgs
Dynamic Web-pages ds #i esa mi;ksx esa fy;k tkrk gS A bUgsa dsoy fdlh osc czkmtj (Web Browser)
tSls & Internet Explorer esa gh Execute djk;k tk ldrk gS A

IIS Application:
bldk mi;ksx bUVjusV ,Iyhds’kUl ds fodkl ds fy, fd;k tkrk gS A blls ,slh ,Iyhds’kUl fodflr
dh tk ldrh gS ftUgs Web Servers ij Execute ;k Run djk;k tk ldrk gS rFkk tks Internet ij Client
Computers ls Internet Information Server dh lgk;rk ls Interact dj ldrh gS A

Addin:
izksxzkelZ }kjk Lo;a ds Add-ins dk fodkl djus ds fy, bl izdkj ds izkstsDV dh lqfo/kk fotqvy
csfld esa miyC/k gksrh gS A Add-ins os Special Commands gksrh gS] ftUgsa fotqvy csfld ds Menus esa
‘kkfey fd;k tk ldrk gS A lkekU;r;k ;g Add-Ins Menu esa Display gksrh gS A

Page - 4  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

VB Enterprise Edition Controls:


;g lkekU;r;k Standard EXE project dh rjg gh gksrk gS] ysfdu blesa fotqvy csfld ds
,UVjizkbZt ,Mh’ku ds lHkh Controls, Tool Box esa Load gks tkrs gS A

Page - 5  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

fotqvy csfld vkbZ-Mh-bZ-


Visual Basic IDE:
fotqvy csfld ,d izksxzkfeax ySaxq,st gh ugha gS cfYd blds lkFk gh bldk ,lksfl,sVsM bUVhxzsfVM
MsoyiesaV ,Uok;jesVa vkrk gS A fotqvy csfld ds izksxzke~l ;k ,Iyhds”ku fodflr djus ds fy, tks
,Uok;jesUa V gksrk gS] mls Integrated Development Environment ;k IDE dgk tkrk gS A ,Iyhds”ku
MsoyiesaV ds fy, vko”;d fofHkUu QaD”kUl tSls fMt+kbu] ,fMfVax] dEikbfyax rFkk fMcfxax dks ,d gh LFkku
ij bUVhxzsV ;kfu lek;ksftr djds ,d Ldzhu ij bUVjQsl ds #i esa miyC/k djk;k x;k gS] ftls ge
bUVhxzsVsM MoyiesaV ,Uok;jesaV dgrs gS A

Components of Visual Basic IDE:

Menu Bar
bl ckj esa os dek.M~l gksrh gS ftudh vko”;drk izR;sd izksxzkej dks fotqvy csfld esa dk;Z djrs
le; gksrh gS A esU;w ckj esa esU;w gksrs gS tSls & File, Edit, View….Etc. ftuds vUnj esU;w vkbVe~l gksrs
gS & tks fd Individual Commands gksrh gS rFkk ftudk mi;ksx fdlh ,d fof”k’V dk;Z dks lEiUu djkus
ds fy, fd;k tkrk gS A
fotqvy csfld esa vU; izksxzke~l dh rjgh gh File, Edit, View, Window o Help tSls Standard
Menus gksrs gS] lkFkk gh izksxzkfeax ls lEcfU/kr fof”k’V QaD”kUl ds fy, Project, Format, Debug…
bR;kfn esU;w gksrs gS A

fotqvy csfld IDE esa miyC/k esU;w o muds mi;ksx fuEu izdkj ls gS &

1. File Menu:
bl esU;w esa izkstsDV dks open o save djus ] exe files cukus ds fy, dek.M~l rFkk recent
projects dh list miyC/k gksrh gS A

2. Edit Menu:
bl esU;w esa ,fMfVax ls lEcfU/kr dek.M~l tSls & Undo,Redo,Copy,Paste bR;kfn dek.M~l ds
vfrfjDr dksM~l dh QkWeZsfVax o ,fMfVax ds fy, Hkh dek.M~l gksrh gS] tSls & Find, Replace bR;kfn A

3. View Menu:
fotqvy csfld dh IDE ds Components ;k Elements dks Hide o Show djus ds fy, bl
esU;w esa dek.M~l gksrh gS A

4. Project Menu:
Current Project esa Components “kkfey djus] Windows Objects ds Reference o
Toolbox esa u;s tools “kkfey djus ds fy, bl esU;w esa fodYi gksrs gS A ;g esU;w Current Project dh
Properties dks Hkh Set djus ds fy, fodYi miyC/k djokrk gS A

Page - 6  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

5. Format Menu:
Controls dks Forms ij O;ofLFkr o foU;kflr djus ds fy, bl esU;w esa fodYi vko”;d lHkh
fodYi miyC/k gksrs gS A

6. Debug Menu:
izksxzkfeax ;k ,Iyhds”ku ds fodkl ds Ik”pkr~ mldks Test fd;k tkrk gS] rFkk =qfV;ksa dks [kkst o
igpku dj nwj fd;k tkrk gS] ftls Debugging dgk tkrk gS A fotqvy csfld ds ,Iyhds”ku fodkl esa
=qfV;ksa dks nwj djus ds fy, vko”;d lHkh lqfo/kk,sa Debug Menu miyC/k djkrk gS A

7. Run Menu:
Current Project ;k Application ds fodkl ds le; mls dbZ ckj pyk dj ns[kuk gksrk gS] pkgs
fMtkbu gks ;k dksfMax] izksxzkej dks ,Iyhds”ku esa fd;s x;s dk;Z dk izHkko ns[kus ds fy, mls pykdj ns[kus dh
vko”;drk iM+rh gS] lkFk gh fcuk cUn fd;s fdlh fof”k’V dksM ds izHkko dks Hkh ns[kuk gksrk gS rks blds fy,
fotqvy csfld dh esU;w ckj esa Run Menu ds vUrxZr Start, Break o End tSls fodYi miyC/k gksrs gS A

8. Query Menu:
Database Applications ds fodkl ds le; Structured Query Language (SQL) dh dek.M
dh vko”;drk gksus ij bl esU;w esa miyC/k fodYiksa ;k dek,.M~l dk mi;ksx dj SQL dh Queries dh
fMtkbu dks vklkuh ls mi;ksx esa fy;k tk ldrk gS A

9. Diagram Menu:
;g esU;w Hkh Database Applications ds fodkl ds le; gh mi;ksx esa fy;k tkrk gS A blesa
miyC/k dek.M~l dh lgk;rk ls Database Diagrams dks Edit fd;k tk ldrk gS A

10. Tools Menu:


bl esU;w esa ActiveX Controls o ActiveX Components ds fodkl ds fy,] Menu
Designing ds fy, Menu Editor] o IDE dks Customize djus ds fy, vko”;d dek.M~l miyC/k
gksrh gS A ,Iyhds”kUl ds fodkl ds le; ;fn izksxzkej dks fotqvy csfld ds IDE ds fdlh fof”k’V O;ogkj esa
ifjorZu djuk gks rks mlds fy, Hkh vko”;d fodYi blesa miyC/k gksrk gS A

11. Add-Ins Menu:


bl esU;w esa add-ins gksrs gS] ftUgs vko”;drkuqlkj blh esU;w ds fodYiksa dk mi;ksx dj Add o
Remove fd;k tk ldrk gS A Bydefault bl esU;w esa dsoy ,d Visual Data Manager uke dk add-
in bULVkWy jgrk gS A

12. Window Menu:


lHkh lkekU; izksxzke~l dh rjg gh fotqvy csfld IDE ds bl esU;w esa Ldzhu ij foUMkst+ dks O;ofLFkr
o fu;fU=r djus ds fy, fodYi miyC/k jgrs gS A

Page - 7  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

13. Help Menu:


fotqvy csfld esa dk;Z djrs le; ;fn fdlh izdkj dh lgk;rk ;k fdlh fodYi dh tkudkjh ysuh
gks rks mlds fy, ekbdzkslkW¶V }kjk fotqvy csfld ds lkFk gh rhu lhMh esa miyC/k fo”ks’k Help ftls
MSDN (Microsoft Developers Network) dgk tkrk gS] ds bULVkWy gksus ij ] bl esU;w dh lgk;rk
ls Help yh tk ldrh gS A

Context Menus

bl izdkj ds esU;w esa ckj&ckj mi;ksx esa vkus okyh egRoiw.kZ dek.M~l ds “kkWVZdV~l gksrs gS A blh
fy, bls “kkWVZdV esU;w Hkh dgk tkrk gS A Context Menu dks Open djus ds fy, ftl vkctsDV dks
mi;ksx fd;k tk jgk gS] ml ij ekml ds jkbV cVu ls fDyd fd;k tkrk gS A Right Click djus ij
lEcfU/kr fodYiksa ds lkFk Context Menu vk tkrk gS A

Toolbars
fotqvy csfld esa dk;Z djrs le; lkekU; rkSj ij ckj & ckj mi;ksx esa yh tkus okyh dek.M~l dks
Quick Access djus dh lqfo/kk Toolbars miyC/k djokrh gS A Toolbar ij mifLFkr cVu ij fDyd
djds mlls lEcfU/kr Action dks Execute fd;k tk ldrk gS A Bydefault Standard Toolbar fotqvy
csfld ds IDE esa iznf”kZr gksrh gS A blds vfrfjDr Editing, Form Designing o Debugging ds fy,
Hkh rhu vyx&vyx Vwyckj gksrh gS] ftUgsa View Menu ds Toolbars fodYi dh lgk;rk ls Show fd;k
tk ldrk gS A

Toolbox:

Toolbox dbZ Tools dk lSV miyC/k djkrk gS] ftudk mi;ksx izksxzkej Design Time ij Controls
dks Form ij Draw djus ds fy, fd;k tkrk gS A VwyckWDl esa bydefault, Pointer fodYi ds vykok 20
Basic ActiveX Controls yksM jgrs gS A ;s fuEu izdkj ls gksrs gS A

1. Picture Box:
bl daVªksy dk mi;ksx izksxzke esa fdlh Image dks Display djus ds fy, fd;k tkrk gS A
Image dks bldh Picture izkWiVhZ dh lgk;rk ls Set fd;k tkrk gS A blds vfrfjDr ;g
daVªksy dbZ ,sls eSFksM~l ftUgsa QaD”ku~l Hkh dgk tk ldrk gS] liksVZ djrk gS] ftudh lgk;rk
ls bl ij xzkfQDl Hkh MªkW dh tk ldrh gS A
2. Label:
;g daVªksy fdlh Form ij Text dks dsoy Display djus ds dke esa vkrk gS] ftls ;wtj
Edit ugha dj ldrk gS A budk mi;ksx lkekUr;k vU; daVªksYl ds ckjs esa ;wtj dks tkudkjh
nsus ds fy, fd;k tkrk gS] rFkk bldk Text bldh Caption uke dh izkWiVhZ ls Set fd;k
tkrk gS A
3. Text Box:
;g daVªksy Text dks Display djus ds vykok ;wtj ls Input ysus ds fy, Hkh dke esa vkrk
gS A blesa Display fd;s x;s Text dks ;wtj Edit Hkh dj ldrk gS A ;g ,d Mini Text

Page - 8  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Editor dh rjg dk;Z djrk gS A bldh eq[; izkWiVhZ Text izkWiVhZ gksrh gS A ftldh lgk;rk
ls Text lSV djus ds vykok ;wtj }kjk buiqV fd;s x;s Text dks Hkh fudkyk tk ldrk gS A
4. Frame:
;g daVªksy fdlh QkWeZ ij ckWDl ds #i esa Draw fd;k tkrk gS A bldh eq[; izkWiVhZ
Caption izkWiVhZ gksrh gS A bldk mi;ksx QkWeZ ij cuk;s x;s nwljs Controls dks Group ;k
lewg esa j[kus ds fy, fd;k tkrk gS A
5. Command Button
;g daVªksy foUMkst+ ds ,yhesVa ~l esa lokZf/kd mi;ksx esa fy, tkus okyk daVªksy gS A ;wtj }kjk
fdlh cVu fDyd djus ij ml ,D”ku dks iznf”kZr djrk gS A bldh Hkh Caption izkWiVhZ ls
bl ij Ok,Cancel,Save bR;kfn fy[kk tk ldrk gS A
6. Check Box:
bl daVªksy dk mi;ksx djds ;wtj dks ,d ;k vf/kd Choices miyC/k djkbZ tk ldrh gS]
ftlesa ls ;wtj ,d ;k vf/kd dks pqu ldrk gS A bldh lcls eq[; izkWiVhZ Value izkWiVhZ
gksrh gS A Value izkWiVhZ dk eku ;fn 0 gS rks bldk vFkZ gS fd ;g Unchecked gS] pquh
gqvk ugha gS A ;fn bldk eku 1 gS rks ;g Checked ;kfu pquk gqvk gS A ;g ,d Toggle
gS] vFkkZr~ ;wtj bl ij ,d ckj fDyd djds bls Checked o nwljh ckj fDyd djds
Unchecked dj ldrk gS A tc Hkh bl ij fDyd fd;k tkrk gS rks ;g viuh voLFkk
Checked gksus ij Unchecked ;k Unchecked gksus ij Checked esa cny ysrk gS A
7. Option Button:
bl daVªksy dks Radio Button Hkh dgk tkrk gS] bUgsa Group ;k lewg esa j[ks tkrs gS rFkk
budk mi;ksx ;wtj dks dbZ fodYi miyC/k djus ds fy, fd;k tkrk gS] ysfdu CheckBox
ds foijhr buesa ,d lewg esa ls dsoy ,d gh fodYi ;wtj pqu ldrk gS A bldh eq[; izkiWVhZ
Checked izkWiVhZ gksrh gS A ftldk eku bldks Checked djus ij True vU;Fkk False
gksrk gS A ,d lewg esa dsoy ,d gh Option Button dh Checked izkWiVhZ dk eku True
gksrk gS] vU; lHkh dh Checked izkWiVhZ dk eku False gksxk A budk lewg cukus ds fy,
lkekU;r;k Frame Control dk mi;ksx fd;k tkrk gS A

8. Combo Box:
bl daVªksy esa dbZ fodYiksa dh ,d lwph ;wtj dks miyC/k djkbZ tk ldrh gS] ftuesa ls ;wtj
dksbZ ,d pqu ldrk gS A bls lkekU;r;k fyLV ckWDl o VsDLV ckWDl dk dkWfEcus”ku dgk
tkrk gS vFkkZr~ blesa fyLV ds lkFk ,d VsDLV ckWDl dh rjg dk VsDLV ,fMV QhYM Hkh gksrk
gS vr% ;wtj fyLV esa ls fdlh fodYi dks pquus ds vfrfjDr Lo;a Hkh dksbZ vU; vkbVe Hkh
Vkbi dj ldrk gS A tks vkbVe ;wtj }kjk fodYiksa dh lwph esa ls pquk tkrk gS vFkok Vkbi
fd;k tkrk gS] mls bldh Text izkWiVhZ ls izksxzke ds dksM esa fudkyk tk ldrk gS A

9. List Box:
;g daVªksy Combo Box ds leku gh gksrk gS] ysfdu blesa ;wtj fodYiksa dh lwph esa ls gh
dksbZ ,d fodYi pqu ldrk gS A blesa dWkEcks ckWDl dh rjg ;wtj fn;s x;s fodYiksa ds
vfrfjDr dksbZ u;k vkbVe ugha buiqV dj ldrk gS A blesa lysDV ;k pquk x;k vkbVe
Text izkWiVhZ ls fudkyk tk ldrk gS A

Page - 9  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

10. Horizontal Scroll Bar:


bldk mi;ksx ;wtj dks fdlh ist dks] fiDpj dks ;k fdlh vU; foUMks esa fdlh VsDLV dks
nk;sa&ck;sa djds Ldzhu ij ykus ds fy, fd;k tkrk gS A bld daVªksy dh ikap eq[; izkiVhZt
gksrh gS A Min , Max, Small Change, Large Change o Value izkiVhZt A Min o
Max izkWiVhZ esa LdzkWy ckj dh dze”k lcls de o lcls vf/kd laHkkfor Value lSV dh tkrh
gSS A Small Change esa blds blds nk;sa o ck;sa tks ,jksa ds fpUg gksrs gS] ml ij fDyd
djus ij Value esa gksus okys ifjorZu o Large Change esa blds cVu dks ;k mlds vkxs
vFkok ihNs fDyd djus ij gksus okys Value izkWiVhZ esa gksus okys ifjorZu dk lSV fd;k tkrk
gS A Value izkIkVhZ bldh orZeku iksth”ku ;k Current Value fudkyus ds fy, mi;ksx esa
yh tkrh gS A bldh ;fn dksbZ Default oSY;w Hkh lSV djus gks rks bldh Value izkWiVhZ dk
mi;ksx fd;k tk ldrk gS A

11. Vertical Scroll Bar:


;g daVªksy Hkh gkWfjtsUVy LdzkWy ckj dh rjg gh leku izkWiVhZt okyk gksrk gS] ysfdu bldk
mi;ksx ist ;k VsDLV ;k fiDpj dks nk;sa & ck;sa djus ds LFkku ij mij&uhps djus ds fy,
fd;k tkrk gSa A

12. Timer:
bl daVªksy dk mi;ksx fdlh iwoZfuf”pr le; vUrjky ij fdlh dk;Z ;k dksM dk dk;kZfUor
;k Execute djokus ds fy, fd;k tkrk gS A bldh eq[; izkWiVhZ Interval izkWiVhZ gksrh gS A
ftlesa feyhlsd.M~l esa le; lSV djus ij ml fuf”pr le; vUrjky ij ;g vkWVkseSfVd ,d
Event ftls Timer Event dgk tkrk gS] Execute dj nsrk gS A Timer Event esa Vkbi
fd;s x;s dksM~l ml le; vUrjky ij ckj&ckj Execute gksrs jgrs gS A fdlh voLFkk esa
;fn bls jksduk gks rks bldh Enabled izkWiVhZ dks False djds bls jksdk tk ldrk gS o
vko”;drk iM+us ij True djds fQj ls pyk;k Hkh tk ldrk gS A

File System Controls:

Drive ListBox, Directory List Box o File ListBox rhuks daVªksy dks izksxzkej vius izksxzke esa
;wtj dks File-handling dh lqfo/kk miyC/k djus ds fy, mi;ksx esa ysrk gS A lkekU;r;k bu rhuksa daVªksYl
dks ,d lkFk mi;ksx esa fy;k tkrk gS rFkk bUgsa File System Controls dgk tkrk gS A

13. Drive List Box:


;g daVªksy flLVe ds MªkbZot+ dks Drop Down List esa Display djrk gS] ftlesa ls ;wtj
dksbZ ,d Drive pqu ldrk gS A bldh eq[; izkWiVhZ Drive Property gksrh gS] ftlesa Drive
lSV fd;k tk ldrk gS ;k Current Drive dkSulk gS] og Hkh fudkyk tk ldrk gS A

14. Directory List Box:


;g daVªksy Current Drive ds lHkh Folders dh fyLV Hieracrhy ds #i esa Display
djrk gS] ftlesa ;wtj Up-Down Move djds fdlh Hkh QksYMj dks pqu ldrk gS A bldh

Page - 10  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

eq[; izkWiVhZ Path izkWiVhZ gksrh gS] ftlesa fdlh Drive dks lSV fd;k vFkok fudkyk tk ldrk
gS A

15. File List Box:


;g daVªksy Current Folder dh lHkh Files dks ,d List esa Display djrk gS A bldh Hkh
eq[; izkWiVhZ Path izkWiVhZ gksrh gS] ftlesa fdlh Folder vFkok Directory dk Path fn;k
vFkok fudkyk tk ldrk gS A

16. Shape:
bl daVªksy dk mi;ksx fdlh Form ij Graphical Objects ;k Elements Draw djus ds
fy, fd;k tk ldrk gS A tSls & Rectangle, Circle, Oval etc.

17. Line:
bl daVªksy dk mi;ksx fdlh Form ij Line Draw djus ds fy, fd;k tkrk gS A

18. Image:
;g daVªksy Picture Box daVªksy dh rjg gh Images Display djus ds fy, fd;k tkrk
gS A ysfdu ;g Picture Box ds leku Graphics Draw djus ds Methods dks Support
ugha djrk gS A uk gh ;g Picture Box dh rjg nwljs daVªksYl ds fy, Container dh rjg
dk;Z dj ldrk gS A ysfdu bldh Strech izkWiVhZ dh lgk;rk ls blesa fdlh Picture dks
Strech djds Display fd;k tk ldrk gS] tks fd Picture Box }kjk ugha fd;k tk ldrk
gS A

19. Data:
;g daVªksy Database esa store fd;s x;s data dks access djus ds fy, lcls vklku lqfo/kk
point-and-click access miyC/k djkrk gS A

20. OLE:
;g daVªksy fdlh vU; ,Iyhds”ku esa cus MkWD;esVa ~l dks display djus ds fy, ,d foUMks
miyC/k djkrk gS A tSls & ekbdzkslkW¶V oMZ ] ,Dlsy bR;kfn dks fdlh Form ij Object ds
#i esa blesa [kksyk tk ldrk gS A ;g vU; applications tks fd OLE dks liksVZ djrh gS]
dh lqfo/kkvksa dks Hkh access fd;k tk ldrk gS A

Page - 11  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Project Explorer Window:

,d izkstsDV dbZ QkbYl dks ,d dysD”ku gksrk gS] ftldk mi;ksx fdlh ,Iyhds”ku ds fodkl esa
fd;k tkrk gS A

bl foUMks esa current project ds components dh list dks display fd;k tkrk gS A fotqvy
csfld esa cus ,d lkekU; exe izkstsDV esa ,d QkWeZ gksrk gS] ftlesa dbZ vU; QkWeZ add fd;s tk ldrs gS]
blds vfrfjDr dbZ vU; izdkj ds components Hkh blesa add fd;s tk ldrs gS] tSls & class modules
o activeX controls.

izkstsDV ds components, folders ds #i esa organized gksrs gS rFkk izkstsDV foUMks dks izkstsDV
,DlIyksjj foUMks dgk tkrk gS] D;ksa fd ;g foUMkst+ ,DlIyksjj dh rjg gh components dks display djrk
gS A blesa fdlh Hkh component dks pqu dj mlds code view ;k design view dks access fd;k tk
ldrk gS A ,d component ls nwljs component dh design vFkok coding esa switch djus ds fy, Hkh
bldk mi;ksx fd;k tkrk gS A

Properties Window:

fotqvy csfld esa mi;ksx esa fy, tkus okys lHkh daVªksYl dh viuh izkWiVhZt gksrh gS A fdlh Hkh daVªksy
;k vkWCtsDV dh izkWiVhZ mlds y{k.k ;k O;ogkj dks iznf”kZr djrh gS A tSls& mldk lkbt] dSI”ku] dyj
bR;kfn A
fdlh QkWeZ ;k ml ij draw fd;s x;s components ;k daVªksYl dks pquus ij mlls lEcfU/kr lHkh
properties dks properties window }kjk display fd;k tk ldrk gS A izkWiVhZt dh values dks lSV
djus ds fy, blesa lHkh izkWiVhZt o muds lkeus mudh laHkkfor values miyC/k gksrh gS] ftuesa ls pqu dj
izksxzkej mudks lSV dj ldrk gS ;k Lo;a dksbZ value izksxzkej manually Vkbi dj ldrk gS] ;fn og izkWiVhZ
,slk liksVZ djrh gS A

Object Browser

fotqvy csfld dh IDE dk ;g component fotqvy csfld ds izkstsDV esa mi;ksx esa fy, tkus okys
lHkh objects o izR;sd objects }kjk liksVZ fd;s tkus okys mlds methods, functions o izkslhtlZ dks
list miyC/k djkrk gS A ftuls mUgsa quickly access fd;k tk ldrk gS A lHkh objects dks explore djus
ds fy, bldk mi;ksx fd;k tk ldrk gS A rFkk muds supported procedures dks orZeku izkt s sDV esa
copy djds paste dj ldrk gS A

Form Designer

fotqvy csfld ds IDE esa e/; esa display gksus okyh main window ftlesa fdlh Hkh Form ij
controls, graphics, pictures vkfn dks add djds ,d vPNk user-interface design fd;k tk ldrk

Page - 12  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

gS] dks Form Designer Window dgk tk ldrk gS A gj QkWeZ dh viuh ,d Form designer window
gksrh gS A

Code Editor Window

Form designer window dh rjg gh gj QkWeZ dh viuh ,d vyx code editor window Hkh
gksrh gS ftlesa ml QkWeZ ds codes izksxzkej }kjk fn;s o edit fd;s tkrs gS A Forms ds vykok class
modules tSls components, ftudh dksbZ visual design ugha gksrh] muds codes dks Hkh blh foUMksa esa
enter o edit fd;s tk ldrs gS A

Form Layout Window

Project ;k application ds Forms dh initial positions dks set djus ds fy, properties
window ds uhps mifLFkr bl foUMks esa ,d small graphical screen o ml ij forms dk preview
miyC/k gksrk gS A mouse dh lgk;rk ls forms dh position dks visually move djds set fd;k tk
ldrk gS A

Immediate Window

Immediate Window esa application ds execution ds le; mls break djds mi;ksx fd;s x;s
variables bR;kfn dh values dks blesa display djds examine fd;k tk ldrk gS A bldsa vfrfjDr
blesa direct gh fotqvy csfld ds fdlh Hkh expression dks enter djds test fd;k tk ldrk gS A

Page - 13  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

fotqvy csfld dh voLFkk,sa (States of Visual Basic)

fotqvy csfld esa ,Iyhds”ku dh rhu voLFkk,sa gksrh gS & design, execution o break.

Design state esa izksxzkej ,Iyhds”ku esa ;wtj bUVjQsl designing ds lkFk & lkFkk coding Hkh dj ldrk
gS A ,Iyhds”ku ds fodkl dh lkjh izfdz;k lkekU;r;k blh mode ;k state esa dh tkrh gS A blesa IDE dh
lHkh foUMkst+ o dek.M~l miyC/k jgrh gS A

tc application dks pyk;k tkrk gS] rks og execution ;k ftls run state ;k mode dgrs gS] mlesa vk
tkrh gS A dqN dek.M~l ds vfrfjDr blesa IDE dh dksbZ Hkh window ;k component display ugha
gksrk gS A bl eksM esa izksxzkej ;wtj bUVjQsl dks o dksM dks edit ugha dj ldrk gS A

break state ;k mode esa application dks execution mode esa temporarily jksdk tk ldrk gS] rFkk
F5 ;k Run>>continue ls resume fd;k tk ldrk gS A bl eksM esa immediate window dks ns[kk tk
ldrk gS rFkk codes dks edit fd;k o u;h commands issue dh tk ldrh gS A ysfdu bl eksM esa Hkh
;wtj bUVjQsl dks edit ugha fd;k tk ldrk gS A

Visual Basic Development Overview:

fotqvy csfld esa application fodkl dks fuEu pj.kksa esa iwjk fd;k tk ldrk gS A

1. Design and build the user interface:


lcls igys fdlh Hkh application ds fodkl ds fy, mldk ;wtj bUVjQsl design fd;k tkrk gS A
;wtj bUVjQsl og Ldzhu gksrh gS] ftlls ;wtj interact djrk gS A bldk lcls eq[; element ,d
QkWeZ gksrk gS tks ,d foUMks dks fMLIys djrk gS A ml QkWeZ ij dbZ vU; daVªksYl] tSls & labels,
textboxes, combo boxes, command buttons vkfn draw djds o mUgs lqO;ofLFkr djds ,d
vPNk ;wtj bUVjQsl fMtkbu fd;k tk ldrk gS A Form ij izksxzkej }kjk Menus o Toolbars Hkh
miyC/k djokbZ tk ldrh gS A

bl pj.k dk lkjk dk;Z fMtkbu eksM esa gh fd;k tkrk gS rFkk daVªksy~l dks VwyckWDl ls pick djds
drag and drop method ls QkWeZ ij lqO;fLFkr fd;k tk ldrk gS A Format menu dh lgk;rk
ls bu daVªksYl dk lkbt] foU;kl] iksth”ku vkfn esa lkekatL; cSBk;k tk ldrk gS A daVªkYs l dh
appearance ls lEcfU/kr izkWiVhZt ds eku lSV djds muds individual look dks change fd;k tk
ldrk gS A bl pj.k dk lkjk eq[; dk;Z Form designer window esa fd;k tkrk gS A

Page - 14  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

2. Write code that responds to evens:


;wtj bUVjQsl design djus ds i”Pkkr~ lcls egRoiw.kZ pj.k application esa mi;ksx fy;s x;s
daVªksYl dks fdz;k”khy cukuk gksrk gS A designing ek= ls application dk;Z”khy ugha gks ldrh
vr% application ds code fy[kus vko”;d gksrs gS A blds fy, application ds ;wtj bUVjQsl esa
design esa dke esa fy, x;s daVªksYl ds eq[; o vko”;d events ij code fy[ks tkrs gS] tks fd
;wtj }kjk og event trigger gksus ij execute gksrs gS A coding dk lkjk dk;Z code window esa
fd;k tkrk gS A

3. Create and call other procedures as needed:


coding ds le; gh dqN fof”k’V lqfo/kkvksa ds fy, fotqvy csfld esa iwoZ esa gh cus izkslhtlZ] ;k
QaD”kUl dk mi;ksx fd;k tk ldrk gS ;k fQj vko”;d izkl s htlZ izkx
s zkej }kjk Lo;a cuk;s tk ldrs
gS A cus cuk;s izkslhtlZ dks in-built ;k built-in dgk tkrk gS] bUgsa ek= call djus ls ;s viuk iwoZ
fu/kkZfjr dk;Z dj nsrs gS A bl pj.k ds Hkh lHkh dk;Z code window esa gh fd;s tkrs gS A

4. Test and Debug:


bl pj.k esa application dks execute djk dj mldks test fd;k tkrk gS fd application o lHkh
lqfo/kk,sa ] QaD”kUl ftl izdkj ls design o fodflr fd;s x;s gS] rFkk pkgs x;s gS mlh izdkj ls dk;Z
dj jgs gS ;k ugha A test djus ij ;fn fdlh izdkj dh error vkrh gS rks mu codes dks break
mode esa ;k application dk execution can djds codes dks iqu% ns[kk tkrk gS] muesa laHkkfor
=qfV;ksa dks [kkstdj mudks nwj fd;k tkrk gS A fQj ls mUgs Test fd;k tkrk gS tc rd fd os lgh
rjhds ls dk;Z ugha djrh gS A =qfV;ksa dks nwj djuk debugging dgykrk gS A bl pj.k esa fotqvy
csfld ds run mode o lcls eq[; break mode esa ;k vko”;d gksus ij design mode esa Hkh dk;Z
fd;k tkrk gS A fotqvy csfld esa bl pj.k ds fy, dbZ izdkj dh lqfo/kk,sa tSls & immediate
window, local window, watch window o debug menu bR;kfn gksrs gS A ftlls Testing o
debugging vklkuh ls o “kh?kzrkiw.kZ dh tk ldrh gS A

5. Convert to runtime version:


fotqvy csfld esa ,Iyhds”ku ds fodkl ds mijksDr lHkh eq[; pj.kksa ds Ik”pkr~ ml ,Iyhds”ku dk
runtime version cuk;k tkrk gS A application ds dbZ comonents gksrs gS A tSls & .frm
files, .vbp files, .bas files bu lHkh izdkj ds components dks lgh rjhds ls combine djds
,d gh Qkby esa ftls executable file dgk tkrk gS] esa convert djuk gksrk gS A lHkh
components dks compiler djds ,d .exe file cuk;h tk ldrh gS A ftls vklkuh ls
distrubute Hkh fd;k tk ldrk gS A File Menu esa Make Exe fodYi dh lgk;rk ls ;g dk;Z
cM+h vklkuh ls fd;k tk ldrk gS ] D;ksa fd ;g iwjh rjg ls ,d automated process gksrk gS A

Page - 15  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

dsoy izksxzkej ls dqN csfld tkudkjh tSls & izkt


s sDV Qkby o cuus okyh .exe Qkby dh yksd”ku
iwNh tkrh gS A

6. Prepare distributable set of files:


Executable files cukus ds Ik”pkr~ lkekU;r;k fdlh izksQ”kuy ,Iyhds”ku dks dbZ ;wtlZ dks forfjr
djuk gksrk gS A ;g dk;Z ,Iyhds”ku dks cd, floppy tSls fdlh storage media dk mi;ksx djds
cM+h vklkuh ls fd;k tk ldrk gS A ysfdu ;g izkslsl lkekU;r;k dfBu gks ldrk gS A D;ksa fd
fdlh vU; dEI;wVj ij ,Iyhds”ku esa dke esa yh xbZ VsDuksykWth] daVªksYl] Qkbyksa dh lgh yksds”ku
bR;kfn ml ,Iyhds”ku dks pykus ds fy, lcls egRoiw.kZ gS A bu lHkh ckrksa dk /;ku j[kk tkuk
vfrvko”;d gS A blh izkslsl dks vklku cukus ds fy, fotqvy csfld }kjk package &
deployment wizard uked important tool miyC/k djk;k tk ldrk gS A ftlls fdlh Hkh exe
Qkby o lEcfU/kr Qkby~l dks combine djds ml izksxzke dk distrubutable version ;k setup
cuk;k tk ldrk gS A dqN third party softwares o tools dk mi;ksx dj Hkh ;g izkslsl iw.kZ fd;k
tk ldrk gS A

Page - 16  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Components of a Visual Basic Project:


fotqvy csfld esa fodflr fd;s fdlh izkstsDV ds izdkj ds vk/kkj ij mlesa dbZ fofHkUu izdkj ds ,d ;k
vf/kd components gks ldrs gS A ;s components fuEu izdkj dh files ds #i esa gks ldrs gS A
1. Form (.frm) :
bl izdkj dh Qkby esa fdlh QkWeZ o ml ij draw fd;s x;s lHkh daVªksYl o mudh izkWiVhZ
lSfVax~l dk textual description gksrk gS A vFkkZr~ QkWeZ o mlds daVªksYl dks Ldzhu ij
visually display djus ds fy, vko”;d dksM~l .frm files esa gksrs gS A bu files esa form
level variables, constants o procedures ds declarations Hkh gks ldrs gS A
2. Class (.cls):
Class files Hkh form files dh rjg gh gksrh gS] ysfdu blesa fy[ks x;s dksM~l fdlh izdkj
ds visual user interface display ugha djrs gS A buesa dsoy izkslsflax ds fy, dksM fy[ks
tkrs gS A izksxzkej ;fn pkgs rks Lo;a ds vkWCtsDVl cukus ds fy, bu class files dk mi;ksx
dj ldrk gS A
3. Standard(.bas):
Standard files(.bas) files esa public o module level ij declare fd;s x;s
variables, constants, user-defined data types o procedures dks contain djds j[kk
tkrk gS A
4. Resource(.res):
fdlh izkstsDV esa dke esa fy;s x;s bitmaps pictures, text strings o vU; lEcfU/kr data
dks j[kk tkrk gS A bUgsa izksxzkej }kjk codes dks re-edit o re-compile fd;s fcuk gh
change fd;k tk ldrk gS A
5. ActiveX documents(.doc):
;g QkbYl form files ds leku gh gksrh gS] ysfdu budks dsoy bUVjsusV czkmtlZ tSls &
bUVjusV ,DlIyksj esa gh pyk;k tk ldrk gS A
6. User Controls and Property Pages (.ctl & .pag):
;s QkbYl Hkh form files dh rjg gh gksrh gS] ysfdu budk mi;ksx izksxzkej }kjk Lo;a ds
ActiveX controls o muls lEcfU/kr Property Pages cukus ds fy, fd;k tkrk gS A
7. ActiveX Controls (.ocx):
fotqvy csfld }kjk miyC/k djk;s x;s default controls ds vfrfjDr dqN vU; optional
controls dks toolbox esa add fd;k tk ldrk gS A rFkk mUgsa form ij mi;ksx esa fy;k tk
ldrk gS A bu daVªksYl dks .ocx files ds #i esa j[kk tkrk gS A
8. ActiveX Designers (.dsr):
Data Environment Designer o Data Report Designer tSls fdlh Hkh u;s designer
component dks bu files ds #i esa j[kk tkrk gS A

Page - 17  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Advantages of Visual Basic:

1. fotqvy csfld dh ,Iyhds”kUl event-driven gksrh gS A Even-driven dk vFkZ gS fd ,Iyhds”ku dk


,DthD;w”ku daVªksy ;wtj ds ikl gksrk gS (user is in control of the application)A tc Hkh ;wtj
ekml ds cVu fDyd djrk gS ;k fdlh key dks press djrk gS] events dh ,d stream generate
djrk gS] fotqvy csfld ,Iyhds”ku mu events dk response izkx s zkej }kjk ml event ij fy[ks x;s
codes dks execute djds nsrk gS A
2. fotqvy csfld izkx s zkfeax ds object-oriented design dh vo/kkj.kk dks vkaf”kd #i ls support djrh
gS A vFkkZr~ fotqvy csfld ,d object-based programming language gS A vr% fotqvy csfld esa
izksxzkej ,Iyhds”ku ds fofHkUu Hkkxksa dks muds features ds vk/kkj ij vyx&vyx objects ds #i esa
treat dj ldrk gS A rFkk mUgsa Lora= #i ls vyx & vyx develop o test dj ldrk gS A ml
object dh dsoy dqN properties dks modify djds rFkk dqN methods dks invoke djds
vfrvlk/kkj.k #i ls user-interaction dks control dj ldrk gS A
3. fotqvy csfld dks Microsoft us ,d Complete Windows application development system
ds #i esa design fd;k gS A bldk eryc gS fd izksxzkej }kjk fodflr dh xbZ applications ;k
programs, windows ds nwljs vU; programs dh rjg gh fn[kkbZ nsrs gS rFkk behave djrs gS]
ftuds lkFk ;wtlZ us work fd;k gksrk gS A blls user interactivity dkQh c<+ tkrh gS D;ksa fd ;wtj
application ds environment ls igys ls gh ifjfpr gksrk gS] ftlls application T;knk user
friendly gks tkrh gS A
4. fotqvy csfld dk mi;ksx dkQh foLr`r gS] D;ksa fd blesa programmer Lo;a ds activeX controls
design dj ldrk gS ] dynamic link libraries cuk ldrk gS] rFkk add-ins develop dj ldrk
gS A blesa fodflr fd;s x;s bu components dk mi;ksx uk flQZ fotqvy csfld esa cfYd word,
excel tSlh vU; windows applications esa Hkh fd;k tk ldrk gS A

Page - 18  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Visual Basic : Programming Fundamentals

Introduction to Variables, Constants and Data Types:

fdlh Hkh izksxzke ;k ,Iyhds”ku esa izkslsflax ;k dSydqys”ku~l ds fy, dqN oSY;qt dks temporarily store djus
dh vko”;drk gksrh gS A tSls & fdUgha nks izkslslt s ls izkIr values dks compare djuk gks rks mu nksuks
results dks temporarily store djuk gksxk A

fotqvy csfld esa nwljh izksxzkfeax ySaxq,stst dh rjg gh ] values dks store djus ds fy, variables dk
mi;ksx fd;k tkrk gS A ,d variable dk ,d name gksrk gS] ftldk mi;ksx fdlh value dks store djus
ds fy;s fd;k tkrk gS rFkk izksxzkej }kjk fn;k tkrk gS ] o data type gksrk gS] tks ;g fu/kkZfjr djus ds fy,
gksrk gS fd og variable fdl izdkj dk data store dj ldrk gS A dbZ values dks ,d gh name ds
vUrxZr store djus ds fy, arrays dk mi;ksx fd;k tk ldrk gS A ftlesa name ,d gh gksrk gS] ysfdu
ml name ds dbZ subscripts gksrs gS] ftUgsa vyx & vyx index values }kjk igpkuk o access fd;k
tk ldrk gS A

blds vfrfjDr dqN values tks fd izksxzke execution ds nkSjku change ugha djus dh vko”;rk iM+rh gS]
mUgs constant ds #i esa store fd;k tk ldrk gS A constants Hkh variable dh rjg ,d fof”k’V uke o
MsVk Vkbi ds gksrs gS] ysfdu buesa store values ml izksxzke ds lEiw.kZ execution esa dHkh Hkh ifjofrZr ugha
gksrh gS A fotqvy csfld esa constants dk mi;ksx numbers dks ,d vFkZiw.kZ uke nsus ds fy, Hkh fd;k
tkrk gS] ftlls mUgsa Hkyh izdkj i<+k tk ldrk gS rFkk ;kn Hkh j[kk tk ldrk gS A fotqvy csfld esa dbZ
lkjs built-in constants Hkh gksrs gS A

Data types fotqvy csfld esa data ds internal storage (memory esa storage) dks daVªksy djrs gS A
By default, fotqvy csfld Variant data type dk mi;ksx djrk gS A ysfdu dbZ vU; izdkj ds data
types Hkh miyC/k gksrs gS ftudk mi;ksx dj codes dks speedy execution o size ds fy, optimize
djus ds fy, fd;k tk ldrk gS A

Variables:
Variables izksxzkfeax eas mi;ksx esa fy;s tkus okyh mu entities dks dgk tkrk gS] ftudh values
izksxzke ds execution ds nkSjku change ;k vary gks ldrh gS A budk mi;ksx values dks izkslsflax ds
nkSjku temporarily store djus ds fy, fd;k tkrk gS A izR;sd variable dk ,d Name o Data Type
gksrk gS A fdlh Hkh Variable dk Name izksxzkej }kjk mlds Declaration ds le; fu/kkZfjr fd;k tkrk
gS A Variable name og “kCn gksrk gS] ftlds }kjk ml variable esa values dks store fd;k tk ldrk gS
rFkk store dh xbZ values dks fudkyk tk ldrk gS A Data type Hkh izksxzkej }kjk declaration ds le;
fn;k tkrk gS rFkk blls ml variable }kjk store fd;s tkus okys data dk izdkj ;k #i fu/kkZfjr gksrk gS
vFkkZr~ og variable fdl izdkj dk data store dj ldrk gS A

Page - 19  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Variables dks fuEu fp=kqulkj vklkuh ls le>k tk ldrk gS A izR;sd variable dh nks values
gksrh gS & rvalue o lvalue A rvalue mlesa stored value o lvalue mldh memory location dh
address value gksrh gS A

1018 1020 1024 1026

Storing and Retrieving Data in Variables:


tSlk fd mijksDr esa dgk x;k gS] fd variables dk mi;ksx values dks izkslsflax ds nkSjku
temporarily store djus ds fy, fd;k tkrk gS A vr% variables esa values dks store djus o iqu%
vko”drk iM+us ij fudkyus (retrieve djus) dh vko”;drk gksrh gS A

variables esa values store djus ds fy, assignment statement dk mi;ksx fd;k tkrk gS A blh izdkj
variables esa store dh xbZ values dks fudkyus (retrieve djus) ds fy, dsoy mudk uke dk mi;ksx
fd;k tk ldrk gS A

mnkgj.k %&

;fn A , B, C uke ds ;fn rhu variable gS rks muesa value dks fuEu izdkj ls store fd;k tk ldrk gS A

A = 10 „storing value 10 to variable A

B = 20 „storing value 20 to variable 20

C = A + B „Retrieving values of A & B, Adding them and storing the addition into C

Page - 20  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Declaring Variables :

fdlh Hkh variable dks declare djus ls vFkZ ] variables ds mi;ksx ls igys program dks mlds
ckjs esa crkuk rkfd vko”;d memory vkjf{kr dh tk lds A
lkekU;r;k fotqvy csfld esa variable declare djus ds fy, Dim statement dk mi;ksx fd;k
tkrk gS rFkk mlds Ik”pkr~ variable dk uke] As dh&oMZ rFkk lcls vUr esa data type fy[kk tkrk gS A

Dim variablename [As type]

Syntax esa mi;ksx es fy;s x;s [ ] square brackets dk vFkZ gS] blds contents optional gS A ;kfu dh
fcuk data type define fd;s Hkh variable dks declare fd;k tk ldrk gS A ,slh fLFkfr esa fotqvy csfld
esa ml variable dks variant data type dh Js.kh esa j[krk gS] ftldk mYys[k vkxs fd;k x;k gS A

blds vfrfjDr variables ds names dks define djus ds fy, Hkh fu;e gksrs gS] ftUgs /;ku esa j[kk
tkuk vko”;d gksrk gS A

;s fuEu izdkj ls gksrs gS &

1- osfj;scy dk uke dk igyk v{kj lnSo letter ;k alphabet gh gksuk pkfg, A

Dim value1 As Integer lgh A


ysfdu
Dim 1value As Integer xyr A

2- osfj;scy ds uke esa fdlh izdkj dk - (period ;k dot ) ugha vkuk pkfg, rFkk uk gh dksbZ type
declaration character ;k special character ugha vkuk pkfg, tSls & space, “”, , * bR;kfnA

Dim st_name as string lgh A

Dim value.1 As Integer xyr A


;k
Dim student.name As String xyr A
;k
Dim st name As String xyr A

3- osfj;scy dk uke 255 dSjDs Vj ls vf/kd length dk ugha gksuk pkfg, A

Page - 21  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

4- osfj;scy dk uke mlds scope ;k lhek esa tgkW mls declare fd;k x;k gS] ogkW unique vFkok
ekSfyd gksuk pkfg, A tSls & fdlh ,d gh event ;k form ij ,d lkFk ,d gh variable name
dks nks ckj declare ugha fd;k tk ldrk gS A bl fu;e ds vuqlkj fuEu variable declaration
xyr gS A
Private Sub Command1_Click()
Dim value1 As Integer
Dim value1 As String
End Sub
5- fdlh Hkh osfj;scy dk uke iwoZ fu/kkZfjr constants ;k keyword ugha gksuk pkfg, A tSls & name
“kCn dk mi;ksx fotqvy csfld ds lHkh daVªksYl dh izkWiVhZ gksrh gS] font fotqvy csfld esa ,d
vkWctsDV gksrk gS] time fotqvy csfld dk ,d vkWCtsDV o QaD”ku dk uke Hkh gS] bl dkj.k izksxzkej
budk mi;ksx variable dk uke fy[kus esa ugha dj ldrk gS A bl fu;e ds vuqlkj fuEu lHkh
variable declaration xyr gS A
Dim name As String
Dim font As String
Dim time As Date

vr% mijksDr Syntax ds vuqlkj ge fuEu nks izdkj ls variable declare dj ldrs gS A

Dim value1 As Integer

Dim value1

Ikgyk statement ,d value1 uke ls variable declare dj nsxk ftlesa dsoy iw.kkZad la[;k,sa gh LVksj dh
tk ldrh gS A

tc fd nwljs statement dk mi;ksx djus ij value1 dks variant type dk eku dj mlesa fdlh Hkh izdkj
dh values dks LVksj fd;s tk ldrk gS A

Page - 22  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Implict and Explicit Declaration:

lkekU;r;k fotqvy csfld esa variables dks declare djus ds rjhdks dks fuEu nks Js.kh esa j[kk x;k gS A

1. Implicit Declaration
2. Explicit Declaration

1. Implicit Declaration:

;|fi yxHkx lHkh izksxzkfeax ySaxq,stst esa fdlh Hkh variables dks mi;ksx esa ysus ls iwoZ mls
declare djuk vko”;d gksrk gS A ysfdu fotqvy csfld esa declare fd;s fcuk Hkh variables dks
mi;ksx esa fy;k tk ldrk gS A mnkgj.k ds rkSj ij &

Dim value1 As Integer, value2 As Integer


------------------------------------
Value1 = 10 ' value1 Declared above

Value2 = 20 ' value2 Declared above

Value3 = value1 + value2 ' value3 Not-Declared

mijksDr mnkgj.k esa A Ok B variables dks declare fd;k x;k gS] ysfdu variable C dks declare ugha
fd;k x;k gS A

bl fLFkfr esa fotqvy csfld automatic C uke dk ,d variable Lo;a gh declare dj ysrk gS A blds
fy, fotqvy csfld esa ,d fof”k’V izdkj dk MsVk Vkbi ftls Variant data type dgrs gS] gksrk gS] ds
dkj.k bl voLFkk esa fotqvy csfld mi;ksx esa ysrs le; rRdky gh mls variant data type ds #i esa
on the spot declare dj nsrk gS tks fd vU; lHkh izdkj ds data dks store dj ldrk gS A value
assign djus ij mlesa assigned value ds vk/kkj ij data type change gksrk jgrk gS A

bl izdkj ;fn izksxzkej }kj fdlh variable dks declare ugha fd;k tkrk o visual basic }kjk og
variable automatically declare fd;k tkrk gS] rks bl izdkj ds variable declaration dks
Implict declaration dgk tkrk gS A

bl izdkj ds declaration dk lcls cM+k ykHk ;g gS fd ;fn izkx s zkej fdlh variable dks declare
djuk Hkwy tk, rks Hkh izksxzke esa fdlh Hkh izdkj dh =qfV ugha vkrh gS o pyrs le; izksxzke vlkekU; #i
ls can gksus ds ctk; LokHkkfod #i ls pyrk jgrk gS A

Page - 23  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Explicit Declaration:

;|fi Implicit declaration lqfo/kktud gS] ysfdu ysfdu bldh dbZ gkfu;kWa Hkh gS A lcls egRoiw.kZ
gkfu ;g gS fd] ftu variables dks izksxzkej }kjk declare ugha fd;k tkrk os visual basic }kjk
automatic variant data type esa declare dj rks fn;s tkrs gS] ysfdu D;ksa fd lHkh izdkj dk data
store fd;k tk lds bl fy, variant declared variables dks lcls vf/kdre memory nh tkrh gS]
ftlls memory dk vuko”;d vkj{k.k gks tkrk gS A lkFk gh ;g Hkh egRoiw.kZ gS fd bl izdkj ds
declaration esa variables dks process djus esa Hkh vf/kd le; yxrk gS vr% izksxzke dh overall
performance izHkkfor gksrh gS A

nwljh lkekU; o LoHkkfod gkfu bl izdkj ds variables dks ;fn misspell fd;k tk;s rks fotqvy csfld
mldks u;k variable ekudj dksbZ error Hkh ugha nsrk o mi;ksx ds le; izksxzke ds execution esa ck/kk
vk ldrh gS A
tSls &
Dim value1 As Integer, value2 As Integer, result as integer
-----------------------------------------------------------
Value1 = 10 ' value1 Declared above

Value2 = 20 ' value2 Declared above

Value3 = value1 + value2 ' value3 Not-Declared

result = vlaue3/2 ' value3 is mispelled as vlaue

mijksDr mnkgj.k esa value3 dks mi;ksx esa ysrs le; mldh spelling xyr fy[k nh xbZ gS A ,slk
LokHkkfod gS A vkSj blds dkj.k izksxzke esa =qfV vk;sxh vkSj og vlkekU; #i ls can gks tk;sxk A ;fn
value3 dks Hkh izksxzkej }kjk declare fd;k tkrk rks ,slh voLFkk esa izksxzke dks Test djrs le;
fotqvy csfld esa error message vkus ij mls Bhd fd;k tk ldrk gS A

vr% mijksDr gkfu;ksa ds fuokj.k ds fy, ;g vko”;d gS fd variables dks izkx


s kz ej ds }kjk ;fn declare
fd;k tk;s vkSj declare ugha fd;s tkus ij fotqvy csfld }kjk warning ;k psrkouh nh tk;s A

izksxzkej }kjk variables dks mi;ksx esa ysus ds iwoZ vko”;d #i ls declare djuk gh Explicit
declaration dgykrk gS A

To explicitly declare variables:

Explicit decalaration ds fy, foqtvy csfld dks vqucfU/kr djus ds fy, &

Page - 24  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

1- izksxzkej }kjk option explicit statement dks Form, Class ;k Standard Module ds
Declaration Section esa fy[k tk ldrk gS A
;k

2- fotqvy csfld dh IDE ds Tools esU;w ds Options fodYi dks pqudj] Editor VSc esa Require
Variable Declaration fodYi dks Check fd;k tk ldrk gS A blls fotqvy csfld ds lHkh
projects esa lHkh components tSls & Form, Class o Standard Modules esa fotqvy csfld
}kjk automatic decalaration section esa option explicit statement dks insert dj fn;k
tkrk gS A
Figure 1.1 Options Dialog Box in VB6 IDE

Page - 25  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

mnkgj.k &
Option Explicit
Dim value1 As Integer, value2 As Integer, result As Integer
Private Sub Command1_Click()
value1 = 10
value2 = 20
value3 = value1 + value2
result = value3 / 2
MsgBox result
End Sub

mijksDr mnkgj.k esa ,d event esa value1, value2, value3 o result uke ds pkj variables dk
mi;ksx fd;k x;k gS A value3 ds vfrfjDr lHkh variables declared gS A pwafd declaration
section esa option explicit fy[kk x;k gS] vr% tc ;g event execute gksxk rc fotqvy csfld }kjk
izksxzkej dks blds ckjs esa warning ;k error message fn;k tk;sxk rFkk lkFk gh izksxzke break mode
esa vk tk;sxk vkSj error okys LFkku dks highlight fd;k tk;sxk A

Page - 26  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

mijksDr of.kZr rjhdksa ds vfrfjDr varaiables dks declaration statements ds fcuk fuEu izdkj ls
declare fd;k tk ldrk gS A

1. Variable declaration character dk mi;ksx dj%

Variables dks declare fd;s fcuk gh mUgsa fdlh fof”k’V data type dk cukus ds fy, fuEu data
declaration characters dks variable name ds lkFk suffix ;k layXu fd;k tk ldrk gS &

Table to be created…. Here (PENDING)

2. Defxxx statement dk mi;ksx dj Hkh variables dks declare fd;k tk ldrk gS A bl


statement ds }kjk alphabets dh range nh tk ldrh gS] ml range esa vkus okys characters ls
start gksus okys lHkh variables dk default data type og gks tkrk gS tks fd Defxxx type }kjk
declare fd;k x;k gksrk gS A

fofHkUu data types ds fy, Defxxx statement fuEu izdkj ls gksrs gS &

Syntax-

DefBool letterrange[, letterrange] . . .

DefByte letterrange[, letterrange] . . .

DefInt letterrange[, letterrange] . . .

DefLng letterrange[, letterrange] . . .

DefCur letterrange[, letterrange] . . .

DefSng letterrange[, letterrange] . . .

DefDbl letterrange[, letterrange] . . .

DefDec letterrange[, letterrange] . . . „Not supported with vb6.0

DefDate letterrange[, letterrange] . . .

DefStr letterrange[, letterrange] . . .

DefObj letterrange[, letterrange] . . .

DefVar letterrange[, letterrange] . . .

Page - 27  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

mnkgj.k&
' Variable names beginning with A through K default to Integer.
DefInt A-K

' Variable names beginning with L through Z default to String.


DefStr L-Z

CalcVar = 4 ' Initialize Integer.

StringVar = "Hello there" ' Initialize String.

AnyVar = "Hello" ' Causes "Type mismatch" error.

Dim Calc As Double ' Explicitly set the type to Double.

Calc = 2.3455 ' Assign a Double.

Page - 28  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Scope of variables:

fdlh Hkh variable ds scope ls rkRi;Z bl ckr ls gS fd ml variable dks code dk dkSulk Hkkx
igpkurk o mi;ksx esa ys ldrk gS] ls gS A tc fdlh variable dks fdlh procedure ds vUnj declare
fd;k tkrk gS rks dsoy og procedure gh ml variable dk mi;ksx dj ldrk gS] pkgs mlesa value store
djuh gks ;k mldh value access ;k retrieve djuh gks A vU; procedures ds fy, og variable vKkr
gksrk gS A vr% bl izdkj ds variable dk scope ml procedure rd gh lhehr vFkkZr~ local gksrk gS A
bl izdkj ds variables dks local variables dgk tkrk gS A bUgsa fdlh procedure esa Dim keyword ls
declare fd;k tk ldrk gS A bUgsa ml procedure ds vfrfjDr fdlh vU; esa Hkh fQj ls declare fd;k tk
ldrk gSa A
mnkgj.k%&
Private Sub cmdAdd_Click()
Dim value1 As Integer, value2 As Integer, result As Integer
value1 = 10
value2 = 20
result = value1 + value2
MsgBox result
End Sub
Private Sub cmdSubtract_Click()
Dim value1 As Integer, value2 As Integer, result As Integer
value1 = 10
value2 = 20
result = value1 - value2
MsgBox result
End Sub

Page - 29  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

ysfdu dbZ ckj izkx


s zkej dks bl izdkj ds variables dh vko”;drk Hkh iM+rh gS] ftudks ml Form,
Class ;k Standard Module ds ,d gh procedure esa ugha cfYd lHkh procedures esa mi;ksx esa yk;k
tk ldsa A bl fLFkfr esa variables dk fdlh ,d procedure ds vUnj declare djus ds ctk;] ml
Form, Class ;k Standard Module ds declaration section esa Dim keyword ls declare fd;k tk
ldrk gS A D;ksa fd budk Scope Form, Class ;k Standar Module rd gksrk gS] vFkkZr~ ml Form,
Class ;k Standard Module ds lHkh Procedures mudk mi;ksx dj ldrs gS A blfy, bUgsa Form
Wide ;k Module-Wide variable dgk tkrk gS A bUgsa ml Form ds vU;= fdlh vU; Form esa rks
declare fd;k tk ldrk gS] ysfdu mlh Form esa iqu% ugha A
mnkgj.k%&
Dim value1 As Integer, value2 As Integer, result As Integer
Private Sub cmdAdd_Click()

value1 = 10
value2 = 20
result = value1 + value2
MsgBox result
End Sub
Private Sub cmdSubtract_Click()

value1 = 10
value2 = 20
result = value1 - value2
MsgBox result
End Sub

Page - 30  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

blds vfrfjDr dbZ ckj izkx


s zkej dks bl izdkj ds variables dh Hkh vko”;drk iM+ ldrh gS fd os
variables dsoy ml Project ds ;k Program ds fdlh ,d Form, Class ;k Standard Modules ds
Procedures esa gh ugha cfYd ml Project ds ;k Program ds lHkh Form, Class ;k Standard
Modules ds Procedures esa mi;ksx esa fy;k tk ldsa A

bl fLFkfr esa mu variables dks ml Program ds fdlh Hkh ,d Form esa Declaration Section
esa gh Declare fd;k tk ldrk gS] ysfdu Dim ds LFkku ij declaration esa Public keyword dk mi;ksx
fd;k tkrk gS A bu variables dk scope D;ksa fd iwjs izksxzke rd gksrk gS A vr% bUgsa Global variables
Hkh dgk tkrk gS A rFkk bUgsa Program esa vU;= dgha iqu% declare ugha fd;k tk ldrk gS A
mnkgj.k%&

Form-1 Code:
Public value1 As Integer, value2 As Integer, result As Integer
Private Sub cmdAdd_Click()

value1 = 10
value2 = 20
result = value1 + value2
MsgBox result
End Sub
Private Sub cmdSubtract_Click()

value1 = 10
value2 = 20
result = value1 - value2
MsgBox result
End Sub

Form-2 Code:

Private Sub cmdMultiplication_Click()

value1 = 10
value2 = 20
result = value1 * value2
MsgBox result
End Sub

Page - 31  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Page - 32  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Public Vs Local Variables:

izksxzkfeax djrs le; Public o Local variables ftudk dh scope vyx & vyx gksrk gS] dks ,d
leku uke fn;s tk ldrs gS A vFkkZr~ ;fn ,d gh uke dks dksbZ variable public declare fd;k x;k gS] rks
ml uke ls dksbZ local variable Hkh declare fd;k tk ldrk gS A D;ksa fd nksuksa ds scope vyx & vyx
gS A

mnkgj.k ds rkSj ij & ;fn ,d Temp uke dk public variable ;fn declared gS] vkSj fdlh
procedure esa mlh uke ;kfu Temp uke dk local variable declare gS A

mijksDr fLFkfr esa ;fn ml procedure esa Temp uke ls variable dks refer fd;k tk;sxk rks ml le;
ml procedure dk local variable access fd;k tk;sxk A vkSj ml procedure ds ckgj fdlh Hkh vU;
procedure esa Temp uke ls variable dks refer fd;k tkus ij public variable dks access fd;k
tk;sxk A

ysfdu ;fn vko”;drk gks rks ml procedure ds vUnj public variable dks Hkh access fd;k tk ldrk
gS] blds fy, ml procedure esa Form ;k Module ds uke ds i”pkr~ MkWV (.) yxkdj variable dk uke
fy[kk tk;sxk A tSls & mijksDr mnkgj.k ds public variable - Temp dks ;fn ml procedure esa
access djuk gS] ftlesa mlh uke dk local variable - Temp gS] rks ml procedure esa Form1.temp
fy[kdj mls public variable – Temp dks access fd;k tk ldrk gS A
mnkgj.k%&
Public Temp As Integer

Private Sub Command1_Click()


Dim Temp As Integer
Temp = 2
MsgBox Form1.Temp
End Sub

Private Sub Form_Load()


Temp = 1
End Sub

Page - 33  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Life time of variables:

Variables ds scope ds lkFk & lkFk izR;sd dk viuk Lifetime Hkh gksrk gS A fdlh variable ds
lifetime ls rkRi;Z gS] og le; tc rd fd mlesa stored values dks og cuk, j[k ldrk gS vFkok lqjf{kr
j[k ldrk gS A

Local, Form-Wide ;k Module-Wide rFkk Public ;k Global variables dk Lifetime Hkh


scope ds leku gh vyx&vyx gksrk gS A

Module-Wide variables dh values ml module ds terminate gksus rd mlesa lqjf{kr jgrh


gS] bldk vFkZ gS fd bl izdkj ds variables dh lifetime ml module dh lifetime ds leku gksrh gS A

Public variables dh values application ds lifetime rd lqjf{kr jgrh gS A vr% mudk


lifetime application ds lifetime ds leku gksrk gS A tSls gh application terminate gksrh gS] mudh
values lost gks tkrh gS A bUgsa Global variables Hkh dgk tk ldrk gS A

Local variables ftUgsa fd dim keyword ls declared fd;k tkrk gS] dh lifetime ml
procedure dh lifetime ds leku gksrh gS] ftlesa og declare fd;k x;k gksrk gS vFkkZr~ tc og
procedure execute gksrk gS] rc mldks memory allocate djds mlesa specified value dks store dj
fy;k tkrk gS] ysfdu procedure ds terminate gksrs gh local variable dh values lost gks tkrh gS rFkk
mi;ksx esa yh xbZ ;k allocate dh xbZ memory iqu% system dks ns nh tkrh gS A vxyh ckj tc Hkh
procedure execute gksrk gS] rc lHkh local variables fQj ls reinitialize gksrs gS A

Static Variables:

tSlk fd ge vc ;g tkurs gS fd Local variables dk lifetime ml procedure rd gh


limited ;k lhehr gksrk gS] ftlesa mls declare fd;k x;k gksrk gS] vr% blls Li’V gksrk gS fd tSls gh og
procedure terminate gksxk local variables esa stored values Hkh terminate ;k lost gks tk;sxh A

ysfdu ;fn fdlh fof”k’V fLFkfr esa ;fn izksxzkej dks ;g vko”;drk gks fd og local variables esa
stored values dks ml procedure ds terminate gksus ds Ik”pkr~ Hkh store djds j[ks rks bl fLFkfr esa
bl izdkj ds variable dks dim ds LFkku ij static keyword ls declare fd;k tkrk gS A
tSls% &
Static Counter as Integer ‘counter is a static variable.

Declaring all local variables as static:

;fn fdlh procedure esa declared lHkh local variables dks static cukuk gks rks ml
procedure ds vkxs private dh txg static keyword dk mi;ksx fd;k tkrk gS A

Page - 34  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Note:

Static variables dk lifetime ml module ds lifetime ds leku gks tkus ls ;g rkRi;Z ugha
yxkuk pkfg, fd mldk scope Hkh ifjofrZr gks x;k gS A vFkkZr~ static variables dks mlh procedure ds
}kjk retrieve ;k access fd;k tk ldrk gS] fdlh nwljs procedure ds }kjk ugha A

Constants:

Constants Hkh values dks Temporarily store djus ds fy, mi;ksx esa fy, tkrs gS A ysfdu ;s
,slh entities gksrh gS] ftudh values izksxzke execution ds nkSjku ifjofrZr ;k change ugha gksrh gS A

izksxzkfeax esa ;g fLFkfr vke gksrh gS fd fdlh code esa ,d gh value dks ckj & ckj iznf”kZr ;k
mi;ksx esa djuk iM+ ldrk gS A blds lkFk gh ,slh Hkh vko”;drk iM+rh gS fd izksxzkej }kjk fy[ks x;s
codes dqN ,sls numbers ;k la[;kvksa ij fuHkZj gks] ftUgsa ;kn j[kuk izksxzkej ds fy, vlqfo/kktud o
vuko”;d gks o ckj&ckj fy[kus ij xyrh gksus dh laHkkouk gks tSls & 3-145950 A

mijksDr fdlh Hkh izdkj dh fLFkfr esa constants dk mi;ksx fd;k tk ldrk gS A bl izdkj ls
code dh readability dks Hkh c<+k;k tk ldrk gS A

,d constant ,d vFkZiw.kZ uke gksrk gS tks fdlh ,sls number ;k string dk LFkku ij mi;ksx esa
fy;k tkrk gS ftudh values change ugha gksrh gS A

Types of Constants:

fotqvy csfld esa fuEu nks izdkj ds constants gksrs gS &

1. Intrinsic or System-defined constants


2. Symbolic or User-defined constants

1. Intrinsic or System-defined constants:

bl izdkj ds constants dks application rFkk controls ds }kjk miyC/k djk;k tkrk gS A Visual
Basic Constants & fotqvy csfld o VBA(VB for applications) dh list ;k lwph object browser
esa object libraries ds vUnj store lwphc) ;k listed gksrh gS A

nwljh vU; applications tSls & ekbdzkslkW¶V ,Dlsy o ekbdzkl s kW¶V izktsDV tks fd object
libraries dh lqfo/kk miyC/k djkrh gS] esa Hkh constants dh lwph ;k list miyC/k gksrh gS] ftuls mu
applications ds objects dks muds methods o properties ds }kjk mi;ksx esa fy;k tk ldrk gS A

izR;sd ActiveX Control dh Object library esa Hkh muds constants defined gksrs gS A

Page - 35  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

2. Symbolic or User-defined constants:

bl izdkj ds constants dks izksxzkej }kjk Const keyword dk mi;ksx djrs gq, declare fd;k
tkrk gS A fdlh Hkh Symbolic constant dks declare djus ds fy, fuEu syntax dk mi;ksx fd;k tk
ldrk gS A

[Public | Private] Const constantname [ As type ] = expression


mnkgj.k &
Private Const PI As double = 3.1428571428571428571428571428571

mijksDr ds vuqlkj loZiFz ke constant dk scope tSls private ;k public fn;k tkrk gS] fQj
Const dh&oMZ dk mi;ksx fd;k tkrk gS] mlds Ik”pkr~ izksxzkej }kjk fu/kkZfjr constant dk uke fn;k tkrk
gS] vkSj vUr esa data type o izkjfEHkd eku ;k initial value.
mnkgj.k&

,d Const statement fdlh mathematical ;k data/time quantity dks iznf”kZr dj ldrk gS A


Const MaxPlanet As Integer = 9

Const ReleaseDate As Date = #1/31/2009#

,d Const statement fdlh String constant dks Hkh define djus esa mi;ksx esa fy;k tk ldrk gS A
Const CodeName As String = "Longhorn"

Const MaleTitle As String = "Mr."

Const FemaleTitle As String = "Mrs. /Miss"

blds vfrfjDr ;fn ,d gh ykbu eas ,d ls T;knk constants dks declaration djuk gks rks mudks
dkSek ( , ) ls separate fd;k tk ldrk gS A tSls &
Const MaleTitle As String = "Mr.", Const FemaleTitle As String = "Mrs./Miss"

Scoping User-defined Constants:

,d Const statement dk Hkh variable declaration ds leku gh scope gksrk gS] ftlds fu;e
fuEu izdkj ls apply gksrs gS &

Page - 36  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

1. fdlh procedure ds vUnj constant declare djus ij og dsoy ml procedure }kjk igpkuk
tk;sxk A ;kfu fd mldk scope ml procedure rd gh limited ;k lhehr gksrk gS A
2. ,slk consant tks fdlh ,d Module ds lHkh procedures ds fy, available ;k miyC/k gks cukus
ds fy, ml constant dk lHkh procedures ds ckgj] ml Module ds declaration section esa
declare fd;k tkrk gS A
3. lEiw.kZ application ds fy, miyC/k jgus okyk constant cukus ds fy, mls fdlh standard
module ds declaration section es]a Public keyword dk Const ls igys mi;ksx djds
declare fd;k tk ldrk gS A ysfdu Public constants dks fdlh Form ;k Class Module esa
declare ugha fd;k tk ldrk gS A

Page - 37  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Data Types in Visual Basic:

Variables o Constants dks declare djrs le; mudk data type define fd;k tkrk gS A fdlh
Hkh variable ds data type ls rkRi;Z program dks ;g crkuk gS fd declare fd;k x;k variable ;k
constant fdl izdkj dh value store djsxk A vyx & vyx type ds data ds fy, vyx & vyx size esa
memory dh vko”;drk gksrh gS A tSls & fdlh Hkh iw.kkZad la[;k dks store djus ds fy, memory esa 2
bytes dh vko”;drk gksrh gS A vr% data type fdlh Hkh variable ;k constant ds fy, vko”;d
memory dk fu/kkZj.k djrs gS rFkk declare djrs le; vko”;d memory ml variable ;k constant dks
allocate dj nh tkrh gS A

Variable rFkk Constants dks declare djrs le; particular data type Hkh define fd;k tkrk
gS rks fotqvy csfld mu variables rFkk constants dks T;knk efficiency o accuracy ls handle dj
ldrh gS A

dsoy variables ;k constants gh ugha cfYd lHkh izdkj dh entities ftuesa data dk
association gksrk gS] mu lHkh ds lkFk data type Hkh associate gksrk gS A data type memory size ds
fu/kkZj.k o allocation dh n`f’V ls vfr egRoiw.kZ gks tkrk gS A

fotqvy csfld esa fuEu izdkj ds data types gksrs gS &

1. Numeric data type


2. Byte data type
3. String data type
4. Boolean data type
5. Date data type
6. Object data type
7. Variant

1. Numberic data type:

fotqvy csfld esa la[;kvksa ;k numbers dks store djus ds fy, dbZ izdkj ds numerice data
type miyC/k gS A ;s fuEu izdkj ls gS &

(1) Integer
(2) Long ;k Long Integer
(3) Single ;k Single-precision floating point
(4) Doulbe ;k Double-precision floating point

Page - 38  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

(5) Currency

1. Integer:

Integer data type dk mi;ksx iw.kkZad la[;kvksa dks vFkkZr~ ,slh la[;k,sa ftuesa n”keyo dk mi;ksx uk
gks dks store djus ds fy, fd;k tkrk gS A ;g memory esa 2 bytes ysrk gS rFkk bldh range -32,768
ls 32,767 gksrh gS A vFkkZr~ Integer type ds variables esa vf/kdre 32,767 rd dh values dks store
fd;k tk ldrk gS A ;fn negative value gks rks Hkh mls -32,768 rd Hkjk tk ldrk gS A blls T;knk
cM+h la[;k gksus ij Run time error no. 6 ftldk vFkZ overflow gksrk gS ;kfu tks limit bl type ds
data dh value dks store djus ds fy, r; gS] og mlls T;knk gS A Integer type ds variables ij
operations lcls fast gksrs gS rFkk nwljs data types dh rqyuk esa memory size Hkh de consume djrs
gS A lkekU;r;k budk lcls vf/kd mi;ksx fdlh For..Next tSls looping structure esa counter
variable ds rkSj ij fd;k tkrk gS A
mnkgj.k &
Dim Value1 As Integer, Value2 As Integer

Private Sub Command1_Click()

Value1 = 32767 „ In range

MsgBox Value1

End Sub

Private Sub Command2_Click()

Value2 = 32768 „ Will generate overflow error

MsgBox Value2 „ Run Time Error No. 6 Overflow

End Sub

2. Long ;k Long Integer:

Long ;k Long Integer data type dks Hkh integer dh rjg gh iw.kkZad la[;kvksa dks gh store djus
ds fy, mi;ksx esa fy;k tkrk gS A ysfdu integer esa values dh range 32,767 ls T;knk dh vko”;drk
gks rc Long data type dk mi;ksx fd;k tkrk gS A ;g memory esa 4 bytes consume djrk gS] rFkk
bldh range -2,147,483,648 ( nks vjc] pkSng djksM+]pkSgrj yk[k] rS;klh gtkj] N% lkS] vM+rkyhl ) ls
2,147,483,647 ( nks vjc] pkSng djksM+]pkSgrj yk[k] rS;klh gtkj] N% lkS] lSarkyhl ) rd gksrh gS A

Page - 39  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

3. Single ;k Single-precision floating point:

Single ;k Single-precision floating point data type dk mi;ksx decimal values n”keyo
okyh la[;kvksa dks store djus ds fy, mi;ksx esa fy;k tkrk gS vFkkZr~ ,slh values ftudk fraction vFkok
va”k Hkh gks A bl data type }kjk memory esa 4 bytes consume gksrs gS rFkk bldh
range -3.402823E38 ls -1.401298E-45 negative values ds fy, vkSj 1.401298E-45 to
3.402823E38 positive values ds fy, gksrh gS A Integers o Long dh rqyuk esa blesa precisions
gksus ds dkj.k ;g vf/kd memory dk mi;ksx djrs gS rFkk lkFk gh budh processing Hkh integers dh
rqyuk esa slow gksrh gS A ftrus T;knk precision gksrs mruh gh vf/kd memory dh vko”;drk rFkk
processing dh speed slow gksrh gS A

Fractional values dk memory esa actual format cgqr T;knk complicated ;k dfBu gksrk gS
vr% bls ;gkWa le>kuk laHko ugha gS A

4. Double ;k Double-precision floating point:

Double ;k Double-precision floating point data type Hkh single ds leku fraction okyh
values dks store djus ds fy, mi;ksx esa fy, tkrs gS] ysfdu blds }kjk memory esa 8 bytes consume
fd;s tkrs gS rFkk budh range single-precision data type dh range ls T;knk gksrh gS A budh
range -1.79769313486231E308 ls -4.94065645841247E-324 negative values ds fy, o
4.94065645841247E-324 ls 1.79769313486232E308 positive values ds fy, gksrh gS A
precisions dh la[;k vR;f/kd gksus ds dkj.k ;g vf/kd memory dk mi;ksx djrs gS rFkk lkFk gh budh
processing Hkh slow gksrh gS A

5. Currency:

Currency data type dk mi;ksx fdlh Hkh izdkj ds financial ;k commercial values tSls
fdlh item dh price, ;k fdlh bank [kkrs ls deposit amount, withdrawl amount bR;kfn store
djus ds fy, fd;k tkrk gS A ;g data type memory esa 8 bytes consume djrk gS rFkk bldh range
-922,337,203,685,477.5808 ls 922,337,203,685,477.5807 gksrh gS A ;g data type fixed
point digits ds lkFk 4 digits precision rd iznf”kZr dj ldrk gS A

2. Byte data type:

Byte data type fotqvy csfld ds lHkh data types esa ls lcls de memory consume djrk gS
o bldh range Hkh lcls de gksrh gS A ;g Hkh integer izdkj dh values dks store djus ds mi;ksx esa
fy;k tkrk gS A ysfdu blds }kjk memory esa dsoy 1 byte dk mi;ksx fd;k tkrk gS rFkk bldh range

Page - 40  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

0 ls 255 rd gksrh gS A ;g negative numbers dks store ugha dj ldrk A rFkk 255 ls vf/kd store
djus dk iz;kl Overflow error ns nsrk gS A bl data type dks de range dk unsigned integer dgk
tk ldrk gS A

okLrfodrk esa bldk mi;ksx binary data dks store djus ds fy, fd;k tkuk pkfg, A ;fn dksbZ
variable dk data binary gks rc mls binary data type ds array ds #i esa declare fd;k tkuk
pkfg, A arrays dk mYys[k vyx ls vkxs fd;k x;k gS A

Byte variables dk mi;ksx binary data dks store djus ds fy, djus ls data type ds format
dks convert djus ij data dks preserve ;k lqjf{kr j[krk gS A tc string variables dks ASCII rFkk
Unicode formats ds e/; esa conversion fd;k tkrk gS] rc dksbZ Hkh binary data tks fd variable esa
store gS] og corrupt ;k csdkj gks tkrk gS A fotqvy csfld automatically ASCII o Unicode ds
e/; fuEu fLFkfr;ksa ls conversion fd;k tkrk gS &

Files dks Read djrs le; A


Files dks Write djrs le; A
DLL‟s dks Call djrs le; A
Objects ds methods o mldh properties dks call djrs le; A

Unary minus operator dks NksM+dj yxHkx lHkh operators tks fd integers ij dk;Z dj ldrs gS]
byte data type ij Hkh dk;Z djrs gS A

3. String:

String data type dk mi;ksx ;fn fdlh izdkj dh la[;k ftldks calculate fd;k tk lds] dks
store ugha djuk gks vkSj alphabets bR;kfn store djus gks rc fd;k tkrk gS A tSls & fdlh company ds
fdlh employee dk uke] irk bR;kfn A bl data type ds }kjk memory esa 10 bytes + string dh
length (number of characters in the string || string esa characters dh la[;k ) ftruh memory
consume dh tkrh gS A bldh range 0 ls 2 billion (nks vjc) rd gksrh gS vFkkZr~ blesa vf/kdre 2 vjc
characters dh string dks store fd;k tk ldrk gS A

Bydefault ,d string type dk variable, osfj;scy ySUFk fLVªax ;k variable length string gksrk
gS vFkkZr~ string esa characters dh la[;k ftls string length dgrs gS] og ifjofrZr gksrh jgrh gS A ;wtj
}kjk input fd;s x;s ;k izksxzkej }kjk assign dh xbZ string NksVh ;k cM+h gks ldrh gS] D;ksa fd ;g
ifjorZuh; gksrh gS A

Page - 41  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

mijksDr ds vfrfjDr izksxzkej }kjk fdlh variable dks string declare djrs le; fixed length
string ds #i esa Hkh declare fd;k tk ldrk gS A fixed length string dks declare djus ds fy,
syntax fuEu izdkj ls gksrk gS A
String * size

mnkgj.k &
Dim StName As String * 15

mijksDr mnkgj.k esa D;ksa fd StName variable dks fixed length string, ftlesa string dh
length 15 characters gS] declare fd;k x;k gS vr% StName variable esa 15 characters ls T;knk
yEch string ugha store dh tk ldrh gS A

4. Boolean:

Boolean data type dk mi;ksx true/false ;k yes/no ;k on/off tSlh values dks store djus
ds fy, fd;k tkrk gS A tSls fdlh program esa a ;fn b ls cM+k gks ldrk gS vU;Fkk NksVk rc ,d
Boolean type dk variable mi;ksx esa fy;k tk ldrk gS] tSls & result ftlesa a>b gksus ij true o
a<b gksus ij false store fd;k tk lds A vr% result dk eku ;fn true gS rks bldk vFkZ gS fd igyh
condition lgh gS vkSj false gS rks igyh condition xyr gS A bldk lcls cM+k ykHk ;g gS fd bl izdkj
ls declared ds variables esa fdlh Hkh izdkj ls true/false ds vfrfjDr dksbZ vU; value store ugha dh
tk ldrh gS] vr% fdlh izdkj dk accidental mi;ksx ugha gks ldrk gS] vkSj result accurate izkIr gksrk
gS A

bl data type ds }kjk memory esa 2 bytes consume dh tkrh gS rFkk range esa dsoy True ;k
False dks store fd;k tk ldrk gS A
mnkgj.k &
Dim value1 As Integer, value2 As Integer, result As Boolean
Private Sub Command1_Click()
If Value > value2 Then
result = True
Else
result = False
End If
End Sub

5. Date:

Page - 42  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Date data type dk mi;ksx data o time values nksuksa dks gh store djus ds fy, fd;k tk
ldrk gS A tSls & ;fn fdlh dEiuh ds izksxzke esa ;g store djuk gks fd fdlh employee us dc join
fd;k gS rks ml data dks store djus ds fy, join_date tSls fdlh uke dk ,d date variable dks
declare djds mi;ksx esa fy;k tk ldrk gS A vU; mnkgj.k ysa tSls fd fdlh Mobile Service
Provider company dks ;g store djuk gS fd mlds fdlh customer us fdlh date dks o fdl time
ij call dh vkSj dc mls terminate fd;k] ftlls dh og mldh billing dj ldsa rks ml company ds
software esa bl rjg ds variables declare fd;s tk ldrs gS tSls & call_start o call_end A

Internally date data type esa store dh xbZ date o time dks okLrfodrk esa double-precision
numbers ds #i esa store fd;k tkrk gS & ftlesa integer part rks date dks iznZf”kr djrk gS tc fd
fractional ;k va”k okyk Hkkx time dks iznf”kZr djrk gS A

Memory esa bl data type }kjk 8 bytes consume dh tkrh gS rFkk blesa January 1, 100 ls
December 31, 9999 rd dh range esa dates store dh tk ldrh gS A
mnkgj.k &
Dim expiry As Date, call_start As Date, call_end As Date
Private Sub Command1_Click()

'Enclosed within Double quotes.

expiry = "01/01/2011"

'Enclosed within # (Hash/Pound)


expiry = #1/1/2011#

'Date and Time both in a single variable.

expiry = "01/01/2011 10:10:59 PM"


expiry = #1/1/2011 10:10:59 PM#

'Time storage into variable may be in double quotes or #.

call_start = "7:43:12 AM"


call_end = #7:45:15 AM#
End Sub

mijksDr mnkgj.k ds vuqlkj ;g Kkr gksrk gS fd fdlh Hkh variable dks date data type ds #i esa
declare djds mlesa date o time nksuksa ,d lkFk ;k vyx & vyx date ;k time dks store fd;k tk

Page - 43  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

ldrk gS A store djus ds fy, simple assignment operator dk mi;ksx fd;k tkrk gS] ysfdu values
dks double quotes (“ ”) ;k Hash # # ds symbols ls enclosed fd;k tk ldrk gS A

6. Object:

Object data type dk mi;ksx fotqvy csfld esa mifLFkr Objects tSls Command Button,
Text Box bR;kfn dks store djus ds fy, fd;k tkrk gS A ;g memory esa 4 bytes consume djrk gS A
rFkk blesa fotqvy csfld ds fdlh Hkh object dks store fd;k tk ldrk gS A Object data type ls
declare ,d variable esa fdlh Hkh Object dks Set statement dk mi;ksx dj fuEu izdkj ls store fd;k
tkrk gS A
Set variablename = object

mnkgj.k &
Dim A As CommandButton, x As TextBox, y As TextBox

Private Sub cmdOk_Click()

A.Caption = Val(x.Text) + Val(y.Text)

End Sub

Private Sub Form_Load()

Set A = cmdOk

Set x = txtValue1

Set y = txtValue2

End Sub

7. Variant:

Variant data type fotqvy csfld ds lHkh system-defined types ds data dks store dj ldrk
gS A mijksDr lHkh data types ds data dks store djus esa ;g iwjh rjg ls leFkZ gksrk gS A ,d variable
;fn variant data type dk declared gS ;k mls declared gh ugha fd;k x;k gS] rks fotqvy csfld ml
variable dh current values ds vuqlkj mldks handle djrk gS A vFkkZr~ ;fn fdlh variant variable
esa ;fn integer value store dh xbZ gS rks fotqvy csfld }kjk og integer type dh rjg gh mi;ksx esa
fy;k tk;ksxk ] ;fn string value store dh xbZ gS rks string type dh rjg gh mls treat fd;k tk;sxk A

Page - 44  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Variant data type ds dkj.k ,d gh izksxzke esa ,d gh variable fofHkUu izdkj ds data types dh
values dks store fd;k ldrk gS A fotqvy csfld values dk data type ifjofrZr gksus ij
automatically lHkh vko”;d conversion dj nsrh gS A

bl data type ls declared variable esa ;fn numbers store fd;k tkrk gS rks ;g memory esa
16 bytes consume djrk gS o blesa Double data type rd dh range dh dksbZ Hkh value store dh tk
ldrh gS A

ysfdu ;fn blesa string store dh tkrh gS rks ;g memory esa 22 bytes + string length ds
cjkcj consume djrk gS A bldh range - variable length string dh range ds cjkcj gksrh gS A

fdlh variable dks variant data type dk cukus ds fy, mls fuEu izdkj ls declare fd;k tk
ldrk gS vFkok mls declare fd;s fcuk gh dke esa fy;k tk ldrk gS A
Dim variablename [As Variant]

mnkgj.k&
Dim SomeValue „declared as Variant

OR

Dim SomeValue As Variant „declared as Variant

‘automatically declared as variant currently of string type

OtherValue = “2500”

‘declared as variant

SomeValue = "17" ‘Two characters long string.

SomeValue = SomeValue – 15 „Now contains Numerice Value 2

SomeValue = "Please Welcome" „14 Character long string.

Page - 45  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Data Type Summary

The following table shows the supported data types, including storage sizes and ranges.

Data type Storage size Range

Byte 1 byte 0 to 255


Boolean 2 bytes True or False
Integer 2 bytes -32,768 to 32,767
Long 4 bytes -2,147,483,648 to 2,147,483,647
(long integer)
Single 4 bytes -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45
(single-precision to 3.402823E38 for positive values
floating-point)
Double 8 bytes -1.79769313486231E308 to
(double-precision -4.94065645841247E-324 for negative values; 4.94065645841247E-
floating-point) 324 to 1.79769313486232E308 for positive values
Currency 8 bytes -922,337,203,685,477.5808 to 922,337,203,685,477.5807
(scaled integer)
Date 8 bytes January 1, 100 to December 31, 9999
Object 4 bytes Any Object reference
String 10 bytes + string 0 to approximately 2 billion
(variable-length) length
String Length of string 1 to approximately 65,400
(fixed-length)
Variant 16 bytes Any numeric value up to the range of a Double
(with numbers)

Variant 22 bytes + string Same range as for variable-length String


(with characters) length
User-defined Number required The range of each element is the same as the range of its data type.
(using Type) by elements

Note : Arrays of any data type require 20 bytes of memory plus 4 bytes for each array dimension plus the number of bytes
occupied by the data itself. The memory occupied by the data can be calculated by multiplying the number of data elements
by the size of each element. For example, the data in a single-dimension array consisting of 4 Integer data elements of 2 bytes
each occupies 8 bytes. The 8 bytes required for the data plus the 24 bytes of overhead brings the total memory requirement
for the array to 32 bytes.

A Variant containing an array requires 12 bytes more than the array alone.

Page - 46  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Converting Data Types:

fotqvy csfld }kjk fofHkUu values dks fdlh specific data type esa ifjofrZr djus ds fy, vusd
conversion functions miyC/k djok;s x;s gS A ;s fuEu izdkj ls gS &
Conversion function Converts an expression to
Cbool Boolean
Cbyte Byte
Ccur Currency
Cdate Date
CDbl Double
Cint Integer
CLng Long
CSng Single
CStr String
Cvar Variant
CVErr Error

fdlh Hkh conversion function esa argument ds #i esa pass dh xbZ values ml data type ds
fy, valid gksuh pkfg, ftlesa mls convert fd;k tk jgk gS A

mnkgj.k ds rkSj ij ;fn fdlh conversion fdlh Long variable ls Integer esa fd;k tk jgk gS
rks] Long variable dh value, Integer dh valid range esa vkuh pkfg, A

Page - 47  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Special Values of Variants:

Variables esa lkekU;r;k program }kjk assign dh xbZ values store gksrh gS A ysfdu tc rd
dksbZ value mudks assign ugha dh tkrh gS] rc numeric variable dh value Zero (0) ;k “kwU; vkSj
string variable dh value Zero Length (“”) gksrh gS A ysfdu variables ds fy, fotqvy csfld esa
dqN special values Hkh gksrh gS tks fd fuEu izdkj ls gS &

1. Empty Value
2. Null Value
3. Nothing Value
4. Error Value

1. Empty Value:

fdlh Hkh variant variable dks ;fn declare fd;k tkrk gS] ml fLFkfr esa tc rd dh dksbZ value
mldks assign ugha dh tkrh] rc rd mldh value Empty value gksrh gS A Empty value vU; lHkh
values ls fHkUu gksrh gS A ;g Zero, Zero Length string ;k Null ls vyx gksrh gS A

Empy value rc rd gh jgrh gS tc rd fd Variant variable dks vU; dksbZ value assign
ugha dh tkrh gS] fQj pkgs og Zero, Zero Length string ;k Null gh D;ksa u gks A

ysfdu fdlh variant variable esa Empty ds vfrfjDr ;fn dksbZ value store dj yh tkrh gS rc
Hkh mlesa iqu% Empty value dks Empty keyword ls store ;k assign fd;k tk ldrk gS A

;fn fdlh fLFkfr esa ;g check djuk gks fd fdlh variable dks ;fn dksbZ value mldks create
djus ds ckn ugha nh xbZ gks rks IsEmpty( ) function dk mi;ksx fd;k tk ldrk gS A
mnkgj.k&
Dim Value
Private Sub Command1_Click()
If IsEmpty(Value) Then ‘Return True If Executed Before
MsgBox IsEmpty(Value) ‘Command2_Click()
Else
MsgBox IsEmpty(False)
End If
End Sub
Private Sub Command2_Click()
Value = 25
If IsEmpty(Value) Then ‘Return False Whenever Executed
MsgBox IsEmpty(Value)
Else

Page - 48  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

MsgBox IsEmpty(False)
End If
End Sub
Private Sub Command3_Click()
Value = Empty
MsgBox IsEmpty(Value) ‘Return True Whenver Executed
End Sub
2. Null Value:

Null Value dk mi;ksx lkekU;r;k database applications esa unknown ;k missing data dks
iznf”kZRk djus ds fy, fd;k tkrk gS A ,d variant variable bl izdkj dh value Hkh store dj ldrk gS A
blds vfrfjDr object variable dks Hkh tc rc dksbZ value assign ugha dh tkrh gS rc rd mldh
value Null gh jgrh gS A vU; fdlh Hkh izdkj ds data type esa value dHkh Null ugha gksxh tc rd fd
mlesa Null value dks fuEu izdkj ls assign ugha fd;k tk;s A
Variablename = Null

Database field ds ,sls variables ftudk izkjfEHkd eku ugha fn;k tkrk gS mudh izkFkfed value
Null ghs gksrh gS] Empty ugha A

fdlh database field ds variable dh value Null gS ;k ugha ;g fuEu izdkj ls IsNull( )
function ls check fd;k tk ldrk gS A
If IsNull(DbFieldVariable) Then

'process variable as required

Else

'display message "can not be null" or take required action

End If

Null value dsoy variant variables dks gh assign dh tk ldrh gS] vU; type ds variables
dks Null assign djus ij Run time error no. „94‟ – “Invalid Use of Null” error message vkrk
gS A
mnkgj.k &
Private Sub Command1_Click()
X = Null 'Null value assignment
Y = Null 'Null value assignment

Page - 49  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

If IsNull(X) And IsNull(Y) Then 'Will be true


Z = Null
Else
Z = 0
End If
End Sub

Page - 50  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

3. Nothing Value:
Nothing value dk mi;ksx object variables ds lkFk fd;k tkrk gS rFkk ;g n”kkZrk gS fd
declare fd;k x;k object variable dks dksbZ value assign ugha dh xbZ gS A ysfdu lkFk gh ;fn dksbZ
value assign dj nh xbZ gks vkSj ml object dks object variable ls deassociate ;k vyx djuk gks rks
ml object variable esa set statement dh lgk;rk ls Nothing value store djds] fd;k tk ldrk gS A
check djus ds fy, fuEu izdkj ls Is Nothing statement dk mi;ksx fd;k tkrk gS A

If Variablename Is Nothing then

'process variable as required it is initialized.

Else

'variable has not yet been initialized.

End If

mnkgj.k &

Dim X As CommandButton
Private Sub Command1_Click()
If (X Is Nothing) Then ‘Will be True
MsgBox "X object variable yet has not been initialized."
End If
End Sub
Private Sub Command2_Click()
Set X = Command1 ‘Will be False
If (X Is Nothing) Then
MsgBox "X object variable yet has not been initialized."
Else
MsgBox "X has been initialized."
End If
End Sub
Private Sub Command3_Click()
Set X = Nothing „assignment of Nothing
If (X Is Nothing) Then ‘Will be true
MsgBox "X object variable yet has not been initialized."
Else
MsgBox "X has been initialized with."
End If
End Sub

Page - 51  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Page - 52  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

4. Error Value:
fdlh variant variable esa store gksus okyh ;g fof”k’V value ;g n”kkZrh gS fd fdlh function ;k
procedure esa dksbZ error condition mRiUu gks xbZ gS vkSj og successful ugha gks ik;k gS A Error
value lnSo function ds }kjk return dh tkrh gS uk fd assign dh tkrh gS A
bldk mi;ksx dj ;g irk yxk;k tk ldrk gS fd fdlh fLFkfr esa dksbZ function ;k procedure
fail rks ugha gqvk gS A ,slk djus ds fy, IsError ( ) function dk mi;ksx fd;k tk ldrk gS A

mnkgj.k &

Result = MyFunction(arguments)
If IsError (Result) Then
'write here codes to handle error as required.
Else
'use the result return by the function.
End If

Page - 53  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Examining Variable Types:


fotqvy csfld esa fdlh variable dk data type set djus rFkk mudks ,d data type ls nwljs
data type esa convert djus ds vfrfjDr variables ds data type check djus ds fy, Hkh nks functions
miyC/k djk;s x;s gS A ;s nks functions fuEu izdkj gS &

1. VarType( )
2. TypeName( )

1. VarType ( ):

VarType ( ) function dk mi;ksx variable ds data type dk irk yxkus ds fy, fd;k tkrk gS A
bl function ds argument ds #i esa fdlh variable dk name nsus ij ;g viuk result ,d Integer
number ds #i esa nsrk gS A

Syntax

VarType(varname)

mnkgj.k

VarType (a)

VarType ( ) function }kjk return fd;s tkus okys integer number o muds }kjk iznf”kZr data
type fuEu izdkj ls gksrs gS A

Return Values:

Constant Value Description


vbEmpty 0 Empty (uninitialized)
vbNull 1 Null (no valid data)
vbInteger 2 Integer
vbLong 3 Long integer
vbSingle 4 Single-precision floating-point number
vbDouble 5 Double-precision floating-point number
vbCurrency 6 Currency value
vbDate 7 Date value
vbString 8 String
vbObject 9 Object
vbError 10 Error value
vbBoolean 11 Boolean value
vbVariant 12 Variant (used only with arrays of variants)

Page - 54  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

vbDataObject 13 A data access object


vbDecimal 14 Decimal value
vbByte 17 Byte value
vbUserDefinedType 36 Variants that contain user-defined types
vbArray 8192 Array

Page - 55  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

mnkgj.k &
Dim IntVar, StrVar, DateVar, MyCheck
Private Sub Command1_Click()
' Initialize variables.
IntVar = 459: StrVar = "Hello World": DateVar = #2/12/1969#

MyCheck = VarType(IntVar) ' Returns 2.


MsgBox MyCheck

MyCheck = VarType(DateVar) ' Returns 7.


MsgBox MyCheck

MyCheck = VarType(StrVar) ' Returns 8.


MsgBox MyCheck
End Sub

2. TypeName ( ):

TypeNmae ( ) function dk mi;ksx Hkh variable ds data type dk irk yxkus ds fy, fd;k
tkrk gS A bl function ds argument ds #i esa fdlh variable dk name nsus ij ;g data type dk uke
string ds #i esa return djrk gS A

Syntax

TypeName(varname)

The required varname argument is a Variant containing any variable except a variable of a user-defined
type.

Return Values:

String returned Variable


object type An object whose type is objecttype
Byte Byte value
Integer Integer
Long Long integer
Single Single-precision floating-point number
Double Double-precision floating-point number
Currency Currency value
Decimal Decimal value
Date Date value
String String
Boolean Boolean value

Page - 56  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Error An error value


Empty Uninitialized
Null No valid data
Object An object
Unknown An object whose type is unknown
Nothing Object variable that doesn't refer to an object

mnkgj.k&
' Declare variables.
Dim NullVar, MyType, StrVar As String, IntVar As Integer, CurVar As Currency
Dim ArrayVar(1 To 5) As Integer
Private Sub Command1_Click()

NullVar = Null ' Assign Null value.

MyType = TypeName(StrVar) ' Returns "String".


MsgBox MyType

MyType = TypeName(IntVar) ' Returns "Integer".


MsgBox MyType

MyType = TypeName(CurVar) ' Returns "Currency".


MsgBox MyType

MyType = TypeName(NullVar) ' Returns "Null".


MsgBox MyType

MyType = TypeName(ArrayVar) ' Returns "Integer()".


MsgBox MyType

End Sub

Page - 57  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

mijksDr ds vfrfjDr Hkh fotqvy csfld esa dqN functions miyC/k gksrs gS tks fd variables ds
data types return djrs gS ysfdu ;s functions mudk exact data type ugha crkrs gS A ;s fuEu izdkj ls
gS &

1. IsNumeric ( ) Function:

IsNumeric ( ) esa fn;k x;k arguments variable ;k dksbZ expression gks ldrk gS A blds }kjk
return fd;k x;k result Boolean gksrk gS vFkkZr~ true vFkok false . ;fn fn;k x;k variable ;k
expression number (Integer,Long,Currency, Single or Double ) gksrk gS rks blds }kjk True
return fd;k tkrk gS vU;Fkk False.

Syntax:

IsNumeric(expression)

The required expression argument is a Variant containing a numeric expression or string


expression.

Note:

IsNumeric returns True if the entire expression is recognized as a number; otherwise, it returns False.
IsNumeric returns False if expression is a date expression.

mnkjg.k &
Dim MyVar, MyCheck
Private Sub Command1_Click()
MyVar = "53" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
MsgBox MyCheck

MyVar = "459.95" ' Assign value.


MyCheck = IsNumeric(MyVar) ' Returns True.
MsgBox MyCheck

MyVar = "45 Help" ' Assign value.


MyCheck = IsNumeric(MyVar) ' Returns False.
MsgBox MyCheck
End Sub

Page - 58  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

2. IsDate ( ) Function:
IsDate ( ) esa fn;k x;k argument ;fn valid date or time gksrk gS rks ;g true return djrk gS
vU;Fkk false. ;fn fn;k x;k argument automatic conversion djds date o time esa convert fd;k
tkrk gS rks Hkh ;g true return djrk gS A

Syntax

IsDate(expression)

The required expression argument is a Variant containing a date expression or string expression
recognizable as a date or time.

Note:

IsDate returns True if the expression is a date or is recognizable as a valid date; otherwise, it
returns False. In Microsoft Windows, the range of valid dates is January 1, 100 A.D.(bZLoh lu~)
through December 31, 9999 A.D.; the ranges vary among operating systems.

mnkjg.k &
Dim MyDate, YourDate, NoDate, MyCheck
Private Sub Command1_Click()
MyDate = "February 12, 1969": YourDate = #2/12/1969#
NoDate = "Hello"

MyCheck = IsDate(MyDate) ' Returns True.


MsgBox MyCheck

MyCheck = IsDate(YourDate) ' Returns True.


MsgBox MyCheck

MyCheck = IsDate(NoDate) ' Returns False.


MsgBox MyCheck
End Sub

Page - 59  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

3. IsArray ( ) Function:
;g function fn;s x;s variable dks check djds True return djrk gS ;fn og ,d array gks rks
vU;Fkk False return djrk gS A

Syntax

IsArray(varname)

The required varname argument is an identifier specifying a variable.

Note:

IsArray returns True if the variable is an array; otherwise, it returns False. IsArray is especially
useful with variants containing arrays.

mnkgj.k&

' Declare array variables.


Dim MyArray(1 To 5) As Integer, YourArray, MyCheck
Private Sub Command1_Click()
' Used Array function to assign array to variable.
YourArray = Array(1, 2, 3)

MyCheck = IsArray(MyArray) ' Returns True.


MsgBox MyCheck

MyCheck = IsArray(YourArray) ' Returns True.


MsgBox MyCheck
End Sub

Page - 60  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

4. IsMissing ( ) Function:
IsMissing ( ) dk mi;ksx rc fd;k tkrk gS tc ;g check djuk gks fd fdlh Procedure dk
dksbZ Optional Variant Argument Missing gS ;k ugha A ;fn Optional Variant Argument
Missing gS rks bl function ds }kjk True vU;Fkk False return fd;k tkrk gS A

Syntax

IsMissing(argname)

The required argname argument contains the name of an optional Variant procedure argument.

Note :

IsMissing does not work on simple data types (such as Integer or Double) because, unlike
Variants, they don't have a provision for a "missing" flag bit.

mnkgj.k &

Dim ReturnValue

' The following statements call the user-defined function procedure.


ReturnValue = ReturnTwice() ' Returns Null.
ReturnValue = ReturnTwice(2) ' Returns 4.

' Function procedure definition.


Function ReturnTwice(Optional A)
If IsMissing(A) Then
' If argument is missing, return a Null.
ReturnTwice = Null
Else
' If argument is present, return twice the value.
ReturnTwice = A * 2
End If
End Function

Page - 61  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

5. IsObject ( ) Function:

IsObject( ) esa fn;k x;k argument ;fn Object gks rks ;g True vU;Fkk False return djrk
gS A

Syntax

IsObject(identifier)

The required identifier argument is a variable name.

Note:

IsObject is useful only in determining whether a Variant is of VarType vbObject. This could
occur if the Variant actually references (or once referenced) an object, or if it contains Nothing.

IsObject returns True if identifier is a variable declared with Object type or any valid class type,
or if identifier is a Variant of VarType vbObject, or a user-defined object; otherwise, it returns
False. IsObject returns True even if the variable has been set to Nothing.

mnkgj.k &

Dim MyInt As Integer, YourObject, MyCheck ' Declare variables.


Dim MyObject As Object
Private Sub Command1_Click()
Set YourObject = MyObject ' Assign an object reference.

MyCheck = IsObject(YourObject) ' Returns True.


MsgBox MyCheck

MyCheck = IsObject(MyInt) ' Returns False.


MsgBox MyCheck
End Sub

Page - 62  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Arrays:

Arrays Hkh variables dh rjg gh Temporary storage ds fy, miyC/k bZdkbZ gksrs gS A lkekU;r;k ,d
variable esa ,d gh value store dh tk ldrh gS] tSls a =10, b =20 ysfdu ;fn dbZ values dks store
djuk gksrk gS rks mlds fy, dbZ variables Hkh cukus iM+rs gS] os Hkh fHkUu uke ls A blls mudks ;kn j[kuk
o manage djuk dkQh eqf”dy gks tkrk gS A vr% fotqvy csfld gh ugha cfYd yxHkx lHkh
programming language esa array uke dh data unit miyC/k gksrh gS A

Array ,d leku data type okyh dbZ values ;k elements dk ,d collection gksrk gS ftls fd
,d gh uke ls igpkuk tkrk gS A blds subscript ;k elements dks store ;k access djus ds fy,
mudh index value dk mi;ksx fd;k tkrk gS A Array ds lHkh elements memory esa ,d ds ckn ,d &
,d gh J`a[kyk (sequence) esa store gksrs gS blfy, bUgsa sequential memory location units Hkh dgk
tkrk gS A
;|fi Arrays ,d leku data type dh values ;k elements dks ,d collection ;k lewg gksrs
gS] ysfdu fotqvy csfld esa variant data type dh lqfo/kk miyC/k gksus ds dkj.k fdlh array dks variant
Hkh declare fd;k tk ldrk gS A blls Array ds lHkh elements leku data type ds gksus ds ctk; izR;sd
element vyx data type dk Hkh gks ldrk gS ;fn og fdlh vU; MkVk Vkbi esa fMDY;sj ugha gksA
lkekU;r;k ;g lqfo/kk vU; izksxzkfeax ySaxq,stst esa ugha gksrh gS A vkSj bldk mi;ksx djuk Hkh memory size
o program performance dh n`f’V ls lgh ugha ekuk tkrk gS A
izR;sd array dh nks values dze”k% Lower bound o Upper bound values gksrh gS A array dk
lcls igys element Lower bound dgykrk gS tks fd bydefault index value 0 gksrk gS A array dk
lcls vfUre element Upper bound dgykrk gS tks fd izksxzkej }kjk ;k ;wtj }kjk fu/kkZfjr fd;k tk
ldrk gS A
,d array dks Hkh variable dh rjg gh lHkh data type esa declare fd;k tk ldrk gS A Integer
declare djus ij array ds lHkh elements integer gksx]sa String declare djus ij array ds lHkh
elements String gksx a s bR;kfn A lkFk gh array dks variant declare djus ij lHkh elements vyx
vyx data type dh values dks store dj ldrs gS A
fotqvy csfld esa array nks izdkj ds gksrs gS & fixed-size array ftudk size lnSo ,d gh jgrk gS
rFkk dynamic array ftudk size run time ij change gks ldrk gS A

Declaring Fixed-Size Arrays:

Variable dh rjg gh arrays dks Hkh declare djus ds fy, Dim keyword dk mi;ksx fd;k tkrk
gS] fQj array dk name fn;k tkrk gS] ysfdu mlds i”Pkkr~ parenthesis ( ) esa maximum number of
elements tks fd og store dj ldrk gS] fy[kk tkrk gS A

Page - 63  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Syntax:
Dim arrayname(maximumsize) [ As datatype]

Page - 64  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

izR;sd array ds lHkh elements dks mudh index value dk mi;ksx dj fuEu izdkj ls muesa
values store dh tk ldrh gS A

arrayname(index) = value

blh izdkj ls array ds fdlh Hkh element dks access djus ds fy, fuEu syntax dk mi;ksx fd;k
tk ldrk gS A

Print arrayname(index)
;k

var = arrayname(index)
;k

MsgBox arrayname(index)

mnkgj.k &
Dim marks(5) As Integer

mijksDr mnkgj.k esa &


marks, array dk uke gS ftlesa 5 integer values dks store fd;k tk ldrk gS A
Bydefault Lower bound 0 gksrh gS o Upper bound 5 gS A vFkkZr~ blesa dqy 6 elements
store fd;s tk ldrs gS ftudh index values 0 ls 5 gksxh A
buesa lHkh elements dks access djus ds fy, marks(0), marks(1),marks(2)…..marks(5) ds
#i esa index fn;k tk ldrk gS A tSls &

marks(0) = 23
marks(1) = 25
marks(2) = 36
marks(3) = 18
marks(4) = 13
marks(5) = 31

;fn blds rhljs o ikapos element dks message box esa print djkuk gks rks fuEu izdkj ls fd;k
tk ldrk gS A

MsgBox marks(2) „Third element of the array.

Page - 65  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

„36 will be displayed

MsgBox marks(4) „Fifth element of the array.


‟13 will be displayed

;fn array dh lowerbound ls upperbound ds vfrfjDr index value nsdj access djus dk
iz;kl fd;k tkrk gS rks run time error no. 9 – “subscript out of range” dh error vkrh gS A

tSls &

„Will display Run time error „9‟ – “Subscript out of range” because
„lower bound is 0

marks(-1) = 12

„Will display Run time error „9‟ – “Subscript out of range” because
„upper bound is 5

marks(6) = 14

;fn array dh lower bound o upper bound Kkr djuh gks rks fotqvy csfld }kjk LBound( )
o UBound ( ) function miyC/k djk;s x;s gS A

LBound ( ) function:

;g function ,d Long integer return djrk gS tks array dh Lower bound dks n”kkZrk gS A

Syntax

LBound(arrayname[, dimension])

The LBound function syntax has these parts:

Part Description
arrayname Required. Name of the array variable; follows standard variable naming conventions.
dimension Optional; Variant (Long). Whole number indicating which dimension's lower bound is
returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted,
1 is assumed.

Page - 66  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

tSls & MsgBox LBound(marks) fd;k tk;sxk rks lower bound = 0 return fd;k tk;sxk A

Page - 67  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

UBound ( ) function:

;g function Hkh ,d Long integer return djrk gS tks fd array dh Upper bound dks n”kkZrk
gS A

Syntax

UBound(arrayname[, dimension])

The UBound function syntax has these parts:

Part Description
arrayname Required. Name of the array variable; follows standard variable naming conventions.
dimension Optional; Variant (Long). Whole number indicating which dimension's upper bound is
returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1
is assumed.

tSls & MsgBox UBound(marks) fd;k tk;sxk rks Upper bound = 5 return fd;k tk;sxk A

Specifying Limits:
;|fi fdlh Hkh array dk lower bound ;k first element dk index bydefault 0 gksrk gS ysfdu
fotqvy csfld esa izkx
s zkej }kjk lower bound dks upper bound dh rjg gh define fd;k tk ldrk gS A
vFkkZr~ lower bound esa 0 ds vfrfjDr dksbZ vU; index value Hkh gks ldrh gS A blds fy, lkekU;r;k
parenthesis ( ) esa upperbound nsus ds LFkku ij range & ftlesa lower bound o upper bound nksuks
nh tk ldrh gS A

Syntax:
Dim arrayname(lowerbound To upperbound)

tSls & Dim marks(10 To 20)

bl mnkgj.k esa lowerbound ;k array ds first element dh index value 10 o upperbound


20 gksxh A

blds vfrfjDr ;fn fdlh Hkh module ds declaration section esa Option Base 1 statement
dk mi;ksx dj ml module ds lHkh array dh default lower bound dks 0 ds ctk; 1 fd;k tk ldrk
gS A
tSls &

Page - 68  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Option Base 1
Dim Marks(6) As Integer
Marks(1) = 100
Marks(2) = 150
.
.
.
Marks(6) = 145 „LBound = 1 & UBound = 6
fdlh array ds multiple elements dk buiqV user ls ,d & ,d index ls access djds ysus ds
ctk; looping construct dk tSls For loop dk mi;ksx dj fd;k tk ldrk gS

tSls &
„Loop for Input of all elements through user.
For counter = 0 to 5
marks(i) = InputBox(“Enter marks for subject ” & i+1)
Next counter

„Loop for Output of all elements.


For counter = 0 to 5
Debug.print “Marks for subject ” & i+1 & “ is : “ & marks(i)
Next counter

Dimensions of Arrays:
izR;sd array ds vius dimensions Hkh gksrs gS A mijksDr lHkh mnkgj.k one dimensional array
Fksa A vFkkZr~ array ds lHkh elements ,d ds ckn ,d gh sequence esa store gksrs gS A tSls & mijksDr
mnkgj.k esa dsoy 6 subjects ds marks store gh store djus Fks A ysfdu ;fn dbZ students ds izR;sd ds
6 subjects ds marks store djus gks rks fQj Two dimensional array dk mi;ksx fd;k tk ldrk gS A
blesa array dk izR;sd element Lo;a ,d one dimensional array gksrk gS A vr% ,d Two
dimensional array esa First dimension dsoy rows create djrk gS rFkk second dimension izR;sd
row esa column create djrk gS A
Two dimensional arrays dks fuEu izdkj ls declare fd;k tk ldrk gS &

Dim arrayname(first_upperbound, second_upperbound)

tSls & Dim marks(4,5) As Integer

mijksDr mnkgj.k eas marks uke dk ,d Two dimensional array declare fd;k x;k gS ftlds
lHkh elements integer gksxa sA

Page - 69  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

blesa first dimension dh lower bound 0 o upper bound 4 gS tc fd second dimension


dh lower bound 0 rFkk upper bound 5 gS vFkkZRk~ ;g array dqy 5 students ds izR;sd ds 6 – 6
subjects ds marks store dj ldrk gS A
bldks rows o column ds #i esa fuEu izdkj ls iznf”kZr fd;k tk ldrk gS A
0 1 2 3 4 5 Second Dimension ( 0-5 = 6 Subjects marks )
First Dimension ( 0-4 = 5 Students )

0
1
2
3
4
Two dimensional ds elements dks fuEu izdkj ls refer fd;k tk ldrk gS A

First student‟s Six subjects:


marks(0,0) „ First student, First Subject
marks(0,1) „ First student, Second Subject
marks(0,2) „ First student, Third Subject
marks(0,3) „ First student, Fourth Subject
marks(0,4) „ First student, Fifth Subject
marks(0,5) „ First student, Sixth Subject

Second student‟s Six subjects:


marks(1,0) „ Second student, First Subject
marks(1,1) „ Second student, Second Subject
marks(1,2) „ Second student, Third Subject
marks(1,3) „ Second student, Fourth Subject
marks(1,4) „ Second student, Fifth Subject
marks(1,5) „ Second student, Sixth Subject

looping construct esa two dimensional array ds elements dks fuEu izdkj ls refer fd;k tk
ldrk gS A

Loop for input of all elements of a two dimensional array.

For i = 0 To 4

Page - 70  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

For j = 0 To 5
marks(i, j) = InputBox("Enter marks for Student [ " & i + 1 & " ] Subject [ " & j + 1 & " ] ")
Next j
Next i

Loop for output of all elements of a two dimensional array.

For i = 0 To 4
For j = 0 To 5
Debug.Print "Marks for Student [ " & i + 1 & " ] Subject [ " & j + 1 & " ] = " & marks(i, j)
Next j
Next i

mijksDr izdkj ls gh array dks vko”;drk vuqlkj three dimensional ;k vf/kd dimensional
okyk cuk;k o mi;ksx esa fy;k tk ldrk gS A bl izdkj array ds multiple dimensions gksus ij mUgsa
multidimensional array dgk tkrk gS A

Page - 71  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Dynamic Arrays:
Dynamic Arrays ,sls arrays gksrs gS ftudk upper bound ;k maximum size, program
execution ds nkSjku codes ds fu/kkZfjr gksrk gS A Program ds execution ds nkSjku gksus ds dkj.k buds
dimensions dynamically fu/kkZfjr gksrs gS A vr% bUgs dynamic arrays dgk tkrk gS A budk size
program execution ds nkSjku ifjofrZr fd;k tk ldrk gS A
budk mi;ksx lkekU;r;k rc fd;k tkrk gS tc fd izksxzkej dks ;g lqfuf”pr ugha gks dh array dks
exactly fdruk cM+k cuk;k tk;s ;k fdrus T;knk ls T;knk elements blesa store fd;s tk lds A
,d dynamic array dks fdlh Hkh le; resize fd;k tk ldrk gS A dynamic array fotqvy
csfld ds lokZf/kd flexible o convenient features gksrs gS ftudh lgk;rk ls memory dks
efficiently manage fd;k tk ldrk gS A mnkgj.k ds fy, fdlh large array dk mi;ksx de le; ds
fy;s fd;k tk ldrk gS ysfdu ckn esa tc mldh vko”;drk ugha gks rks mldh memory dks free up fd;k
tk ldrk gS A
bldk ,d fodYi ;g Hkh gks ldrk gS fd array dks laHkkfor lcls vf/kd size dk declare fd;k
tk;s vkSj ftrus elements dh vko”;drk gks mudk mi;ksx dj fy;k tk;s rFkk vU; dks tks fd “ks’k cp
tk;s ignore dj fn;k tk;s A ysfdu bl izdkj ls ckjEckj ;k overuse djus ij memory low gksus dh
laHkkouk jgrh gS A vr% dynamic array bldk lcls vPNk fodYi gS A

To create a dynamic array:


,d dynamic array dks fuEu izdkj ls create fd;k tk ldrk gS A

1. Array dks declare djrs le; mldk maximum size o dimension list dks [kkyh NksM+ fn;k
tk;s A ;g declaration lkekU;r;k declaration section esa fd;k tkrk gS ysfdu scope dh
vko”;drk ds vuqlkj bls fdlh procedure esa Hkh declare fd;k tk ldrk gS A
Syntax:
Dim dynamic_arrayname( ) [As Datatype]
mnkgj.k &
Dim DynArray ( )
2. Declare fd;s x;s dynamic array dks lcls igys fdlh procedure ds vUnj ReDim
statement dk mi;ksx djrs gq, blds dimensions o upper bound ;k maximum size fn;s
tkrs gS mlds Ik”pkr~ gh mlesa elements dks refer djds values dks access vFkok store fd;k tk
ldrk gS A

Syntax (ReDim statement):

ReDim dynamic_arrayname(dimension_list)

Page - 72  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

tSls & ReDim DynArray(6)

ReDim dynamic_arrayname( [lowerbound To [upperbound]])

tSls & ReDim DynArray(5 To 10)

3. ;|fi ReDim statement dk mi;ksx ,d ls vf/kd ckj dj dynamic array dks resize fd;k tk
ldrk gS ysfdu igyh ckj ReDim statement dk mi;ksx djrs le; fn;s x;s dimensions dks
change ugha fd;k tk ldrk gS A
tSls &
ReDim DynArray(6,2) ugha fd;k tk ldrk D;ksa fd blls igys geus bls One
dimension dk declare fd;k Fkk vkSj vc ge blesa Two Dimension define djus dk iz;kl
dj jgs gS A

ysfdu
ReDim DynArray( UBound(DynArray+1) ) fd;k tk ldrk gS D;ksa fd ge dsoy
array dk size increase dj jgs gS A
4. ReDim statement dk tc Hkh mi;ksx fd;k tkrk gS rks ;g ml array esa mifLFkr lHkh
elements dh values ;k data dk lost dj nsrk gS A fotqvy csfld lHkh elements dh values
dks bl izdkj ls reset dj nsrk gS tSls fd mls vHkh gh declare fd;k x;k gks A (;fn values
variant type dh gS rks mUgsa Empty values assign dj nsrk gS] ;fn values Numeric type dh
gS rks mUgsa zero assign dj nsrk gS o values ;fn string type dh gS rks mUgsa Zero Length ;k
Empty string assign dj nsrk gS )
5. izFke ckj ReDim statement dk mi;ksx dj tc dynamic array dks declare fd;k tkrk gS rc
rks blls dqN QdZ ugha iM+rk ysfdu tc mlesa data store dj fy;k tkrk gS vkSj mlds Ik”pkr~ mls
resize djus ds fy, tc Hkh ReDim statement dk mi;ksx fd;k tkrk gS rc iwoZ esa stored data
dk lost gksuk dkQh gkfudkjd gks ldrk gS A
6. ;fn iwoZ esa store fd;s x;s data dk lqjf{kr j[kuk gks rks ReDim statement ds lkFk esa Preserve
keyword dk mi;ksx fuEu izdkj ls fd;k tk ldrk gS A

ReDim Preserve DynArray( UBound(DynArray) + 1 )

Page - 73  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

mnkgj.k ds fy, fuEu program esa dynamic array dk mi;ksx dj le>k;k x;k gS A

Dim marks() As Integer 'Declaration of Dynamic Array


Private Sub Command1_Click()
ReDim marks(1 To 6) 'Defining Dimension and range of elements

marks(1) = 10 'storing elements


marks(2) = 25
marks(3) = 76
marks(4) = 85
marks(5) = 98
marks(6) = 12

For i = 1 To 6 'printing all elements


Debug.Print "Marks for Subject " & i & " = " & marks(i)
Next i

'Resizing array using Redim causes previously stored data


ReDim marks(UBound(marks) + 1)

marks(7) = 22 'Storing 7th element

'printing all elements, will display 0 to 1-6 and 22 to 7th element


For i = 1 To 7
Debug.Print "Marks for Subject " & i & " = " & marks(i)
Next i

'Restoring of data individually


marks(1) = 10
marks(2) = 25
marks(3) = 76
marks(4) = 85
marks(5) = 98
marks(6) = 12

'Resizing array using Redim with Preserve causes to preserve


„previously stored data
ReDim Preserve marks(UBound(marks) + 1)

marks(7) = 22

Page - 74  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

'printing all elements will display all the elements as data has not
„lost due to preserve
For i = 1 To 6
Debug.Print "Marks for Subject " & i & " = " & marks(i)
Next i

End Sub
Output :

Marks for Subject 1 = 10


Marks for Subject 2 = 25
Marks for Subject 3 = 76
Marks for Subject 4 = 85
Marks for Subject 5 = 98
Marks for Subject 6 = 12

Marks for Subject 1 = 0


ReDim marks(UBound(marks) + 1)
Marks for Subject 2 = 0
Marks for Subject 3 = 0 Previous Data Lost
Marks for Subject 4 = 0
Marks for Subject 5 = 0
Marks for Subject 6 = 0
Marks for Subject 7 = 22

Marks for Subject 1 = 31 ReDim Preserve marks(UBound(marks) + 1)


Marks for Subject 2 = 34
Marks for Subject 3 = 84 Previous Data Preserved
Marks for Subject 4 = 14
Marks for Subject 5 = 91
Marks for Subject 6 = 47
Marks for Subject 7 = 22

Page - 75  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Collections:
Arrays related data dks store djus ds fy, dkQh convenient gksrs gS ] ysfdu individual
element dks access djuk eqf”dy gksrk gS A fdlh Hkh individual elements dks access djus ds fy,
mldh index value dks ;kn j[kuk eqf”dy gksrk gS A tSls fd ;fn fdlh array esa 5 cities dk
temperature store djus ds fy, single data type dk ;fn ,d one-dimensional array
temperature uke ls cuk;k tk;s rks mlesa stored fdlh fof”k’V city dk temperature fdlh index ij
store fd;k x;k gS ;g ;kn j[kuk gksxk A mUgsa ;kn j[kuk rc vkSj eqf”dy gks tkrk gS tc fd elements
dh la[;k T;knk gks ;k array multidimensional gkss A
fotqvy csfld esa bl leL;k ds lek/kku Lo#i Collections dh oSdfYid lqfo/kk gksrh gS A array
ds leku gh collections esa Hkh related items dks store fd;k tk ldrk gS A ysfdu Collections okLro
esa ,sls Object gksrs gS ftudh viuh properties o methods gksrs gS A
Arrays dh rqyuk esa Collections dk mi;ksx djus dk lcls vf/kd ykHk ;g gS fd Collections
esa stored items ;k elements dks index value ds lkFk & lkFk fdlh key dh lgk;rk ls Hkh access
fd;k tk ldrk gS A
mijksDr mnkgj.k esa tc 5 cities ds temperature dks ;fn collection esa store fd;k tk;s rks
store djrs le; gh muds lkFk key dks associate dj fn;k tkrk gS A rFkk izR;sd item dks key ds }kjk
access fd;k tk ldrk gS A mudh index values dks ;kn j[kus dh vko”;drk ugha gksrh gS A
fdlh Hkh Collection dk mi;ksx djus ds fy, mls Hkh vU; data entities dh rjg lcls igys
declare djuk iM+rk gS A Collections dks fuEu izdkj ls declare fd;k tk ldrk gS A
Syntax:
Dim collection_name As New Collection

New keyword fotqvy csfld dks fn;s x;s uke ls ,d u;k collection cukus ds ckjs esa tkudkjh
nsrk gS A

tSls & Dim Temperatures As New Collection

Collection Object ds fuEu rhu methods o ,d property gksrh gS &

Add method : Collection esa items dks add djus ds fy, A


Remove method : Collection ls fn;s x;s index ;k key okys item dks delete djus ds fy, A
Item method : Collection ls fn;s x;s index ;k key okys item dks access djus ds fy, A
Count property : Collection ds dqy items dh la[;k return djrh gS A

Page - 76  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

Adding items to a Collection:


fdlh Hkh collection dks declare djus ds Ik”pkr~ mlesa items add djus ds fy, ;k igys ls cus
collection esa New Items dks add djus ds fy, Add method dk mi;ksx fd;k tkrk gS A

Syntax:
CollectionName.Add Item,[key],[before],[after]

tSls &
Tempratures.Add “Mumbai”, 24

fdlh Hkh collection esa ,d u;k element add djus ds fy,] Item argument esa value dks
assign fd;k tkrk gS rFkk key dks key argument esa A
New item dks fdlh fof”k’V yksds”ku ij store djus ds fy, before ;k after esa ls fdlh ,d
argument dks specify fd;k tkrk gS A New Item dks fdlh element ds igys insert djuk gks rks
before esa ml item dh key ;k index fn;k tkrk gS A tc fd fdlh element ds i”pkr~ insert djuk gks
rks after esa ml item dh key ;k index fn;k tkrk gS A

mnkgj.k &

Dim Temperatures As New Collection 'Declaration of Collection


Private Sub Command1_Click()
'Adding Items for the very first time to collections.
Temperatures.Add 24, "Mumbai"
Temperatures.Add 27, "Delhi"
Temperatures.Add 19, "Chennai"
Temperatures.Add 21, "Kolkata"

Debug.Print " All elements for the first time ...." & vbCrLf

'Printing all items of collection.


For i = 1 To Temperatures.Count
Debug.Print Temperatures.Item(i)
Next i

Debug.Print " All elements for the second time ...." & vbCrLf

'Adding New Element before = Chennai.


Temperatures.Add 27, "Hyderbad", "Chennai"

Page - 77  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

'Printing all items of collection.


For i = 1 To Temperatures.Count
Debug.Print Temperatures.Item(i)
Next i

Debug.Print " All elements for the third time ...." & vbCrLf

'Adding New Element after = Chennai


Temperatures.Add 18, "Banglore", , "Chennai"

'Printing all items of collection.


For i = 1 To Temperatures.Count
Debug.Print Temperatures.Item(i)
Next i
End Sub

All elements for the first time ....

24
27
19
21

All elements for the second time ....

24
27
27
19
21

All elements for the third time ....

24
27
27
19
18
21

Page - 78  Kshitij Divakar


 Kshitij Divakar Student’s Guide to Visual Basic 6.0

mijksDr mnkgj.k esa fuEu add statement dk mi;ksx fd;k x;k gS] ftlesa Chennai ds i”pkr~
new element banglore add fd;k tk;sxk bl fLFkfr esa before argument dks skip djuk gksxk A &

'Adding New Element after = Chennai


Temperatures.Add 18, "Banglore", , "Chennai"

Page - 79  Kshitij Divakar

Vous aimerez peut-être aussi