What is Subroutines in VB.Net

Subroutines

Subroutines ऐसे statements के code blocks है जो किसी define किए गए task को handle करने के लिए प्रयोग किए जाते हैं। Subroutines को Sub Procedures भी कहते है। Subroutines की statements Sub…………End Sub statement के block के बीच लिखी जाती हैं और इन्हे इनके नाम से identify किया जाता है। Subroutines C,C++ मे use होने वाले functions की तरह ही होते है केवल subroutines कोई value return नहीं करती है। Visual Basic को एक procedural language भी कहा जाता है क्योंकि इसमे ज़्यादातर codes sub procedures के अंदर लिखे जाते है।
“A Subroutine is a block of statements that carries out a well-defined task.”

Example: Sub ShowDate()
Msgbox( now( ))
End Sub

Declaring Subroutines: Subroutine को declare करने के लिए निम्नलिखित स्टेटमेंट का प्रयोग किया जाता है।
Syntax- Sub ( [arguments] )
[Statements] End Sub

Example: Private Sub ShowDate()
Msgbox ( now())
End Sub

Calling Subroutines:किसी भी sub procedure को call करने के लिए उसके name का use किया जाता है। sub procedure का name लिखकर उसे call करते हैं यदि उसमे arguments को use किया गया हो तो उन्हे भी define किया जाता है। call keyword का भी use subroutines को call करने के लिए किया जाता है।

Syntax- [Call] Sub_procedure_Name ([arguments])
Example- ShowDate ( )
या Call ShowDate ( )

जब किसी भी subroutine को call किया जाता है तब program का control subroutine के procedure मे move हो जाता है। subroutine के execution के बाद end sub statement मे पहुचने के बाद program का control फिर से calling program के पास वापस पंहुच जाता है। subroutine से program को directly exit करने के लिए exit sub statement का use किया जाता है।



error: Content is protected !!