Wednesday, May 26, 2010

How to Create, Copy, Move, Rename, Delete File or Directory VB.net or Visual Basic

Hello and welcome to another cool vb.net tutorial. Today in this tutorial i will be teaching u all how to use the Directory or File Operations in Vb.net or Visual Basic



Requirements:
4 Timers (Name: Timer1, Timer2, Timer3, Timer4) (Interval: 150, 1000, 1000, 1000)
1 Label (Name: Label1) (Text: Status.)
8 Buttons (Name: Button1, Button2, Button3,Button4, Button5, Button6, Button7, Button8)(Text: Create Directory, Move Directory, Delete Directory, Create File, Copy File, Delete File, Rename File)

Codes:

Imports System.IO
Public Class Form1

Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
Timer1.Enabled = True
Timer2.Enabled = True
Timer3.Enabled = True
Timer4.Enabled = True
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = "Status"
Timer1.Enabled = False
Timer2.Enabled = True
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Label1.Text = "Status."
Timer2.Enabled = False
Timer3.Enabled = True
End Sub

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Label1.Text = "Status.."
Timer3.Enabled = False
Timer4.Enabled = True
End Sub

Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
Label1.Text = "Status..."
Timer4.Enabled = False
Timer1.Enabled = True
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim path As String = "c:\test"
If Directory.Exists(path) Then
Directory.Delete(path)
Label1.Text = "Directory Deleted Successfully"
Else
Label1.Text = "Directory Not Found"
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
If Not Directory.Exists("c:\test") = True Then
Label1.Text = "Directory Does Not Exist..Program will now create a Directory..!"
Directory.CreateDirectory("c:\test\")
Label1.Text = "Directory Created Successfully"
Else
Label1.Text = "Directory Already Exist..!"
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Dim destination As String = "c:\hello"
Dim path As String = "c:\test"
If Directory.Exists(destination) Then
Label1.Text = "Folder with same name already exist in the destination "
ElseIf Directory.Exists(path) Then
Directory.Move(path, destination)
Label1.Text = "Directory Moved Successfully"
Else
Label1.Text = "Directory Already Exist in the location specified"
End If
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Dim oldname As String = "c:\hello"
Dim newname As String = "c:\Subscribe"
If Directory.Exists(oldname) And Not Directory.Exists(newname) Then
Directory.Move(oldname, newname)
Label1.Text = "Renaming was Successfull"
Else
Label1.Text = "There is folder already with same name in the Directory"
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Dim filetocreate As String = "c:\test.txt"
If Not File.Exists(filetocreate) Then
File.Create(filetocreate)
Label1.Text = "File Created Successfully"
Else
Label1.Text = "File Already Exist"
End If
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Dim path As String = "c:\test.txt"
Dim destination As String = "c:\Subscribe\test.txt"
If File.Exists(path) And Not File.Exists(destination) Then
File.Copy(path, destination)
Label1.Text = "File Copied Successfully"
Else
Label1.Text = "There is already a file called test.txt in the Destination Folder"
End If
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Dim filetodelete As String = "c:\test.txt"
If File.Exists(filetodelete) Then
File.Delete(filetodelete)
Label1.Text = "File Deleted Successfully"
Else
Label1.Text = "File Not Found"
End If
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Dim oldname As String = "c:\Subscribe\test.txt"
Dim newname As String = "c:\Subscribe\Subscribe Please.txt"
If File.Exists(oldname) And Not File.Exists(newname) Then
File.Move(oldname, newname)
Label1.Text = "Renaming Was Successfull"
Else
Label1.Text = "File Already Exist with the same name"
End If
End Sub

End Class


Here is the video tutorial:



Sunday, May 23, 2010

Timespan Tutorial - Calculate the Date and Time Difference Between 2 Dates or Times Visual Basic {VB.net}

Hello and welcome to another cool VB.net tutorial by MrVBDude.!!!

Alright today i will be teaching u all how to calculate the time or date difference between two dates of two times.. ok so lets begin..!

REQUIREMENTS:
8 Labels (Name: Label1-Label8) (Text: StartDate, End Date, Start Time, End Time, Total Number of Days, Total Number of Hours, Total Number of Minutes, Total Number of Seconds)
2 DateTimePicker (Name: DateTimePicker1, DateTimePicker2)
8 Textbox (Name: Textbox1-Textbox8) (Text: " ")
1 Button (Name: Button1) (Text: Find Timespan (Time Difference) between 2 dates?)

Codes:

Public Class Form1

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim date1 As Date
Dim date2 As Date
Dim difference As TimeSpan
date1 = Convert.ToDateTime(DateTimePicker1.Value)
date2 = Convert.ToDateTime(DateTimePicker2.Value)
difference = date2.Subtract(date1)
TextBox3.Text = FormatNumber(difference.Days, 0)
TextBox6.Text = FormatNumber(difference.TotalHours, 0)
TextBox5.Text = FormatNumber(difference.TotalMinutes, 0)
TextBox4.Text = FormatNumber(difference.TotalSeconds, 0)

End Sub

End Class
_________________________________________________________________________

Here is the video tutorial:

Sunday, May 16, 2010

ProgressBar Visual Basic {VB.net} Detailed Tutorial

Hello and welcome to another tutorial on vb.net. Today in this tutorial i will be teaching u all how to use the progressbar component in visual basic 2005, 2008, 2010.

Requirements:
2 ProgressBar - ProgressBar1, ProgressBar2
1 Label - Label1
4 Buttons (|<<,<<,>>,>>|)

Codes:

Public Class Form1

Dim myprogress As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ProgressBar1.Style = ProgressBarStyle.Marquee
ProgressBar2.Style = ProgressBarStyle.Continuous
ProgressBar2.Step = 1
Timer1.Enabled = True
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 100
ProgressBar1.Value = 0
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If ProgressBar1.Value <>
ProgressBar1.Value += 5
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If ProgressBar1.Value > 0 Then
ProgressBar1.Value -= 5
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ProgressBar1.Value = 100
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ProgressBar1.Value = 0
End Sub

Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
If e.Delta > -1 Then
If ProgressBar1.Value <>
ProgressBar1.Value += 5
End If
Else
If ProgressBar1.Value > 0 Then
ProgressBar1.Value -= 5
End If
End If
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar2.Value = myprogress
If myprogress < myprogress =" myprogress">
Label1.Text = "Installing = " & myprogress & "%"
If myprogress = 100 Then
Label1.Text = "Complete"
ProgressBar1.Style = ProgressBarStyle.Continuous
ProgressBar1.Value = 0
Timer1.Enabled = False
End If
End Sub
End Class
_________________________________________________________________________

Here is the video tutorial:




Thursday, May 6, 2010

Hit Enter to Activate a Button Tutorial Visual Basic {VB.net}

Hello and welcome people to another VB.net tutorial. Today in this video tutorial i will be showing u all how to activate or enable or press button when the enter key is pressed on the keyboard.


REQUIREMENTS:

A button
A textbox

Codes:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(TextBox1.Text, vbInformation, "MrVBDude")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AcceptButton = Button1
End Sub

End Class_________________________________________________________________________

Here is the video tutorial:

Saturday, May 1, 2010

Format Date and Time Detailed Tutorial Visual Basic {VB.net}

Hi all today i will be showing u all how to format date and time in VB.net.

First of all add one label, 5 timers and 5 buttons to your project.
And then watch the video and images carefully to understand how the form is setup.


Codes:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer5.Enabled = False
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = TimeOfDay
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer5.Enabled = False
Timer2.Enabled = True
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Label1.Text = Format(TimeOfDay, "h:mm:ss tt")
End Sub


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer4.Enabled = False
Timer5.Enabled = False
Timer3.Enabled = True
End Sub

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick

Label1.Text = DateTime.Now.Date
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer5.Enabled = False
Timer4.Enabled = True
End Sub

Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
Label1.Text = Format(DateTime.Now.Date, "MM/dd/yy")
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer4.Enabled = False
Timer3.Enabled = False
Timer5.Enabled = True
End Sub

Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
Label1.Text = Format(DateTime.Now, "dd/MM/yyyy")
End Sub

End Class
_________________________________________________________________________

Here is the detailed video tutorial (Voice):