Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Procedure in visual basic

Visual basic में Procedure का महत्वपूर्ण कार्य होता है । Procedure एक ऐसा block code होता है ।
जिसके द्वारा विशे ष कार्य किया जाता है ।

Visual basic में सभी events की coding Procedure  के अं दर की जाती है । ये Procedure Visual
basic  में पहले से ही मौजूद है । इन्हें हम event Procedure  भी कहते हैं । Visual basic में प्रत्ये क control
की अपनी स्वयं की Procedure होती है । बिना Procedure के Visual basic में coding
करना सम्भव नहीं है ।

एक Procedure के अं दर variable, methods, properties, object तथा function का इस्ते माल किया जाता है ।

Types of Procedure in vb -
1. Subroutines or sub procedures
2. Function procedures
3. Property Procedures return and assign values of properties on objects or modules.
4. Operator Procedures define the behavior of a standard operator when one or both of the
operands is a newly-defined class or structure.

(1) Subroutines :-
Subroutines ऐसी procedure जो visual basic की Bydefault procedure होती है जिसमें code
statement Sub/End sub के मध्य लिखा जाता है । यह user को किसी तरह का value return नहीं करती है
तथा इसे अन्य procedure के द्वारा call नहीं कराया जा सकता है ।

Syntex :- 
Private/Public/Static/Subprocedure name (argulist) statement

उदाहरण-
Private Sub Command1_Click ()
Dim x as integer.
............x = msgbox "This is procedure"
.............
End Sub.

यह एक ऐसी subroutine procedure है जिसका स्कोप private है तथा subkeyword इसके


sub-routine होने का प्रमाण है तथा command1_ सम्बन्धित Controls का procedure होने को दर्शाता
है तथा Click() इस procedure का event है जो mouse द्वारा किया जाएगा ।
(2) Function :- 
Function subroutine के ही समान होता है ले किन function के द्वारा value को return कराया जा सकता है ।
function, function keyword के द्वारा परिभाषित होता है । इसे user directly code editor window में
keyboard के द्वारा type करके अथवा option menu के Add procedure dailogbox में function का
नाम, scope, तथा event दे कर भी create कर सकता है ।

Syntex :-
Private/Public/Function Function_name (argulist) as datatype
Function name=Expression.
End Function.

उदाहरण :-
Function का प्रयोग करके दो Integer का जोड़ ज्ञात करो-

Private fun add() 


Dim a, b, c As integer
a=val (Text1. text)
b=val (Text2. text)
c= a+b
Text3. text=c
End function.

Private     Sub Command1_click0


                  Dim x as integer
                  x=add ()
End sub.

Property Procedures (Visual Basic)


is a series of Visual Basic statements that manipulate a custom property on a module, class, or
structure. Property procedures are also known as property accessors.

Visual Basic provides for the following property procedures:

 A Get procedure returns the value of a property. It is called when you access the property in
an expression.
 A Set procedure sets a property to a value, including an object reference. It is called when
you assign a value to the property.

You usually define property procedures in pairs, using the Get and Set statements, but you can
define either procedure alone if the property is read-only (Get Statement) or write-only (Set
Statement).

Declaration syntax
A property itself is defined by a block of code enclosed within the Property Statement and the End
Property statement. Inside this block, each property procedure appears as an internal block
enclosed within a declaration statement (Get or Set) and the matching End declaration.

[Default] [Modifiers] Property PropertyName[(ParameterList)] [As DataType]


[AccessLevel] Get
' Statements of the Get procedure.
' The following statement returns an expression as the property's value.
Return Expression
End Get
[AccessLevel] Set[(ByVal NewValue As DataType)]
' Statements of the Set procedure.
' The following statement assigns newvalue as the property's value.
LValue = NewValue
End Set
End Property
' - or -
[Default] [Modifiers] Property PropertyName [(ParameterList)] [As DataType]

EXAMPLE:
Dim firstName, lastName As String
Property fullName() As String
Get
If lastName = "" Then
Return firstName
Else
Return firstName & " " & lastName
End If

End Get
Set(ByVal Value As String)
Dim space As Integer = Value.IndexOf(" ")
If space < 0 Then
firstName = Value
lastName = ""
Else
firstName = Value.Substring(0, space)
lastName = Value.Substring(space + 1)
End If
End Set
End Property

The following example shows typical calls to the property procedures


of fullName:
fullName = "MyFirstName MyLastName"
MsgBox(fullName)
फाइल एक्सेस सिस्टम इन विजु अल बे सिक - 
फाइल सम्बन्धित डे टाओं के समूह को कहते हैं जिसके अन्तर्गत यूजर के द्वारा create किये गए Documents तथा
प्रोग्राम होते हैं जिन्हें परमाने न्टली (Permanently) disk में Store कराया जाता है तथा Store data के साथ user
सभी manupulation कर सकता है । जै से- editing, modify, delete, copy, save इत्यादि। Files के द्वारा यूजर disk में
store किये गए डे टा का Access भी कर सकता है । किसी प्रोग्राम में यदि फाइल का प्रयोग नहीं होता है उस स्थिति में
प्रोग्राम का क् रे ता variable तथा array के रूप में Temporary memory में store होता है तथा यह केवल तभी तक
मै मोरी में रहता है जब तक execute किया गया प्रोग्राम close न हो जाए।

फाइल्स के द्वारा ही Stored किये गए डे टा read अथवा write किया जाता है । यह हम किसी व प्रोसे सर अथवा वर्ड
प्रोसे सर के बनाए गए Application के माध्यम से कर सकते हैं । System में mainly three types की files उनके काम के
आधार पर create की जाती है जो के कि निम्न हैं

1. Sequential files

2. Binary files 

3. Random Access files 

1. Sequential files - 
जै सा कि नाम से ही स्पष्ट होता है sequential files ऐसी files होती है जिन्हें continuous block में read अथवा write
करने के लिए create किया जाता है । यहाँ डे टा मु ख्यतः sequence में store होते हैं । जिस तरह इन फाइल्स को read
किया जाता है उसी प्रकार इसे write भी किया जाता है । यह फाइल्स की सबसे बड़ी समस्या इसका read अथवा write
करने में अधिक समय ले ने की है । Sequential files के अर्न्तगत string files को Double Quatations में बन्द किया
जाता है तथा प्रत्ये क files की command से अलग किया जाता है । Sequantial files को मु ख्यतः Open output
Append mode में use किया जाता है ।

यदि फाइल दिये गए स्थान पर स्थित नहीं है , तो विजु अल बे सिक इसे एक नई रिक्त फाइल बना दे ता है और यदि फाइल
दिये गए स्थान पर स्थित है तथा इसे output में खोला गया है तो डे टा की प्रविष्टि एक नए सिरे से होती है अर्थात् इस
files की प्रविष्टि पहले से स्थित डे टा पर overwrite हो जाती है ।

उदाहरण- Sequential files में Data read and write करना।

Dim fileNo As Integer File No Free File.

Open "C:\my text. text " For Append As file No

Print # file No, "Ajay" Print #file No, 12000

close file No
2. Binary files - 
विजु अल बे सिक में Binary files के द्वारा डाटाओं को Binary format में reading और writing करने के लिए Binary flies
का प्रयोग किया जाता है । इस mode में file को लिखने के लिए put स्टे टमे न्ट तथा पढ़ने के लिए Get statement का
प्रयोग किया जाता है । बायनरी और Random के मध्य केवल इतना अन्तर है कि Random Access files को खोली गई
फाइल के Data को हम Record के आधार पर पढ़ते और लिखते हैं अर्थात् फाइल से Randomly Access कर सकते हैं
जबकि Binary Access मोड में खोली गयी डे टा को Randomly Access नहीं कर सकते हैं । Binary Access mode में
खोली गई फाइल के Data को हम एक श्रख ृं ला के रूप में पढ़ सकते हैं । निम्न कोड के हम 20 बाइट् स तक पढ़ सकते हैं ।

T = String ( 20, "") 

Get #file No,,T

ध्यान दे ने योग्य बात यह है कि उपरोक्त कोड में RecNo पै रामीटर नहीं है , क्योंकि फाइल से डे टा के रूप में पढ़ा जाता है ।
विजु अल बे सिक फाइल की प्रारम्भिक स्थिति को नोट करके रखता है इसलिए प्रोग्रामर को यह ज्ञात करने की
आवश्यकता नहीं होती कि फाइल कहाँ से शु रू हो रही है । 

3. Random Data files - 


यह ऐसा file type है जिसमें Data को read अथवा write किसी भी order से किया जा सकता है । यह Data को
Randomly Access करने के लिए use होता है जबकि Sequential फाइल डे टा को हर बार read करने के लिए प्रारम्भ
से शु रू करना होता Sequential file अपनी इसी समस्या के कारण अधिक समय files को Access करने के लिए ले ती है
जबकि इससे साथ ऐसी कोई समस्या नहीं तथा यह निर्धारित fixed length के Records को Access करता है । "इसे
टे बल के माध्यम से आसानी से समझा जा सकता है
Random files में सारे Records same size के होते हैं । Records में सारे fields का Length और position fixed होता
है । 

Random files के लिए Record को define करना - जब किसी Random files को define किया जाता है तो इसे
structrue की तरह define करना होता है ।

Private Type Member StrName As String * 20

StrAge As String *20

StrCon As String *20

End Type.

Random files को open करना - इसे open statements के द्वारा open किया जाता है ।

Example - 

Open "C:\data\age.txt" for Random As # 10

You might also like