Wednesday, July 13, 2011

[VB.net] Structure, Arraylist and Combination {Detailed Tutorial}. Part -1/2

Hi all,

In this tutorial, you will learn almost everything about Structures, Arraylist and how to use the combination of both to get the best results. I am also gonna be teaching how to save and reload an arraylist.

Structures

Structures is basically a tool for handling a group of logically related data items or field. Structures are very similar to classes. The main difference between classes and structures is that structures are value type and classes are reference type.

Difference between Value and Reference Type:-

I can't explain better than this website.

"Reference types are stored on the run-time heap; they may only be accessed through a reference to that storage. This allows the garbage collector to track outstanding references to a particular instance and free the instance when no references remain. A variable of reference type always contains a reference to a value of that type or a null reference. A null reference refers to nothing; it is invalid to do anything with a null reference except assign it. Assignment to a variable of a reference type creates a copy of the reference, not a copy of the value being referenced.

Value types are stored directly on the stack, either within an array or within another type. When the location containing a value type instance is destroyed, the value type instance is also destroyed. Value types are always accessed directly; it is not possible to create a reference to a value type. Prohibiting such a reference makes it impossible to refer to a value class instance that has been destroyed. A variable of a value type always contains a value of that type. Unlike reference types, the value of a value type cannot be a null reference, nor can it reference an object of a more derived type. Assignment to a variable of a value type creates a copy of the value being assigned."

Source: http://www.dotnetspider.com/resources/1479-Difference-between-reference-Linktype-value-type.aspx

Codes:

Public Class Form1
Dim inc As Integer = 0
Dim emp(inc) As employee

Structure employee
Dim EmpName As String
Dim EmpId As Integer
Dim EmpDesignation As String
Dim EmpSal As Double
End Structure

Private Sub btn_Structures_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Structures.Click

emp(inc).EmpName = "Udit Dua"
emp(inc).EmpDesignation = "Software Developer"

MsgBox(emp(inc).EmpName)
MsgBox(emp(inc).EmpDesignation)

ReDim Preserve emp(inc + 1)

emp(inc).EmpName = "John Smith"
emp(inc).EmpDesignation = "School Teacher"

MsgBox(emp(inc).EmpName)
MsgBox(emp(inc).EmpDesignation)

ReDim Preserve emp(inc + 1)

End Sub
End Class


Here is the video tutorial:



Friday, June 25, 2010

How to login into Youtube, Gmail, Yahoo, Facebook, Hotmail using Visual Basic 2010 or 2008 {VB.net}

Requirements:
4 Textbox (Textbox1, Textbox2, Textbox3, Textbox4)
1 Button (Name: Button1, Text: Set Cursor Position and Log me In"
2 Timers (Timer1 (Interval: 100, Enabled: True), Timer2 (Interval: 10000, Enabled: False)
2 Labels (Name: Label1 (Text: X), Label2 (Text: Y))


Codes:

Public Class Form1
Public Declare Sub SetCursorPos Lib "user32" (ByVal X As Integer, ByVal Y As Integer)
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.Text = Cursor.Position.X
TextBox2.Text = Cursor.Position.Y
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim first As Integer = TextBox3.Text
Dim second As Integer = TextBox4.Text
SetCursorPos(first, second)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Timer2.Enabled = True
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
SendKeys.Send("YOUR YOUTUBE USERNAME")
SendKeys.Send("{TAB}")
SendKeys.Send("YOUR YOUTUBE PASSWORD")
SendKeys.Send("{ENTER}")
Timer2.Enabled = False
End Sub
End Class
_________________________________________________________________________

Here is the video tutorial:



Monday, June 14, 2010

Visual Basic - Screen Capturing Program Tutorial - Take a ScreenShot of your screen..! - VB.net

Requirements:
2 Buttons (Name: Button1 (Text: Capture), Button2 (Text: Save)

1 PictureBox (Size Mode: Stretched Image)

1 Timer (Name: Timer1) (Interval approx. 10000)


Codes:

Public Class Form1
'Button 2 = Capture
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Opacity = 0
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = Screen.PrimaryScreen.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = screenshot
Timer1.Enabled = False
Me.Opacity = 100
End Sub

'Button1 = Save
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim savefiledialog1 As New SaveFileDialog
Try
savefiledialog1.Title = "Save File"
savefiledialog1.FileName = "Save As..."
savefiledialog1.Filter = "JPEG |*.jpeg"
If savefiledialog1.ShowDialog() = DialogResult.OK Then PictureBox1.Image.Save(savefiledialog1.FileName,System.Drawing.Imaging.ImageFormat.Bmp)
End If
Catch ex As Exception
'Do Nothing
End Try
End Sub

End Class
_________________________________________________________________________

Here is the video tutorial: