Calculating Date Difference

When you need a code to calculate the date difference between 2 data either day, month, or year, the following example:

Fungsi : DateDiff( Interval Type, First Date, Second Date )

Jenis IntervalKeterangan
dDay (Hari)
mMonth (Bulan)
yyyyYear (Tahun)
hHour (Jam)

nMinute (Menit)
sSecond (Detik)
wwWeek (Minggu)
qQuater (4 Bulan)

Suppose you want to calculate the difference in days between the date of January 15, 2012 (written # 01/15/2012 #) and 20 Jan 2012, which means it will use a type of interval "d".t = DateDiff("d", #1/15/2012#, #1/20/2012#) , hasilnya 5
If the date obtained from controls such as the DateTimePicker, then the code:t = DateDiff("d", DateTimePicker1.Value, DateTimePicker2.Value)

Round Decimal Numbers

Many ways in VB to round a number / decimal numbers into integers. If you do not understand, here's a brief explanation:
  •      Automatic rounding
     Rounding is done automatically depending on the number is.
     If the primary number is odd and decimal numbers> = 0.5, then the rounding up (main numbers plus 1) and if the decimal number <0.5, then the rounding down.
     However, if the main number is 0 or even, and decimal numbers> 0.5, then the rounding up and when the decimal number <= 0.5, then the rounding down.
     i = CInt (0.4), the result is 0
     i = CInt (0.5), the result is 0
     i = CInt (0.6), the result 1
     i = CInt (1.4), the result 1
     i = CInt (1.5), the result is 2
     i = CInt (1.6), the result is 2
  •      Rounding Always Down
     Rounding is done is always down any decimal digit. In other words, would eliminate the decimal numbers.
     i = Int (1.1), the result 1
     i = Int (1.5), the result 1
     i = Int (1.8), the result 1
  •      Always rounding to the Top
     Rounding is done is always up regardless of decimal numbers.
     i =-Int (- (1.1)), the result is 2
     i =-Int (- (1.5)), the result is 2
     i =-Int (- (1.8)), the result is 2
  •      Rounding The Specified
     Rounding is done according to a predetermined limit.
     So if the decimal number> = limit then the rounding up and when the decimal number <limit then the rounding down.
     For example, the prescribed limit is 0.4 code like this:
  • Dim Nilai As Double, Hasil As Long

    Nilai = 1.4 'bilangan yg akan dibulatkan

    Hasil = Int(Nilai) + IIf(CDbl(CStr(Nilai - Int(Nilai))) >= 0.4, 1, 0) 'Batas = 0,4

    MsgBox Hasil 'pesan Hasil = 2

Reforming Child Form in MDI Form

If you're making project that uses MDI Form, there is good to add code to set the Child Form to make it look neat.
  • Cascade

    Kode :
    [ VB 6.0 ] Me.Arrange vbCascade
    [ VB .NET ] Me.LayoutMdi(MdiLayout.Cascade)

  • Tile Horizontal

    Kode :
    [ VB 6.0 ] Me.Arrange vbTileHorizontal
    [ VB .NET ] Me.LayoutMdi(MdiLayout.TileHorizontal)

  • Tile Vertical

    Kode :
    [ VB 6.0 ] Me.Arrange vbTileVertical
    [ VB .NET ] Me.LayoutMdi(MdiLayout.TileVertical)


To facilitate the user to use it, you can create a special menu like this:

Application Block Websites

This is an application used to block or blocking pulled Computer to access the website / specific sites of the Browser.

Pinger apps

As the name implies, this application is useful to ping the website. This application is also useful for stabilizing a weak internet connection.

ListBox can be in Edit


In order for the items contained in the ListBox can be edited, it would require a special way by combining it with the TextBox. Here's how:

    1. Add 1 ListBox, then 1 TextBox (property Visible = False) to the Form.
    1. Type this code in the event ListBox1_MouseDoubleClick:
      Dim i As Integer = ListBox1.SelectedIndex
      If i < 0 Then Exit Sub

      With TextBox1
        .Top = ListBox1.GetItemRectangle(i).Top + ListBox1.Top
        .Left = ListBox1.GetItemRectangle(i).Left + ListBox1.Left

        .Text = ListBox1.Items(i)
        .Visible = True
        .Focus()
      End With

    2. Type This code in event TextBox1_KeyPress :
      If e.KeyChar = Chr(Keys.Enter) Then
        ListBox1.Items(ListBox1.SelectedIndex) = TextBox1.Text
        TextBox1.Visible = False
      ElseIf e.KeyChar = Chr(Keys.Escape) Then
        TextBox1.Visible = False
      End If

    3. Type This code in event TextBox1_LostFocus :
      TextBox1.Visible = False

    4. For the experiment, you can fill out the items by typing in this code in event Form1_Load :
      Dim i As Integer
      For i = 1 To 100
        ListBox1.Items.Add("Item ke " & i)
      Next
    Run the application, and then double-click the item to be edited.

    Detect the version of MS Office

    The easiest way to detect the version of MS Office that are installed on the computer, that is by reading the registry value. Here's the code:

    Write the function code in the new module:
    Function VersiOffice(ByVal Aplikasi As String) As String
        On Error GoTo Ero
        Dim Reg As Object
        Dim s As String
          
        Set Reg = CreateObject("Wscript.Shell")
        s = Reg.RegRead("HKCR\" & Aplikasi & ".Application\CurVer\")
        VersiOffice = Replace(s, Aplikasi & ".Application.", "", , , 1)
      
    Ero:
    End Function

    Use code like this:
    Dim v As String
    v = VersiOffice("Word")
    If v <> "" Then
        MsgBox ("Microsoft Word versi " & v)
    Else
        MsgBox ("Microsoft Word tidak ter-install")
    End If

    Can be seen in the example above is used to detect the Word, then it can also be used to Excel, PowerPoint, Access, etc.

    Progress on the Taskbar


    Cara menambahkan Progress di Taskbar ini hanya bisa diterapkan pada Windows 7 menggunakan VB .NET. Library yang digunakannya adalah WindowsAPICodePack.

    Pressing the button with code

    Here's how to push Button / Button using code, so without doing click using the mouse pointer.

    Write the following code in the event '(Declarations)' of Form


    [VB 6.0]
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    [VB.Net]
    Private Declare Function SendMessage Lib"user32.dll" Alias "SendMessageA"(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As Object) As Integer

    Const WM_LBUTTONDOWN = &H201
    Const WM_LBUTTONUP = &H202
    Now for practice use code like the following:
    [VB 6.0]
    SendMessage Command1.hwnd, &HF3, 1, 0
    Sleep 150
    SendMessage Command1.hwnd, &HF3, 0, 0

    Command1.Value = True 
    [VB.Net]
    SendMessage(Button1.Handle, WM_LBUTTONDOWN, 0, 0)
    Application.DoEvents()
    Threading.Thread.Sleep(150)
    SendMessage(Button1.Handle, WM_LBUTTONUP, 0, 0)

    Button1.PerformClick()

    Visual Styler


    Visual Styler is a control that is used to change the appearance of the form and its controls in it. The interface can be changed to such Office, Mac, or Vista.

    Its use is very easy, you just add the control to the Form Visual Styler. Then select the desired view in VisualStyle his property. After that save the Project to make changes.

    EDraw Office Viewer



    Edraw Office Viewer is used to help control displays office files Word, Excel, PowerPoint into a Form.

    Web Search Applications


    This application is a simple application that was made to make it easier for internet users in the internet web pecarian like using Google, Yahoo, Bing, etc.

     
    Support : Creating Website | Johny Template | Mas Template
    Copyright © 2011. Sanjaya Catur Blogging - All Rights Reserved
    Template Modify by Creating Website
    Proudly powered by Blogger