[VB.NET] Quick Refference Syntax


Description
      Here's quick refference syntax that i already use , and it's always update.

How To

IF - ELSE
if <exp> then
     'to do here
else
     'to do here
end if
example :
if i = true then
     msgbox "yes"
else
     msgbox "no"
end if


FOR - NEXT
for <var initialize> <condition>
     'to do here
next <var initialize>
example :
for i = 1 to 5
     msgbox(i)
next i


WHILE
while <expression>
     'to do here
end while
example :
while i = 5
     msgbox "yes"
end while


DO-WHILE-LOOP
do
     'to do here
loop while <expression>
example
do
     msgbox "yes"
loop while i = 5


SELECT - CASE
select <expression>
case <expression>
      'to do here
case default
      ' if not match any case
end select
example
select number
case "1"
      msgbox " yes"
case default
      msgbox "no"
end select


*get path current application
My.Application.Info.DirectoryPath & "\SQLServer.udl"

*playing sound
Imports System.Media.SoundPlayer
Dim Sound As New System.Media.SoundPlayer()
Sound.SoundLocation = My.Application.Info.DirectoryPath & "\Sound\tick.wav"
Sound.Load()
Sound.Play()

*format string (add some string), for example i want format string like this "000005" (convert from int)
.ToString().PadLeft(5, "0")

*get datetime now , with custom format
DateTime.Now.ToString("MM/dd/yyyy")

*set variable constant
Public Const IP_DB_SQLSERVER As String = "1x.xx.xx.xx"

*remove space
trim("this is space") 'the result : "thisisspace"

*Escape string
 Uri.EscapeDataString("string")

*Set Regional Setting to standart - it's affect date time
Imports System.Threading
Imports System.Globalization
    Public Sub regionalSetting()
        ' Sets the culture to US (en-US)
        Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
        ' Sets the UI culture to US (en-US)
        Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-US")
    End Sub

*Set oracle Language (Datetime) - it's affect date time in Oracle Database
Imports Microsoft.Win32
Public Sub oraNLSLangReg()
        Dim regKey As RegistryKey
        Dim backupVal As String

        'reading
        regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\ORACLE\KEY_OraClient10g_home1", False)

        If regKey.GetValue("NLS_LANG") = "AMERICAN_AMERICA.WE8ISO8859P1" Then
            'no need for edit
        Else
            ' need for setting but backup first
            backupVal = regKey.GetValue("NLS_LANG")
            regKey.Close()
            regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\ORACLE\KEY_OraClient10g_home1", True)
            regKey.SetValue("BACKUP_NLS_LANG", backupVal)
            regKey.SetValue("NLS_LANG", "AMERICAN_AMERICA.WE8ISO8859P1")
            regKey.Close()
        End If
    End Sub

Note : if you have any quick refference that you think is important , just comment below .... i will add in this article, thank you.

Post a Comment

Harap gunakan bahasa yang baik dan sopan, terima kasih