Tuesday, January 1, 2013


        functions और subroutines directly program से interact नहीं कर सकते। अधिकतर procedures इन्हे call करने के लिए arguments का use करते है। इन arguments को इस procedures मे value पास करने के लिए प्रयोग किया जाता है। यह arguments functions और subroutines के लिए input की तरह ही होते हैं जो इन्हे calling program के द्वारा दिया जाता है।

Ex-
Functions Min (ByVal a As Single, ByVal b as Single) As Single
      If a<b then
         Min= a
      else
         Min= b
      End If
End Function


Argument- Passing Mechanisms:

VB.Net मे किसी भी function या subprocedure मे arguments को Pass किया जा सकता है। इसका passing mechanism determine करता है की pass किए जाने वाले arguments की value को subprocedure modify कर सकता है या नहीं।

Syntax- [Byval / ByRef] <variable_name> As <Data Type>

 VB.Net procedures मे arguements को pass करने के लिए निम्नलिखित दो प्रकार के machanisms का use किया जाता है।

·         Passing Arguments by Values: जब arguments by value pass किए जाते हैं तब procedure argument की copy को use करता है और उसमे किए गए changes का main argument पर कोई effect नहीं होता है। arguments को by value pass करने पर केवल उसी procedure मे उसे change किया जा सकता है जहां इसे declare किया गया है। इसके लिए Byval keyword का use किया जाता है।


Private Function Sum(ByVal a As Integer, ByVal b As Integer) As Integer
        Return (a + b)
End Function

·         Passing Arguments By Reference: जब arguments को By Reference pass किया जाता है तब argument मे actual variable pass हो जाता है। इसमे calling procedure के द्वारा main variable का address pass किया जाता है जिससे called procedure मे argument की value change करने पर pass किए गए argument को original value change हो जाती है। इसके लिए ByRef keyword का use किया जाता है।


 Private Function Sum(ByRef a As Integer, ByRef b As Integer) As Integer
        Return (a + b)
 End Function

Monday, December 31, 2012


Return Type: 

         VB.Net मे सभी functions value return करते है इसलिए सभी functions का type होता है जिसे की return type कहते है और return होने वाली value को return value कहते है। function का return type, returning value और calling code मे use होने वाला variable का type हमेशा एक type का ही होना चाहिए। return type किसी भी टाइप का हो सकता है जैसे class, datatype, structure, object etc. 

Returning Value:

          function से return की जाने वाली value को returning value कहते है। returning value function के return type पे depend करती है। value को return करने के लिए Return keyword का use किया जाता है।

Syntax-       Return (returning value)
Ex-        Return (c)

Functions:

Functions subroutine के तरह ही code के blocks है जो की calling program को value return करते है। subroutines किसी define किए गए task को पूरा करने के बाद कोई भी value return नहीं करते है जबकि functions किसी define किए गए task को पूरा करने के बाद calling program को एक value return करते है। function subroutine की तरह ही arguments accept करते है। functions को declare करने के लिए Function…. End function statement का use किया जाता है। जिसकी syntax निम्न लिखित है।

       <Access modifier> Function <Function Name> ([arguments]) As <Return Type>

           [Function’s statements]

           Return <returning value>

     End Function
Ex-
       Private Function Sum ( ) As Double
           Dim a, b, c as Double
           a = Val (Textbox1.Text)
           b = Val (Textbox2.Text)
           c= a + b
           Return (c)
     End Function

Access modifier function के scope को बताता है। यह private, public and friend हो सकता है।

Saturday, December 29, 2012

Subroutines: 

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

Sub ShowDate() 

Msgbox( now( )) 

End Sub 



Declaring Subroutines: Subroutine को declare करने के लिए निम्नलिखित statement का प्रयोग किया जाता है।



<Access_modifier> Sub <Sub_Procedure_Name> ( [arguments] )

[Statements]

End Sub




Ex- Private Sub ShowDate()

Msgbox ( now())

End Sub

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

Syntax- [Call] Sub_procedure_Name ([arguments])

Ex- 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 किया जाता है।

Thursday, December 27, 2012

Queue:


 यह भी एक प्रकार का डाटा structure है जो की Queue की तरह work करता है। इसमे First in First out (FIFO) के अनुसार काम करता है। इसमे सबसे पहले insert किया गया item सबसे पहले बाहर जाएगा और सबसे last मे input किया गया item last मे बाहर जाएगा।
Syntax: Dim <Queue Name> As New Queue 

Ex- Dim q as new queue 

  • Enqueue: इस method का use item को queue मे add करने के लिए किया जाता है। 

Syntax: Queue.Enqueue (object) 

Ex- q.Enqueue (“A”) 

  • Dequeue: इस method का use item को queue से delete करने के लिए किया जाता है। 

Syntax: Queue.Dequeue() 

Ex- q.Dequeue () 

  • Contains: इसका प्रयोग item को चेक करने के लिए किया जाता है। 

Syntax: Queue.Contains (object) 

Ex- q.Contains (“A”) 

Program: Queue:


Public Class Form1

    Dim q As New Queue

    Private Sub Refreshlabel()
        Dim i As Integer
        Dim ar() As Object
        ReDim ar(q.Count)

        ar = q.ToArray
        Label1.Text = ""
        For i = 0 To q.Count - 1
            Label1.Text = Label1.Text & ar(i) & Chr(13)
        Next
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        q.Enqueue(TextBox1.Text)
        TextBox1.Clear()
        TextBox1.Focus()
        Refreshlabel()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        q.Dequeue()
        Refreshlabel()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim s As String
        s = InputBox("Enter value to check")
        If q.Contains(s) = True Then
            MsgBox("Found")
        Else
            MsgBox("not Found")
        End If
    End Sub
End Class


Tuesday, December 25, 2012

Stack: 


             Stack भी एक VB.Net collections का टाइप है जो की Data structure के Stack की तरह ही कार्य करता है। यह last in first out के अनुसार काम करता है। इसमे डाटा input के लिए Push और Out के लिए Pop operation का use किया जाता है।

Declaration:

Syntax: Dim <stack name> As New Stack 

Ex- Dim stk As new stack 

Important Methods:

  • · Push: इसका प्रयोग stack मे item को add करने के लिए किया जाता है। 

Syntax: Stack.Push (object) 

Ex- stk.push (“A”) 
  • Pop: इसका प्रयोग stack से item को remove करने के लिए किया जाता है। 

Syntax: Stack.pop 

Ex- stk.pop 

  • Contains: इस method का use object को check करने के लिए किया जाता है। 

Syntax: Stack.Contains (object) 

Ex- stk.Contains (“A”) 

PROGRAM: STACK

Public Class Form1

    Dim stk As New Stack

    Private Sub Refreshlabel()
        Dim i As Integer
        Dim ar() As Object
        ReDim ar(stk.Count)
        ar = stk.ToArray
        Label1.Text = ""
        For i = 0 To stk.Count - 1
            Label1.Text = Label1.Text & ar(i) & Chr(13)
        Next
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        stk.Push(TextBox1.Text)
        TextBox1.Clear()
        TextBox1.Focus()
        Refreshlabel()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        stk.Pop()
        Refreshlabel()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim s As String
        s = InputBox("Enter value to check")
        If stk.Contains(s) = True Then
            MsgBox("Found")
        Else
            MsgBox("not Found")
        End If
    End Sub
End Class


Monday, December 24, 2012

HashTable:
hashtable का use paired type के data को store करने के लिए किया जाता है। यह collection भी arraylist की तरह ही होता है पर इसमे item को access करने के लिए key का use किया जाता है। इसमे सभी items की एक key होती है। value array मे store होने वाली value ही होती केवल इसमे सभी values के साथ एक key भी होती है। hashtable मे key और value दोनों object type के होते हैं।
Declaration of HashTable:
       Syntax: Dim <HashTable name> As New HashTable
       Ex- Dim htable As new HashTable
Important Functions used HashTable:
  • Add: इस function का use hashtable मे value को add करने के लिए किया जाता है। इसमे key – key value है और Value- add होने वाला item है।
Syntax: HashTable.Add (key, value)
Ex- htable.add (1, “A”)
htable.add (2, “B”)
htable.add (3, “C”)
  • ContainsKey(): इस function का use hashtable मे key को check करने के लिए किया जाता है।
Syntax: Hashtable.ContainsKey (Key)
Ex- htable.ContainsKey (1)
  • ContainsValue: इस फंकशन का use hashtable मे value को check करने के लिए किया जाता है।
Syntax: Hashtable.ContainsValue (Value)
Ex- htable.ContainsKey (“A”)
  • Remove: इसका use key और उसकी value को hashtable से delete करने के लिए किया जाता है।
Syntax: Hashtable.Remove(key)
Ex- htable.remove(2)
Program: HashTable:

Public Class Form1

    Dim htable As New Hashtable

    Private Sub RefreshLabel()
        Dim objkey As Object
        Dim objval As Object
        Label1.Text = ""
        For Each objkey In htable.Keys
            objval = htable.Item(objkey)
            Label1.Text = Label1.Text & "Key :  " & objkey.ToString & ",  Value:   " & objval.ToString & Chr(13)
        Next
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oval, okey As Object
        okey = InputBox("Enter Key")
        oval = InputBox("Enter Value")
        htable.Add(okey, oval)
        RefreshLabel()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim okey As Object
        okey = InputBox("Enter Key to check")
        If htable.ContainsKey(okey) = True Then
            MsgBox("Key found")
        Else
            MsgBox("Not Found")
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim oval As Object
        oval = InputBox("Enter Key to check")
        If htable.ContainsValue(oval) = True Then
            MsgBox("Value found")
        Else
            MsgBox("Not Found")
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim okey As Object
        okey = InputBox("Enter Key to remove")
        htable.Remove(okey)
        RefreshLabel()
    End Sub
End Class

Contact us

Name

Email *

Message *