Creating Customized Dialog Boxes with User Form Objects in Hindi
Makhanlal Chaturvedi University / BCA / VBA programming
Creating Customized Dialog Boxes with User Form Objects in Hindi
Table of Contents
- Creating Customized Dialog Boxes with User Form Objects in Hindi
- Introduction to User Form Objects for Customized Dialog Boxes in Hindi
- Using Command Buttons in User Forms in Hindi
- Adding and Configuring List and Combo Boxes in User Forms in Hindi
- Using Labels, Option Buttons, and Check Boxes in User Forms in Hindi
Creating Customized Dialog Boxes with User Form Objects in Hindi
Introduction to User Form Objects for Customized Dialog Boxes
User Form Object एक ऐसा powerful tool है जो Microsoft Excel जैसे applications में Customized Dialog Box बनाने में मदद करता है। इसका उपयोग हम तब करते हैं जब हमें user से input लेना होता है, जैसे कोई form भरवाना, किसी list में से option चुनवाना या किसी button को click करवा कर कोई काम करवाना।
User Form एक Graphical Interface (GUI) प्रदान करता है जिसमें हम Labels, TextBox, ComboBox, ListBox, Option Button, CheckBox, और Command Button जैसे elements को जोड़ सकते हैं। इन सभी को collectively Controls कहा जाता है। इन controls को customize करके हम अपने हिसाब से Dialog Box तैयार कर सकते हैं।
Using Command Buttons in User Forms
Command Button User Form का एक मुख्य हिस्सा होता है। इसकी मदद से हम user द्वारा किए गए actions को control कर सकते हैं। जैसे कोई button दबाने पर form submit हो, clear हो, या close हो जाए।
- Command Button को Insert करने के लिए VBA Editor में जाएं, Toolbox में से "CommandButton" को UserForm पर drag करें।
- इस button का नाम और caption आप Properties window से बदल सकते हैं।
- इस button पर click करने पर क्या होना चाहिए, यह आप उसके click event में कोड लिखकर तय कर सकते हैं।
Private Sub CommandButton1_Click()
MsgBox "Form Submitted Successfully!"
End Sub
Adding and Configuring List and Combo Boxes in User Forms
ListBox और ComboBox दोनों का प्रयोग तब किया जाता है जब हमें user को predefined options देना हो। फर्क यह है कि ListBox में सारे options एक साथ दिखाई देते हैं जबकि ComboBox में dropdown menu होता है।
- Toolbox में से ListBox या ComboBox select करें और UserForm पर place करें।
- Properties window में जाकर उसका नाम, font, size आदि बदल सकते हैं।
- Option जोड़ने के लिए initialize event या manually कोड से भी जोड़ सकते हैं।
Private Sub UserForm_Initialize()
ComboBox1.AddItem "Option 1"
ComboBox1.AddItem "Option 2"
ListBox1.AddItem "Item A"
ListBox1.AddItem "Item B"
End Sub
जब user कोई option select करता है, तो आप उस value को process करने के लिए नीचे जैसा कोड लिख सकते हैं:
Private Sub CommandButton1_Click()
MsgBox "You selected: " & ComboBox1.Value
End Sub
Using Labels, Option Buttons, and Check Boxes in User Forms
Labels
- Label का प्रयोग जानकारी दिखाने के लिए किया जाता है जैसे - "Enter Name:"
- Label सिर्फ दिखाने का काम करता है, इसमें user input नहीं कर सकता।
Option Buttons
- Option Button का प्रयोग तब होता है जब आपको user से एक विकल्प चुनवाना हो।
- सिर्फ एक Option एक समय में select किया जा सकता है।
- उदाहरण: Gender - Male / Female
If OptionButton1.Value = True Then
MsgBox "You selected Male"
ElseIf OptionButton2.Value = True Then
MsgBox "You selected Female"
End If
Check Boxes
- Check Box का प्रयोग तब होता है जब एक से अधिक विकल्प चुने जा सकते हों।
- उदाहरण: Hobbies - Reading, Dancing, Singing
Dim hobbies As String
If CheckBox1.Value = True Then hobbies = hobbies & "Reading "
If CheckBox2.Value = True Then hobbies = hobbies & "Dancing "
If CheckBox3.Value = True Then hobbies = hobbies & "Singing "
MsgBox "You selected: " & hobbies
Additional Important Concepts
TextBox का प्रयोग
- TextBox में user कोई text या number type कर सकता है।
- Input को validate करने के लिए हम इसके Text property का use करते हैं।
If TextBox1.Text = "" Then
MsgBox "Please enter your name"
Else
MsgBox "Welcome " & TextBox1.Text
End If
Form Initialization
जब भी UserForm खुलता है, तो उसमें पहले से values या default settings set करने के लिए UserForm_Initialize() event का उपयोग होता है।
Form को Show और Hide करना
Form को show करने के लिए आप module में नीचे जैसा कोड लिख सकते हैं:
Sub ShowMyForm()
UserForm1.Show
End Sub
Form को close करने के लिए:
Unload Me
Form Validation और Error Handling
- Form validation का मतलब है user द्वारा गलत data input को रोकना।
- उदाहरण: कोई TextBox खाली न हो, या उम्र 0 से ज्यादा हो।
If IsNumeric(TextBox2.Text) = False Then
MsgBox "Please enter a valid number"
Exit Sub
End If
Useful Properties Table
| Control | Property | Purpose |
|---|---|---|
| TextBox | Text | User द्वारा डाला गया text |
| ComboBox | Value | Selected item |
| ListBox | List | सभी items की list |
| CommandButton | Caption | Button पर दिखाई देने वाला text |
Final Practical Example
एक simple form जिसमें Name TextBox, Gender OptionButtons, और Submit Button होगा:
Private Sub CommandButton1_Click()
Dim name As String, gender As String
name = TextBox1.Text
If OptionButton1.Value = True Then gender = "Male"
If OptionButton2.Value = True Then gender = "Female"
MsgBox "Name: " & name & vbNewLine & "Gender: " & gender
End Sub
FAQs
If OptionButton1.Value = True Then
MsgBox "You selected Male"
End If
If TextBox1.Text = "" Then
MsgBox "Please enter your name"
End If
Sub ShowForm()
UserForm1.Show
End Sub