User Defined Functions in Hindi
Makhanlal Chaturvedi University / BCA / VBA programming
User Defined Functions in Hindi
User Defined Functions in Hindi
What are User Defined Functions and why use them in Hindi
जब हम किसी प्रोग्रामिंग लैंग्वेज जैसे Python, JavaScript या Excel VBA में काम करते हैं, तो वहाँ कई बार कुछ कोड बार-बार लिखने की ज़रूरत पड़ती है। ऐसे समय में अगर हम हर बार वही कोड कॉपी-पेस्ट करें तो समय भी ज़्यादा लगता है और प्रोग्राम भी बहुत बड़ा और उलझा हुआ हो जाता है। इसी समस्या का हल होता है – User Defined Functions (यूज़र डिफाइंड फ़ंक्शन)।
User Defined Functions वे फ़ंक्शन होते हैं जो हम खुद अपने उपयोग के लिए बनाते हैं। ये फ़ंक्शन किसी भी टास्क को बार-बार करने के लिए बनाए जाते हैं ताकि उस टास्क को हर जगह दोहराने की ज़रूरत न हो, बस फ़ंक्शन को कॉल करें और काम हो जाए। ये हमें कोड को re-use करने, readable बनाने और manage करने में बहुत मदद करते हैं।
Syntax and structure of User Defined Functions in Hindi
User Defined Functions बनाने का सिंटैक्स (structure) बहुत ही सरल होता है। नीचे एक बेसिक structure बताया गया है:
Function FunctionName(Parameter1, Parameter2, ...)
' यहाँ पर function की body होती है
FunctionName = ReturnValue
End Function
- Function: ये कीवर्ड हमें बताता है कि हम एक function डिक्लेयर कर रहे हैं।
- FunctionName: ये आपके function का नाम होता है जो आप खुद रख सकते हैं जैसे – AddNumbers, GetArea आदि।
- Parameters: ये वो values होती हैं जो आप function को input के रूप में देते हैं।
- ReturnValue: ये वो result होता है जो function process करने के बाद वापस देता है।
ध्यान दें कि function को End Function से बंद करना होता है।
Creating your first User Defined Function in Hindi
अब हम एक सिंपल example से अपना पहला User Defined Function बनाएँगे। मान लीजिए हमें दो numbers को जोड़ना है और बार-बार ये task perform करना है। ऐसे में हम एक छोटा सा function बना सकते हैं:
Function AddNumbers(a, b)
AddNumbers = a + b
End Function
ऊपर दिए गए function में हमने दो parameters लिए हैं a और b और उनका जोड़ AddNumbers के ज़रिए return किया है। जब भी हम AddNumbers(5, 10) लिखेंगे तो इसका output 15 आएगा।
Calling and reusing User Defined Functions in Hindi
User Defined Functions का main उद्देश्य यही होता है कि हम किसी भी task को बार-बार आसानी से कर सकें। इसको call करना बहुत आसान है। जब आप function एक बार define कर लेते हैं, उसके बाद आप उसे कहीं भी कॉल कर सकते हैं। जैसे:
Sub TestAddition()
Dim result
result = AddNumbers(10, 20)
MsgBox "Addition Result is: " & result
End Sub
ऊपर दिए गए example में हमने AddNumbers function को TestAddition नाम के Subroutine के अंदर call किया है और MsgBox से result को display भी किया है।
Advantages of Using User Defined Functions in Hindi
- Reusability: एक बार function बना लेने के बाद उसे कहीं भी इस्तेमाल किया जा सकता है।
- Readability: प्रोग्राम ज़्यादा readable और समझने में आसान होता है।
- Modular Programming: बड़े प्रोग्राम को छोटे-छोटे blocks में divide किया जा सकता है।
- Debugging आसान होती है: अगर कोई गड़बड़ी हो तो हम उसी function में जाकर उसे सुधार सकते हैं।
Types of User Defined Functions in Hindi
User Defined Functions को उनके behavior के अनुसार भी classify किया जा सकता है:
| Function Type | Explanation (in Hindi) |
|---|---|
| Parameterised Function | इसमें values input के रूप में दी जाती हैं और उसी पर आधारित output मिलता है। |
| Non-Parameterised Function | इसमें कोई भी input parameter नहीं लिया जाता, सिर्फ fix code run होता है। |
| Return Type Function | ये function कोई value return करता है जिसे हम आगे इस्तेमाल कर सकते हैं। |
| Void Function (Subroutine) | ये कोई value return नहीं करता, बस कोई task perform करता है। |
Best Practices while creating User Defined Functions in Hindi
- Function का नाम meaningful रखें जैसे – CalculateSalary, GetDiscountAmount आदि।
- Comments लिखें ताकि दूसरों को भी समझ आ सके कि function क्या कर रहा है।
- Function को छोटा और specific रखें ताकि वो सिर्फ एक ही काम करें।
- Error Handling ज़रूरी हो तो function के अंदर करें, ताकि गलत input आने पर सही message मिल सके।
Example: User Defined Function with Condition in Hindi
मान लीजिए हम एक ऐसा function बनाना चाहते हैं जो किसी number को even या odd check करे:
Function CheckEvenOdd(n)
If n Mod 2 = 0 Then
CheckEvenOdd = "Even"
Else
CheckEvenOdd = "Odd"
End If
End Function
जब आप CheckEvenOdd(7) लिखेंगे तो यह output देगा "Odd" और CheckEvenOdd(8) पर output होगा "Even"।
Where to use User Defined Functions in Hindi
- जब किसी calculation को बार-बार perform करना हो।
- जब कोई logic बार-बार use करना हो जैसे – tax calculation, discount, EMI आदि।
- जब आप अपने code को छोटे और समझने लायक blocks में बाँटना चाहते हैं।
- जब आप Excel VBA, Python, JavaScript जैसे भाषाओं में बड़े project बना रहे हों।
Final Thought on User Defined Functions in Hindi
User Defined Functions एक programmer के लिए बहुत ही powerful और उपयोगी feature है। ये हमें अपने code को structured, readable और efficient बनाने में बहुत मदद करता है। Beginner programmers को शुरू से ही functions का उपयोग करना सीखना चाहिए ताकि वो भविष्य में बड़े projects को भी आसानी से manage कर सकें। इनका सही उपयोग करने से आप अपने प्रोग्राम को simple, reusable और smart बना सकते हैं।
FAQs
Function FunctionName(Parameter1, Parameter2)
FunctionName = Result
End Functionइसमें function का नाम, parameters और return value शामिल होते हैं।
result = AddNumbers(5, 10)इससे function execute होकर result return करता है।
MyFunction = a + b