Theory
एक Job, दो Spellings
ShopKeeper को item names capitals में print करना ज़रूरी है। आप 2 seniors से पूछते हैं और 2 answers मिलते हैं:
UCase(item) कहता है वह senior जिसने classic VB सीखी।
item.ToUpper() कहता है वह जो BCA403 के Java से आया।
दोनों correct VB.NET हैं। Language ने अपनी classic function family रखी AND .NET method family पाई, क्योंकि String underneath System.String है। Catch: 2 families अलग तरह से गिनती हैं, और वही difference है जहाँ exam छुपता है।
At a glance
वही Job, दोनों Spellings
| Job | Classic Function (1-based) | .NET Method (0-based) |
|---|---|---|
| Length | Len(s) | s.Length |
| Capitals / Small | UCase(s), LCase(s) | s.ToUpper(), s.ToLower() |
| Slice | Mid(s, 5, 6) | s.Substring(4, 6) |
| Position ढूँढना | InStr(s, "Keep"): 0 = not found | s.IndexOf("Keep"): -1 = not found |
| Ends | Left(s, 4), Right(s, 4) | s.Substring with lengths |
| Spaces Clean करना | Trim(s) | s.Trim() |
Theory
Counting Mismatch, Precisely
s = "ShopKeeper" लीजिए (10 characters)।
Classic functions S को position 1 की तरह treat करते हैं: Mid(s, 5, 6) 5th character (K) से शुरू होता है और "Keeper" return करता है। InStr(s, "Keep") 5 answer देता है, और 0 का मतलब not found है।
.NET methods S को index 0 की तरह treat करते हैं, बिल्कुल BCA403 के Java जैसे: s.Substring(4, 6) भी "Keeper" return करता है। s.IndexOf("Keep") 4 answer देता है, और -1 का मतलब not found है।
वही slice, 2 coordinate systems, हमेशा के लिए exactly 1 से off।
Practical
एक Typed Item Clean करना, दोनों Styles
Module TextDemo
Sub Main()
Dim raw As String = " masala tea "
' Classic family
Dim t As String = Trim(raw) ' "masala tea"
MsgBox(UCase(Left(t, 6))) ' MASALA
MsgBox(InStr(t, "tea")) ' 8 (1-based)
' .NET method family, same results
Dim m As String = raw.Trim()
MsgBox(m.Substring(0, 6).ToUpper()) ' MASALA
MsgBox(m.IndexOf("tea")) ' 7 (0-based)
MsgBox(Replace(t, "tea", "chai")) ' masala chai
End Sub
End Module
Quiz
s = "ShopKeeper"। एक student Mid(s, 1, 4) लिखता है, दूसरा s.Substring(1, 4) लिखता है। उन्हें क्या मिलता है?
- दोनों को "Shop" मिलता है: calls equivalent हैं
- Mid "Shop" देता है, Substring "hopK" देता है: Mid 1 से गिनता है, Substring 0 से
- Mid "hopK" देता है, Substring "Shop" देता है: Mid 0 से गिनता है, Substring 1 से
- Substring एक error throw करता है: VB.NET strings सिर्फ़ classic functions support करते हैं
Show the answer
Mid "Shop" देता है, Substring "hopK" देता है: Mid 1 से गिनता है, Substring 0 से
Mid का position 1 first character HAI, तो वहाँ से 4 characters "Shop" spell करते हैं। Substring का index 1 SECOND character (h) है, तो यह "hopK" return करता है। Option C दोनों conventions को swap करता है, वही precise mistake जिसे catch करने के लिए यह question exist करता है: classic functions 1-based हैं, .NET methods 0-based। Option D इस पूरे lesson के point को भूल जाता है: एक VB.NET String System.String है, तो हर .NET method available है। जब marks इस पर depend करें, string को लिखिए और इसे दो बार number कीजिए, 1 से और 0 से।
Theory
Dates: Bill का दूसरा Column
हर ShopKeeper bill एक date रखता है, और 3 tools syllabus cover करते हैं:
- Now current date AND time है; Today सिर्फ़ date है
- DateAdd calendar arithmetic करता है:
DateAdd(DateInterval.Day, 7, Today)7-day return deadline है - DateDiff gaps measure करता है:
DateDiff(DateInterval.Day, billDate, Today)purchase के बाद से days गिनता है
Display के लिए, explicitly format कीजिए: Format(Today, "dd/MM/yyyy") या Today.ToString("dd/MM/yyyy"), क्योंकि एक unformatted date जिस भी style में till का Windows set हो उसमें print होता है।
Think first
Return-Window Check
एक bill 1 July 2026 को बना। Customer item 11 July 2026 को return करता है, और Mehta Stores 7 days allow करते हैं। अपने दिमाग़ में DateDiff(DateInterval.Day, billDate, returnDate) compute कीजिए और return पर rule कीजिए।
Show the answer
DateDiff पहली date से दूसरी तक के days गिनता है: 1 July से 11 July 10 days है, और 10 > 7, तो window बंद है: refused (politely)। Argument order नोटिस कीजिए, positive answer के लिए smaller-first: DateDiff(interval, earlier, later)। इन्हें swap कीजिए और आपको -10 मिलता है, और diff <= 7 जैसा एक naive check तब हर late return को ग़लती से APPROVE कर देता: एक one-line bug जो याद रखने लायक है, और exam snippets में एक favourite trick।
Watch out
3 Not-Found Answers
तीन अलग "कुछ नहीं मिला" signals अब आपके दिमाग़ में रहते हैं; इन्हें अलग रखिए:
InStr0 answer देता है (positions 1 से शुरू होते हैं, तो 0 not-found के लिए free है)IndexOf-1 answer देता है (indexes 0 से शुरू होते हैं, तो -1 free value है; BCA403 इससे सहमत था)Val("abc")0 answer देता है, जिसका मतलब है "कोई number नहीं मिला"
Absence के लिए If InStr(...) = -1 या If s.IndexOf(...) = 0 test करना दोनों ऐसे तरीकों से ग़लत हैं जो happily compile हो जाते हैं।
Theory
एक Project के लिए एक Family चुनिए
Professionals usually .NET methods पर settle होते हैं (वे हर दूसरी .NET language और BCA403 की habits से match करते हैं), पर इस paper के exams classic family को पसंद करते हैं, तो आपको दोनों fluently पढ़ना ज़रूरी है। ShopKeeper के लिए practical rule: code में methods, और जब कोई आपको answer sheets मार्क करने के लिए Mid और InStr देता है, बिना flinch किए 1 से गिनिए। अगला lesson code को organise करता है: Sub, Function, और arguments कैसे travel करते हैं।
Summary
Key takeaways
- VB.NET strings 2 families को answer देते हैं: classic functions (Len, UCase, Mid, InStr) और .NET methods (Length, ToUpper, Substring, IndexOf)।
- Classic functions positions 1 से गिनते हैं; .NET methods 0 से index करते हैं: Mid(s,1,4) = s.Substring(0,4)।
- Not-found: InStr 0 देता है, IndexOf -1 देता है: sentinels को कभी mix मत कीजिए।
- Now = date+time, Today = date; DateAdd एक date shift करता है, DateDiff(interval, earlier, later) gap measure करता है।
- Format(d, "dd/MM/yyyy") display control करता है; unformatted dates Windows regional settings follow करते हैं।
- Replace(s, old, new) दोनों families में text swap करता है।
- Memory hook: classic लोगों को गिनता है (1 से), .NET floors को गिनता है (0 से)।