Lessons in this course (12)

11. The My namespace, Microsoft.VisualBasic helpers and late binding

AdvancedMediumLesson 11 of 12
vb
Dim userName = My.User.Name                       ' current Windows user
Dim content = My.Computer.FileSystem.ReadAllText("a.txt")
My.Settings.LastOpened = Date.Now : My.Settings.Save()    ' WinForms settings
Dim conn = My.Settings.ShopConnectionString

' Classic VB functions from Microsoft.VisualBasic
Dim first3 = Left("Divakar", 3)                  ' "Div"  (= "Divakar".Substring(0, 3))
Dim mid = Mid("Divakar", 2, 3)                   ' "iva"  (1-based!)
Dim len = Len("Divakar")
If IsNumeric(input) Then ...
Dim answer = MsgBox("Save changes?", MsgBoxStyle.YesNo)   ' WinForms only

Late binding (Option Strict Off): calling members on an Object resolved at runtime — used historically for COM/Office automation (CreateObject("Excel.Application")). With Option Strict On use proper types or dynamic-like patterns via interop assemblies.

1-based vs 0-based: classic functions (Mid, InStr) are 1-based; .NET methods (Substring, IndexOf) are 0-based — a common bug source when mixing them.