Thursday, July 4, 2013

Calculate your BOD


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = ""
        Dim strYear() As String = {"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snack", "Horse", "Goat", "Monkey", "Chicken", "Dog", "Pig"}
        Dim strDOB As String = MaskedTextBox1.Text
        Dim intAge As Integer = Math.Floor(DateDiff(DateInterval.Month, DateValue(strDOB), Now()) / 12)
        Label1.Text = "Age : " & intAge

        Dim thisDate1 As Date = MaskedTextBox1.Text
        Label4.Text = "Date is " + thisDate1.ToString("MMMM dd, yyyy") + "."

        Dim value1 As String = ""
        Dim y As Integer = thisDate1.ToString("yyyy")
        Dim x As Integer = (1901 - y) Mod 12
        If x = 1 Or x = -11 Then
            value1 = strYear(0)
        ElseIf x = 0 Then
            value1 = strYear(1)
        ElseIf x = 11 Or x = -1 Then
            value1 = strYear(2)
        ElseIf x = 10 Or x = -2 Then
            value1 = strYear(3)
        ElseIf x = 9 Or x = -3 Then
            value1 = strYear(4)
        ElseIf x = 8 Or x = -4 Then
            value1 = strYear(5)
        ElseIf x = 7 Or x = -5 Then
            value1 = strYear(6)
        ElseIf x = 6 Or x = -6 Then
            value1 = strYear(7)
        ElseIf x = 5 Or x = -7 Then
            value1 = strYear(8)
        ElseIf x = 4 Or x = -8 Then
            value1 = strYear(9)
        ElseIf x = 3 Or x = -9 Then
            value1 = strYear(10)
        Else
            If x = 2 Or x = -10 Then
                value1 = strYear(11)
            End If
        End If

        Label1.Text = "Date is " + thisDate1.ToString("MMMM dddd") + " " + value1 + " Year."
    End Sub
End Class

Tuesday, June 18, 2013

Create your own download manager by VB.net


Imports System.Net

Public Class Form1
    
Public WithEvents Download As New WebClient
    
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        FolderBrowserDialog1.ShowDialog()
        LbSaveAddress.Text = FolderBrowserDialog1.SelectedPath
        Download = New WebClient
        Download.DownloadFileAsync(New Uri(txtURL.Text), LbSaveAddress.Text + "\" + txtSaveFileName.Text)

    End Sub

    Private Sub Download_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles Download.DownloadProgressChanged
        Button1.Text = "Downloading"
        ProgressBar1.Value = e.ProgressPercentage
        Label2.Text = e.ProgressPercentage & "%"
    End Sub

    Private Sub txtURL_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtURL.MouseDown
        txtSaveFileName.Text = "Default.exe"
    End Sub
End Class


Monday, June 17, 2013

Create Easy Print by VB.net




Public Class FrmEasyPrint

    Private Sub cmdFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFont.Click
        Dim font_dialog As New FontDialog
        If font_dialog.ShowDialog() = DialogResult.OK Then
            TextBox1.Font = font_dialog.Font
        End If
    End Sub

    Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
        If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PrintDocument1.Print()
        End If
    End Sub

    Private Sub cmdPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrintPreview.Click
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim FontText As Font
        FontText = TextBox1.Font
        e.Graphics.DrawString(TextBox1.Text, FontText, New SolidBrush(Color.Black), 10, 10)
    End Sub
End Class

Create your own Email sending by VB.net



Imports System.Net.Mail
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim EmailMessage As New MailMessage()
        Try
            EmailMessage.From = New MailAddress(txtFrom.Text)
            EmailMessage.To.Add(txtTo.Text)
            EmailMessage.Subject = txtSub.Text
            EmailMessage.Body = txtMessage.Text
            Dim SMTP As New SmtpClient("smtp.gmail.com")
            SMTP.Port = 587
            SMTP.EnableSsl = True
            SMTP.Credentials = New System.Net.NetworkCredential(txtFrom.Text, "YourEmailPassword")
            SMTP.Send(EmailMessage)
            MsgBox("Message has been send to," & txtTo.Text & " Successfully!")
        Catch ex As Exception
            MsgBox("Sending Fail")
        End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtFrom.Text = "YourEmail"
    End Sub
End Class

Create Notepad by VB.net



Public Class Form1

    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
        RichTextBox1.Clear()
    End Sub

    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        Try
            Dim dlg As OpenFileDialog = New OpenFileDialog
            dlg.Title = "Open"
            dlg.Filter = "Rich Text Files (*.rtf)|*.rtf"
            If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
                RichTextBox1.LoadFile(dlg.FileName)
            End If
        Catch ex As Exception
            MsgBox("Open File Error")
        End Try
    End Sub

    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        Try
            Dim dlg As SaveFileDialog = New SaveFileDialog
            dlg.Title = "Save"
            dlg.Filter = "Rich Text Files (*.rtf)|*.rtf"
            If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
                RichTextBox1.SaveFile(dlg.FileName, RichTextBoxStreamType.RichText)
            End If
        Catch ex As Exception
            MsgBox("Error to save file!")
        End Try
    End Sub

    Private Sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem.Click
        RichTextBox1.Undo()
    End Sub

    Private Sub RedoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedoToolStripMenuItem.Click
        RichTextBox1.Redo()
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click
        RichTextBox1.Cut()
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
        RichTextBox1.Copy()
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click
        RichTextBox1.Paste()
    End Sub

    Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
        RichTextBox1.Clear()
    End Sub

    Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click
        RichTextBox1.SelectAll()
    End Sub

    Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
        Try
            Dim dlg As FontDialog = New FontDialog
            dlg.Font = RichTextBox1.Font
            If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
                RichTextBox1.Font = dlg.Font
            End If
        Catch ex As Exception
            MsgBox("Erro Font")
        End Try
    End Sub

    Private Sub ColourToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColourToolStripMenuItem.Click
        Try
            Dim dlg As ColorDialog = New ColorDialog
            dlg.Color = RichTextBox1.ForeColor
            If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
                RichTextBox1.ForeColor = dlg.Color
            End If
        Catch ex As Exception
            MsgBox("Erro Color")
        End Try
    End Sub
End Class

Event sharing IT experiences


Register: https://www.facebook.com/events/144561725733472/?ref=2
Website: http://www.cita.asia/en/