Visual Basic .NET Lessons
- Introduction
Lets first learn about visual basic.It is the software created by microsoft as a .net framework.It is programming model first released in 1991. Visual Basic was derived fromBASIC and enables rapid application development (RAD) of graphical user interface (GUI) applications. The scripting language VBScript is subset of Visual Basic.A programmer can create an application using components provided by the Visual Basic program itself. Programs written in Visual Basic can also use the Windows API, but doing so requires external function declarations.
- Lesson-1
To learn visual basic we must download the software:
www.microsoft.com/visualstudio/eng/.../visual-studio-2010-express
set up continues and install all the components that are downloaded.
- Lesson-2
After the installation open Microsoft visual basic 2010 express.Now click new project
and open windows form application.
- Open tool box add button1 to form1.
- At text we can change button as we like it.Now i will change this as click me
- As we change colour too.
- Double click on click me and write
MessageBox.Show("HI")
now press debug and it shows as click me.If we press click me it shows HI.
- Lesson-3
- New project -> Windows form application.
- In this lesson we can change properties.
- We can see the properties bar at right side.
- Accessibility
- Appearance
- Behaviour
- Data
- Design
- Focus
- Layout
- Lesson-4
- New project-> Windows form application.
- Open tool box add button1 to the form1.
- Then double click button1.
- Enter
MessageBox.Show(1+5)
Start Debug and click button1
6
- Lesson-5
- New project-> Windows form application.
- Open toolbox add textbox,button1 and listbox to the form1.
- If you want to change any properties that you can do that.
- After that double click button1
Start debug and enter some text on text box and click on button1 it shows in listbox.
- Lesson-6
- New project-> Windows form application.
- Open toolbox and add label,textbox,button1.
- In label write login form and change text of button1 to login.
- Now go to solutipon explorer and right click on windows application.
- Add windows form as form2.vb.
- Now in form2 add label as welcome to fb.
- Now double click on login.
- Enter
Form2.Show()
Else
MessageBox.Show("wrong password")
End If
Start debug
Now enter password as password then it shows welcome to fb.
If you enter other than password then it shows wrong password.
- Lesson-7
- New project-> windows form application.
- Open tool box and add button1 and text box.
- Change text of button1 to speak.
- Double click on speak and enter
SAPI = CreateObject("SAPI.spvoice")
SAPI.speak(Textbox1.Text)
Start debug
Enter some text on textbox and click speak.It speak what you have entered in textbox.
- Lesson-8
- New project-> Windows form application.
- Open tool box and add button1 and progress bar.
- Click on progress bar and place values which appears in properties
Minimum-0
Maximum-100
4.Now double click button1 and enter
ProgressBar1.Value = ProgressBar1.Value + 10
Start debug by clicking button1
By each click 10% increases in progress bar.
- Lesson-9
- New project -> Windows form application.
- Open tool box and add button1 to form1.
- At text we can change button1 as click me.
- After that double click click me and enter
MessageBox.Show(messagecontent)
MessageBox.Show(messagecontent,messagecontent)
Then start debug and click on click me then it show HI in both and top of the window.
If we create like this instead of above one
Dim mynumber As Integer = 10
MessageBox.Show(mynumber)
Then start debug and click on click me it shows as 10.
- Lesson-10
- New project -> Windows form application.
- Open toolbox and add button1,label1 and textbox1 to form1.
- Then doubleclick on button1 and enter
Label1.Text = "world"
End If
- Lesson-11
- New project-> Windows form application.
- Open toolbox and add label1,radiobutton1,radiobutton2 and button1.
- After that in the label enter some age.
- Then double click button1 and enter
MessageBox.Show("you are under 16")
Else If RadioButton2.Checked = True Then
MessageBox.Show("you are over 16")
End If
Now start debug if you click under 16 and click on button1 then it shows you are under 16.
If you click over 16 and enter button1 then it shows you are over 16.
If you click over 16 and enter button1 then it shows you are over 16.
- Lesson-12
- New project-> Windows form application.
- Open toolbox and add checkbox1,checkbox2,checkbox3,label1 and button1.
- Change label1 to favourite movie.
- Enter in checkbox1 as 2012,checkbox2 as avatar and checkbox3 as harrypotter respectively.
- Now double click button1 and enter
MessageBox.Show("you like 2012")
End If
If CheckBox2.Checked = True Then
MessageBox.Show("you like avatar")
End If
If CheckBox3.Checked = True Then
MessageBox.Show("you like harrypotter")
End If
Now start debug if you click harrypotter and then click on button1 then it shows you like harrypotter.
- Lesson-13
- New project-> Windows form application.
- Open toolbox and add tabcontrol1,button1,checkedlistbox1,label1 and toolstrip.
- Now click on toolstrip1 and change randommode into system.
- Click on arrow on toolstrip1 and to the label1.
- Now enter the right click and go to convert and to drop down button.
- Enter the text as file in the boxes and change text of button1 and button2 as help and exit.
- Double click help and enter
Double click exit and enter
Me.Close()
Now start debug if you click on help then it shows here your help.If you click on exit it closes the window.
- Lesson-14
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 to show form2.
- Go to solution explorer on the rightside and right click on windows application1.
- Add windows form as form2.vb.Now in form2 add label as second form.
- Now double click on show form2 and enter
Form2.Show()
Now start debug and click on show form2 then it shows second form.
- Lesson-15
- New project -> Windows form application.
- Open toolbox and add progressbar,radiobutton,windowsmediaplayer.
- Go to solution explorer and right click on windows application1 and add splash screen.
- Now change text as splash screen application.
- Now again go to solution explorer and right click and open properties.
- Now at bottom splash screen and make that one as splash screen1.
- Now start debug and splash screen opens for few seconds.
- Lesson-16
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 to for loop.
- Double click for loop and enter
For i = 0 To 10
MessageBox.Show("the value of i is :" & i)
Next
Now start debug and click on for loop then it shows the value of i is : 0.
It shows upto 10.
It shows upto 10.
- Lesson-17
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text to dowhile.
- Double click on dowhile and enter
Do While num1 < 10
MessageBox.Show("the value of num1 is :" & num1)
num1 = num1 + 1
Loop
Now start debug and click on dowhile then it shows the value of num1 is : 1.
It shows upto 10.
- Lesson-18
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 to dountil.
- Double click on dountil and enter
Do until num = 5
MessageBox.Show("the value of num is :" & num)
num = num + 1
Loop
Now start debug and click on dountil then it shows the value of num is : 1.
If you press ok it shows upto 5.
- Lesson-19
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 to callsub.
- Double click on callsub and enter
MessageBox.Show("i am cool")
End sub
- Private sub Call givemessage()
Now start debug and click on call sub and it shows i am cool.
- Lesson-20
- New project-> Windows form application.
- Open toolbox and add label1 and button1.
- Change text of button1 as usefunction.
- Double click on usefunction and enter
Private Function changelabeltext()
Return labeltext
End Function
-Private Sub
Now start debug and click on usefunction then it shows functions are cool in label.
www. youaretheoneimagine.blogspot.in
These are just easy lessons in visual basic.net.
Please share and comment if you like this lessons.Any doubts or suggestions make a Comment.
- Lesson-21
- New project -> Windows form application.
- Open toolbox and add button1.
- Change text of button1 to question.
- Double click on question and enter
MessageBoxButtons.YesNo,
MessageBoxIcon.Question)=
Windows.Forms.DialogResult
.Yes Then
MessageBox.Show("you clicked yes")
Else
MessageBox.Show("you clicked no")
End If
Now start debug and click on question then it shows whatever yes no.
If you click yes then it shows you clicked yes.
If you click no then it shows you clicked no.
- Lesson-22
- New project -> Windows form application.
- Open toolbox and add button1 and textbox1.
- change text of button1 to check.
- Double click on check and enter
If num<= 0 Then
MessageBox.Show("True")
End If
If TextBox1.Text<> "poop" Then
MessageBox.Show("you didnt enter the right password")
End If
Now start debug and click on check then it shows you didnt enter the right password.
If you click poop on textbox1 and click on check then it accepts.
- Lesson-23
- New project-> Windows form application.
- Open toolbox and add button1,label1,textbox1 and textbox2.
- Change text of button1 to login and label to please enter both passwords.
- Go to solution explorer and right click on windows application add windows form.
- Now open toolbox and add label in the box.
- Change text of label to password accepted.
- Now go to form1 and double click on login
MessageBox.Show("you didnt fill the fields")
End If
If TextBox1.Text = "passwordone" And TextBox2.Text
= "passwordtwo" Then
Form2.Show()
Else
MessageBox.Show("wrong password")
End If
Now start debug and enter in textbox1 as passwordone and enter in textbox2 as passwordtwo.
Click login then it shows password accepted.
If the two textboxs are empty and click login then it shows you didnt fill the fields.
If the passwords entered are wrong and click login then it shows wrong password.
- Lesson-24
- New project-> Windows form application .
- Open toolbox and add timer,button1,button2 and textbox1.
- Change text of textbox1 as 1 and button1 as start and button2 as stop.
-private sub
Timer1.Start()
-private sub
Timer1.Stop()
Now start debug and click on start then it add 1 for every one second and now click stop then it stops.
- Lesson-25
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as send email.
- Double click on send email and enter
- public class
-private sub
Dim Mail As New Mail Message
Mail.Subject = "test email"
Mail.To.Add("yourmail@gmail.com")
Mail.From = New Mail Address("yourmail@gmail.com")
Mail.Body = "this is ownage email using vb.net"Dim SMTP As New smtpClient("smtp.gmail.com")
SMTP.Enable Ssl = True
SMTP.Credentials = New System.Net.Network
Credential("username",
"password")
SMTP.Pat = "587"
SMTP.Send(Mail)
Now start debug and click on send email then email will be sent.
- Lesson-26
- New project -> Windows form application.
- Open toolbox and add button1,textbox1,textbox2,textbox3,label1 and label2.
- Change text of button1 as send email and label1 as username and label2 as password.
- Double click on send email and enter
- public class
-private sub
Dim Mail As New Mail Message
Mail.Subject = "test email"
Mail.To.Add(TextBox2.Text)
Mail.From = New Mail Address(TextBox2.Text)
Mail.Body = TextBox1.Text
Dim SMTP As New smtpClient("smtp.gmail.com")
SMTP.Enable Ssl = True
SMTP.Credentials = New System.Net.Network
Credential(TextBox2.Text,
TextBox3.Text)
SMTP.Pat = "587"
SMTP.Send(Mail)
Now start debug and click send email then email will be sent.
- Lesson-27
- New project -> Windows form application.
- Open toolbox and add button1.
- Double click on button1 and enter
-private sub
MessageBox.Show("hello world")
End Sub
This is how we can comment on anything that you want.
- Lesson-28
- New project -> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as sendfile.
- Double click on sendfile and enter
DirectCast(System.Net.WebRequest.
Create("ftp://ftp.drivehq.com
/file.txt"),System.Net.
FtpWebRequest)
request.Credentials = NewSystem.Net.Network
Credential("username","password")
request.Method = System.Net.WebRequestMethods.
Ftp.UploadFile
Dim file() As Byte = System.IO.File.ReadAllBytes("C:\
file.txt")
Dim strz As System.IO.System = request.GetRequest
Stream()
strz.Write(file,0,file.Length)
strz.Close()
strz.Dispose()
Now start debug and click on sendfile then the data is send to the above website.
- Lesson-29
- New project -> Windows form application.
- Open toolbox and add button1,label1,label2,label3,textbox1,textbox2,textbox3.
- Change text of button1 as sendfile and label1 as username,label2 as password,label3 as file.
- Double click on sendfile and enter
Dim request As System.Net.FtpWebRequest=
DirectCast(System.Net.WebRequest.
Create("ftp://ftp.drivehq.com
/file.txt"),System.Net.
FtpWebRequest)
request.Credentials = NewSystem.Net.Network
Credential(TextBox1.Text,
TextBox2.Text)
request.Method = System.Net.WebRequestMethods.
Ftp.UploadFile
Dim file() As Byte = System.IO.File.ReadAllBytes
(TextBox3.Text)
Dim strz As System.IO.System = request.GetRequest
Stream()
strz.Write(file,0,file.Length)
strz.Close()
strz.Dispose()
Now start debug and enter your username and password then choose your file and click on sendfile then the file will be sent.
- Lesson-30
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as call.
- Double click on call and enter
Dim number1 As Integer = 5
Sub addnumber(ByVal number2 As Integer)
number2 = number2 + 1
MessageBox.Show(number2)
End Sub
-private sub
Call addnumber(number1)
MessageBox.Show(number1)
Now start debug and click on call then it shows 6.If you click ok then it shows 5.
- Lesson-31
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as call.
- Double click on call and enter
Dim number1 As Integer = 5
Sub addnumber(ByRef number2 As Integer)
number2 = number2 + 1
MessageBox.Show(number2)
End Sub
-private sub
Call addnumber(number1)
MessageBox.Show(number1)
Now start debug and click on call then it shows 6.
- Lesson-32
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as download.
- Double click on button1 and enter
.com\file.exe","C:\downloadfile.exe")
Process.Start("C:\downloadedfile.exe")
This is the process how to download and run an application.
- Lesson-33
- New project -> Windows form application.
- Open toolbox and add button1,button2,button3,button4 and webbrowser.
- Change text of button1 as visiturl ,button2 as back,button3 as forward,button4 as refresh.
- Double click visiturl and enter
Double click on back and enter
WebBrowser1.Navigate(TextBox1.Text)
Double click on back and enter
WebBrowser1.GoBack()
Double click on forward and enter
WebBrowser1.GoForward()
Double click on refesh and enter
WebBrowser1.Refresh()
Click on webbrowser and go to properties then events and then double click navigated option and enter
TextBox1.Text = WebBrowser1.Url.ToString()
Now start debug and enter in textbox www.google.com and click visit url then google page will appear.Now you can use back,forward and refresh button aswell.
- Lesson-34
- Lesson-34
- New project -> Windows form application.
- Open toolbox and add button1,button2,button3,button4 and webbrowser.
- Change text of button1 as visiturl ,button2 as back,button3 as forward,button4 as refresh.
- Double click visiturl and enter
WebBrowser1.Navigate(TextBox1.Text)
Double click on back and enter
WebBrowser1.GoBack()
Double click on forward and enter
WebBrowser1.GoForward()
Double click on refesh and enter
WebBrowser1.Refresh()
Click on webbrowser and go to properties then events and then double click navigated option and enter
TextBox1.Text = WebBrowser1.Url.ToString()
Now start debug and enter in textbox www.google.com and click visit url then google page will appear.Now you can use back,forward and refresh button aswell.
- Lesson-35
- New project -> Windows form application.
- Save the project on the desktop.
- Open toolbox and add label,button1,Textbox.
- Double click on the form1 and enter
Dim greetmsg As String = "Welcometomyownageapp"
-private sub
Label1.Text = greetmsg
Change button1 as change then double click on change and enter
greetmsg = TextBox1.Text
Label1.Text = greetmsg
Now go to build and then build windows application1 and open folder windows application1 then to bin and open release and then windows application.exe
If you change then the label also changes.Now delete all the entered data in the form1 except public class form1 and end class.
Go to solution explorer then application settings and then go to settings
Name Type User Text
greettext string user welcome to the app
Go to form1
Label.Text = My.Settings.greettext
Double click change
My.Settings.greettext = TextBox1.Text
Now start debug and go to release and open windows application1.exe.
If you change the label it wont change.If you open again it will changes.
- Lesson-36
- This is next to lesson-35.
- Now go to add another form and change the name as form2.vb.
- Go to settings
- New project -> Windows form application.
- Open toolbox and add button1,button2,button3,button4 and webbrowser.
- Change text of button1 as visiturl ,button2 as back,button3 as forward,button4 as refresh.
- Double click visiturl and enter
WebBrowser1.Navigate(TextBox1.Text)
- Lesson-35
- New project -> Windows form application.
- Save the project on the desktop.
- Open toolbox and add label,button1,Textbox.
- Double click on the form1 and enter
Dim greetmsg As String = "Welcometomyownageapp"
- Lesson-36
- This is next to lesson-35.
- Now go to add another form and change the name as form2.vb.
- Go to settings
Name Type User Text
greettext string user welcome to the app
username string user michael
Double click form1
Label1.Text = "Hello and welcome to the application"&
My.Settings.username
Delete textbox and double click on change
Change.Show()
Add button1 and textbox to change and enter
My.Settings.username = TextBox1.Text
Now start debug and open application then it shows welcome to the app michael.
If you want to change michael then enter in change box.
Delete label and add textbox.
Change text of button1 as login and add label as please enter password.
Now open settings
Name Type User Text
password string user password123
Click on button1 and enter
If TextBox1.Text = My.Settings.password.Then
Change password.Show()
Else
MessageBox.Show("Invalid password")
End If
Now start debug and enter password123 then it shows change form.
If you again go to change double click button1 and enter
My.Settins.password = TextBox1.Text
Now start debug then enter password123 it also shows changeform then if you change password as text and then close it.
Now again open it and enter some text then it opens.
- Lesson-37
- New project-> Windows form application.
- Open toolbox and add textbox1,button1,button2 and timer.
- Change text of button1 as start and button2 as stop.
- Double click timer and enter
SendKeys.Send(TextBox1.Text)
SendKeys.Send("(Enter)")
Double click start and enter
Timer1.Start()
Double click stop and enter
Timer1.Stop()
Now open note pad and click in text box as I am using vb.net.
Then in note pad it shows for every one second as I am using vb.net.
Now add label and textbox. Change label to send text and add another label as seconds.
Double click start and enter
Timer1.Interval = TextBox2.Text*1000
Timer1.Start()
Now start debug and timer starts and showing I am using vb.net for every one second in note pad.
- Lesson-38
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as message array.
- Double click message array and enter
Dim tvshows(4) As String
tvshows(0) = "south park"
tvshows(1) = "family guy"
tvshows(2) = "american dad"
tvshows(3) = "simpsons"
tvshows(4) = "super natural"
For i = 0 To tvshows.Length-1
MessageBox.Show(tvshows(i))
Next
Now start debug and click on message array then it shows all channels in an order.
- Lesson-39
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as split string.
- Double click on split string and enter
Dim somestring As String = "one two three four"
Dim somestring2() As String
somestring2 = somestring.Split(" ")
For i = 0 To somestring2.Length-1
MessageBox.Show(somestring2(i))
Next
Now start debug and click on split string then it shows one
two
three
four.
- Lesson-40
- New project-> Windows form application.
- Open toolbox and add button1,button2,groupbox,label1,label2,label3,label4, label5,toolbox1,toolbox2,toolbox3,toolbox4,toolbox5,toolbox6 and label6.
- change text of button1 as get information,button2 as clear,label1 as computername,label2 as username,label3 as osname,label4 as capslockon, label5 as mousewheel and label6 as workingarea.
- Double click get information and enter
TextBox1.Text = My.Computer.Name
TextBox2.Text = My.User.Name
TextBox3.Text = My.Computer.Info.OSFullName
TextBox4.Text = My.Computer.Keyboard.CapsLock
TextBox5.Text = My.Computer.Mouse.WheelExists
TextBox6.Text = My.Computer.Screen.WorkingArea. ToString
Now double click clear and enter
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
Go to properties and make readonly for all as true.
Now start debug and click on get information then it shows information that you have entered.If you click clear all the data will be cleared.
These are just intermediate lessons in visual basic.net.
Please share and comment if you like this lessons.Any doubts or suggestions make a Comment.
- Lesson-37
- New project-> Windows form application.
- Open toolbox and add textbox1,button1,button2 and timer.
- Change text of button1 as start and button2 as stop.
- Double click timer and enter
SendKeys.Send(TextBox1.Text)
Then in note pad it shows for every one second as I am using vb.net.
- Lesson-38
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as message array.
- Double click message array and enter
Dim tvshows(4) As String
tvshows(0) = "south park"
tvshows(1) = "family guy"
tvshows(2) = "american dad"
tvshows(3) = "simpsons"
tvshows(4) = "super natural"
For i = 0 To tvshows.Length-1
MessageBox.Show(tvshows(i))
Next
Now start debug and click on message array then it shows all channels in an order.
- Lesson-39
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as split string.
- Double click on split string and enter
Dim somestring As String = "one two three four"
Dim somestring2() As String
somestring2 = somestring.Split(" ")
For i = 0 To somestring2.Length-1
MessageBox.Show(somestring2(i))
Next
Now start debug and click on split string then it shows one
two
three
four.
- Lesson-40
- New project-> Windows form application.
- Open toolbox and add button1,button2,groupbox,label1,label2,label3,label4, label5,toolbox1,toolbox2,toolbox3,toolbox4,toolbox5,toolbox6 and label6.
- change text of button1 as get information,button2 as clear,label1 as computername,label2 as username,label3 as osname,label4 as capslockon, label5 as mousewheel and label6 as workingarea.
- Double click get information and enter
These are just intermediate lessons in visual basic.net.
Please share and comment if you like this lessons.Any doubts or suggestions make a Comment.
- Lesson-41
- New project-> Windows form application.
- Open toolbox and add button1 and textbox.
- Double click on button1 and enter
Dim request As System.Net.HttpWebRequest = System.
Net.httpwebrequest.Create("http://hi.ripway.com
/TeachMeComputer/index.html")
Dim response As System.Net.HttpWebResponse=request.
GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.Stream
Reader(response.GetResponsestream())
Dim sourcecode As String = sr.ReadToEnd()
TextBox1.Text = sourcecode
Now start debug and click on source code then you will get the source code of entered url.
- Lesson-42
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as check.
- Double click on check and enter
Dim request As System.Net.HttpWebRequest = System.
Net.httpwebrequest.Create("http://hi.ripway.com
/TeachMeComputer/index.html")
Dim response As System.Net.HttpWebResponse=request.
GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.Stream
Reader(response.GetResponsestream())
Dim sourcecode As String = sr.ReadToEnd()
Dim newestversion As String = sr.ReadToEnd()
Dim currentversion As String = Application.ProductVersion
If newestversion.Contains(currentversion) Then
MessageBox.Show("you have the current version")
Else
MessageBox.Show("newest version available")
End If
Now start debug and click on check then it shows you have current version.If any new
version available then it shows newest version available.
- Lesson-43
- New project-> Windows form application.
- Open toolbox and add label1,label2,textbox1,textbox2,button1,button2 .
- Also add webbrowser.
- Change text of label1 as username,label2 as password,button1 as navigate .
- Also change button2as login.
- Double click on navigate and enter
WebBrowser1.Navigate("http://login.yahoo.com/")
Double click on login and enter
WebBrowser1.Document.GetElementById("login").Set
Attribute
("value",TextBox1.Text)
WebBrowser1.Document.GetElementById("passwd").Set
Attribute
("value",TextBox2.Text)
WebBrowser1.Document.GetElementById("save").Invoke
Member
("click")
Start debug enter username and password then click login and it will login into
your yahoo account.
- Lesson-44
- New project-> Windows form application.
- Open toolbox and add button1.
- Change text of button1 as showpath.
- Double click on showpath and enter
Dim thepath As String = Environment.GetFolderPath(
environment.
SpecialFolder.MyDocuments)
MessageBox.Show(thepath)
Now start debug and click on showpath then it shows My Documents.
- Lesson-45
- New project-> Windows form application.
- Open toolbox and add label1,textbox1,textbox2,button1 and button2.
- Change text of label1 as filepath,button1 as open and button2 as close.
- Double click on open and enter
If System.IO.File.Exists(TextBox1.Text) = True Then
Dim objreader As New System.IO.StreamReader(TextBox1.
Text)
TextBox2.Text = objreader.ReadToEnd
objreader.close()
Else
MessageBox.Show("that file doesnot exist")
End If
Double click on clear and enter
TextBox2.Clear()
Now start debug and enter in textbox C:\whatever.txt.If file exists then the file opens.
- Lesson-46
- New project-> Windows form application.
- Open toolbox and add textbox1,textbox2,label1,label2,button1 and button2.
- Change text of label1 as filename,label2 as body,button1 as save and button2 as close.
- Double click save and enter
If System.IO.File.Exists(TextBox1.Text) Then
MessageBox.Show("sorry that file doesnot exist")
Else
Dim objwriter As New System.IO.StreamWriter(TextBox1.
Text)
objwriter.Write(TextBox2.Text)
objwriter.Close()
End If
Double click close and enter
Process.Start(TextBox1.Text)
Now start debug and enter in textbox C:\streamfile.txt and enter something in body and
click save.
- Lesson-47
- New project-> Windows form application.
- Open toolbox and add textbox1,button1 and openfiledialog.
- Change text of button1 as browse and openfiledialog as select your file.
- Change properties and double click browse then enter
OpenFileDialog1.ShowDialog()
Open properties and click on file ok .Then double click openfiledialog and enter
TextBox1.Text = OpenFileDialog1.FileName
Now start debug and click browse then you can find some file.txt.
In the below you can select file name and files of type.
- Lesson-48
- New project-> Windows form application.
- Open toolbox and add textbox1,button1 and savefiledialog.
- Change text of button1 as save and also change properties
- Double click save then enter
SaveFileDialog1.ShowDialog()
Double click savefiledialog and enter
Dim FileToSaveAs As String = SaveFileDialog1.FileName
Dim objwriter As New System.IO.StreamWriter(FileToSaveAs)
objwriter.Write(TextBox1.Text)
objwriter.Close()
Now start debug and enter some text in textbox then cilck save.
It saves as somefile.txt.
- Lesson-49
- New project-> Windows form application.
- Open toolbox and add button1,textbox1,textbox2 and webbrowser.
- Change text of button1 as browse.
- Also add scrollbar to textbox2.
- Double click on browse and enter
WebBrowser1.Navigate(TextBox1.Text)
Double click on webbrowser and enter
Dim PageElements As HtmlElementCollection = WebBrowser1
.Document
.getelementsbytagname("img")
For Each CurElement As HtmlElement In PageElements
TextBox2.Text = TextBox2.Text & CurElement.GetAttribute
("src")&Environment.NewLine
Next
Now start debug and enter any link in textbox and click browse then it opens and all the
links in website will open in textbox2.
- Lesson-50
- New project-> Windows form application.
- Open toolbox and add button1,webbrowser and listbox1.
- Double click form1 and enter
WebBrowser1.Navigate("www.youtube.com")
Double click button1 and enter
Dim allelements As HtmlElementCollection = WebBrowser1.
Document.All
For Each webpageelement As HtmlElement In allelements
ListBox1.Items.Add(webpageelement.GetAttribute("src"))
Next
Now start debug and click on button1 youtube will open and then all the elements are
opened in listbox1.
- Lesson-51
- New project-> Windows form application.
- Open toolbox and button1 and webbrowser.
- Double click form1 and enter
WebBrowser1.Navigate("http://login.facebook.com/login.php")
Double click button1 and enter
Dim allelements As HtmlElementCollection = WebBrowser1.
Document.All
For Each webpageelement As HtmlElement In allelements
'value = "Log in"
If webpageelement.GetAttribute("value") = "Log in" Then
webpageelement.InvokeMember("click")
End If
Next
Now start debug and click button1 then facebook login page opens.
- Lesson-52
- New project-> Windows form application.
- Open toolbox and add button1 and textbox1.
- Double click on button1 and enter
Imports System.Net
-public class
-private sub
Dim request As WebRequest = WebRequest.Create("http://
hi.ripway.com/writetext/post.php?w="
&TextBox1.Text)
request.GetResponse()
Now start debug and enter some text in textbox1 and click on button1 then the data goes
to the website.
- Lesson-53
- New project-> Windows form application.
- Open toolbox and add button1,textbox1,textbox2,label1 and textbox3.
- Change text of button1 as calculate and label1 as total.
- Double click on button1 and enter
TextBox3.Text = addnumbers(bla,bla2)
Double click button2 and enter
MessageBox.Show(addnumbers(TextBox1.Text,TextBox2.
Text))
MessageBox.Show(functions.addnumbers(TextBox1.Text,
TextBox2.Text))
Add another form as functions.vb.
-Module functions
Public bla As Integer = 10
Public bla2 As Integer = 20
-Public function addnumbers(By Val number1 As Integer,
By Val number2 As Integer)
Return number1 + number2
End Function
End Module
Now start debug then enter some numbers in two textboxs and click calculate then the
sum of two numbers will be shown.
- Lesson-54
- New project-> Windows form application.
- Add classes as classes.vb.
-public class person
Public firstname As String
Public lastname As String
Public eyecolour As String
Public haircolour As String
Public Sub setvalues(ByVal first As string,ByVal last As string,
ByVal eye As string,ByVal hair As string)
firstname = first
lastname = last
eyecolour = eye
haircolour = hair
End Class
Now go to form1 and add button1 then double click button1 and enter
Dim bob As New Person
bob.firstname = "bob"
bob.lastname = "smith"
bob.eyecolour = "brown"
bob.haircolour = "black"
bob.setvalues("bob","smith","brown","black")
MessageBox.Show("Bobs hair colour is "&bob.haircolour)
Now start debug and click button1 then it shows all the above contents.
- Lesson-55
- New project-> Windows form application.
- Open toolbox and add button1 and listbox1.
- Double click button1 and enter
Imports System.Text.RegularExpressions
-public class
-private sub
Dim request As System.Net.HttpWebRequest = System.Net.
HttpWebRequest.Create("http://services.runescape.
com/m=itemd.b_rs/frontpage.ws")
Dim response As System.Net.HttpWebResponse = request.
GetResponse
Dim sr As System.IO.StreamReader = New System.IO.Stream
Reader(response.GetResponseStream())
Dim rssourcecode As String = sr.ReadToEnd
'<img name = "object" src="http://services.3155_obj_Sprite
.gif?id=19843"alt="Ingredients">
Dim r As New System.Text.RegularExpressions.Regex("<
img name=""object""src=""http://services.runescape
.com/m=itemdb_rs/.*""alt="".*"">")
Dim matches As MatchCollection=r.Matches(rssourcecode)
For Each itemcode As Match In Matches
ListBox1.Items.Add(itemcode.Value.Split("""").GetValue(5))
Next
Now start debug and click on button1 and then all items are shown in listbox.
- Lesson-56
- New project-> Windows form application.
- Open toolbox and add button1,button2,label1 and label2.
- Change label to 0 and double click button1 then enter
-public class
Dim i As Integer
Dim i2 As Integer
Dim thread As System.Threading.Thread
Dim thread2 As System.Threading.Thread
Private Sub countup()
Do Until i = 10000
i = i + 1
Label1.Text = i
Me.Refresh()
Loop
Private Sub countup2()
Do Until i2 = 10000
i2 = i2 + 1
Label2.Text = i2
Me.Refresh()
Loop
-private sub
thread = New System.Threading.Thread(Address Of countup)
thread2.Start()
Double click button2 and enter
thread2 = New System.Threading.Thread(Address Of
countup2)
thread2.Start()
Change label2 to 0 and double click form1 then enter
Me.CheckForIlegalCrossThreadCalls = False
Start debug and click on both buttons then both number will start.
- Lesson-57
- New project-> Windows form application.
- Open toolbox and add label1,label2,textbox1,textbox2,button1,button2.
- Also add webbrowser,richtextbox1.
- Change text of label1 as username,label2 as password and button1 as makerequest.
- Double click makerequest and enter
Imports System.Net
Imports System.Text
Imports System.IO
-public class
Dim logincookie As Cookie Container
-private sub
Dim postData As String = "referer=http%3A%2F%2Fforums
.zybez.net%2Findex.php%3Fapp%3Dcore%26module%3
Dglobal%26section%3Dlogin&username="&TextBox1.Text
&"&password="&TextBox2.Text&"&rememberMe=1"
Dim tempcookies As New Cookie Container
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postData)
Dim postReq As HttpWebRequest = DirectCast(WebRequest.
Create("http://forums.zybez.net/index.php?app=core&
module=global§ion=login&do=process")
,HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.Cookie Container = temp Cookies
postReq.ContentType = "application/x.www.form.urlencoded"
postReq.Referer = "http://forums.zybez.net/index.php?app=\
core&
module=global§ion=login&do=process"
postReq.UserAgent = "Mozilla/5.0(Windows;U;Windows NT
6.1;ru;rv:1.9.2.3)Gecko/20100401Firefox/4.0
(.NETCLR3.5.30729)"
postReq.Content Length = byteData.Length
Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(byteData,0,byteData.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(),HttpWeb
Response)
tempCookies.Add(postresponse.Cookies)
logincookie = tempCookies
Dim postreqreader As New StreamReader(postresponse.
GetResponseStream())
Dim thepage As String = postreqreader.ReadToEnd
RichTextBox1.Text = thepage
Double click button2 and enter
WebBrowser1.Document Text = RichTextBox1.Text
Start debug and enter your username and password then press make request and now
click button2.
- Lesson-58
- New project-> Windows form application.
- Open toolbox and add label1,label2,textbox1,textbox2,button1,button2.
- Also add webbrowser,richtextbox1.
- Also add button3,button4 and richtextbox2.
- Change text of label1 as username,label2 as password and button1 as makerequest.
- Double click makerequest and enter
Imports System.Net
Imports System.Text
Imports System.IO
-public class
Dim logincookie As Cookie Container
-private sub
Dim postData As String = "referer=http%3A%2F%2Fforums
.zybez.net%2Findex.php%3Fapp%3Dcore%26module%3
Dglobal%26section%3Dlogin&username="&TextBox1.Text
&"&password="&TextBox2.Text&"&rememberMe=1"
Dim tempcookies As New Cookie Container
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postData)
Dim postReq As HttpWebRequest = DirectCast(WebRequest.
Create("http://forums.zybez.net/index.php?app=core&
module=global§ion=login&do=process")
,HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.Cookie Container = temp Cookies
postReq.ContentType = "application/x.www.form.urlencoded"
postReq.Referer = "http://forums.zybez.net/index.php?app=
core&
module=global§ion=login&do=process"
postReq.UserAgent = "Mozilla/5.0(Windows;U;Windows NT
6.1;ru;rv:1.9.2.3)Gecko/20100401Firefox/4.0
(.NETCLR3.5.30729)"
postReq.Content Length = byteData.Length
Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(byteData,0,byteData.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(),HttpWeb
Response)
tempCookies.Add(postresponse.Cookies)
logincookie = tempCookies
Dim postreqreader As New StreamReader(postresponse.
GetResponseStream())
Dim thepage As String = postreqreader.ReadToEnd
RichTextBox1.Text = thepage
Double click button2 and enter
WebBrowser1.Document Text = RichTextBox1.Text
Double click button4 and enter
WebBrowser1.DocumentText = RichTextBox2.Text
Double click button3 and enter
Dim request As HttpWebRequest = DirectCast(WebRequest.
Create(""),HttpWebRequest)
request.CookieContainer = logincookie
Dim response As HttpWebResponse = DirectCast(request.
GetResponse(),HttpWebResponse)
Dim reader As New Stream Reader(FileWebResponse,
GetResponseStream())
Dim theusercp As String = reader.ReadToEnd
RichTextBox2.Text = theusercp
Start debug and click all the buttons then the cookies container will opens.
Net.httpwebrequest.Create("http://hi.ripway.com
/TeachMeComputer/index.html")
Dim response As System.Net.HttpWebResponse=request.
GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.Stream
Reader(response.GetResponsestream())
Dim sourcecode As String = sr.ReadToEnd()
TextBox1.Text = sourcecode
Now start debug and click on source code then you will get the source code of entered url.
Net.httpwebrequest.Create("http://hi.ripway.com
/TeachMeComputer/index.html")
Dim response As System.Net.HttpWebResponse=request.
GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.Stream
Reader(response.GetResponsestream())
Dim sourcecode As String = sr.ReadToEnd()
Dim newestversion As String = sr.ReadToEnd()
Dim currentversion As String = Application.ProductVersion
If newestversion.Contains(currentversion) Then
MessageBox.Show("you have the current version")
Else
MessageBox.Show("newest version available")
End If
Now start debug and click on check then it shows you have current version.If any new
Double click on login and enter
WebBrowser1.Document.GetElementById("login").Set
Attribute
("value",TextBox1.Text)
WebBrowser1.Document.GetElementById("passwd").Set
Attribute
("value",TextBox2.Text)
WebBrowser1.Document.GetElementById("save").Invoke
Member
("click")
Start debug enter username and password then click login and it will login into
environment.
SpecialFolder.MyDocuments)
MessageBox.Show(thepath)
Now start debug and click on showpath then it shows My Documents.
Dim objreader As New System.IO.StreamReader(TextBox1.
Text)
TextBox2.Text = objreader.ReadToEnd
objreader.close()
Else
MessageBox.Show("that file doesnot exist")
End If
Double click on clear and enter
TextBox2.Clear()
Now start debug and enter in textbox C:\whatever.txt.If file exists then the file opens.
Else
Dim objwriter As New System.IO.StreamWriter(TextBox1.
Text)
objwriter.Write(TextBox2.Text)
objwriter.Close()
End If
Double click close and enter
Process.Start(TextBox1.Text)
Now start debug and enter in textbox C:\streamfile.txt and enter something in body and
- Lesson-49
- New project-> Windows form application.
- Open toolbox and add button1,textbox1,textbox2 and webbrowser.
- Change text of button1 as browse.
- Also add scrollbar to textbox2.
- Double click on browse and enter
Double click on webbrowser and enter
Dim PageElements As HtmlElementCollection = WebBrowser1
.Document
.getelementsbytagname("img")
For Each CurElement As HtmlElement In PageElements
TextBox2.Text = TextBox2.Text & CurElement.GetAttribute
("src")&Environment.NewLine
Next
Now start debug and enter any link in textbox and click browse then it opens and all the
links in website will open in textbox2.
- Lesson-50
- New project-> Windows form application.
- Open toolbox and add button1,webbrowser and listbox1.
- Double click form1 and enter
Double click button1 and enter
Dim allelements As HtmlElementCollection = WebBrowser1.
Document.All
For Each webpageelement As HtmlElement In allelements
ListBox1.Items.Add(webpageelement.GetAttribute("src"))
Next
Now start debug and click on button1 youtube will open and then all the elements are
opened in listbox1.
- Lesson-51
- New project-> Windows form application.
- Open toolbox and button1 and webbrowser.
- Double click form1 and enter
Double click button1 and enter
Dim allelements As HtmlElementCollection = WebBrowser1.
Document.All
For Each webpageelement As HtmlElement In allelements
'value = "Log in"
If webpageelement.GetAttribute("value") = "Log in" Then
webpageelement.InvokeMember("click")
End If
Next
Now start debug and click button1 then facebook login page opens.
- Lesson-52
- New project-> Windows form application.
- Open toolbox and add button1 and textbox1.
- Double click on button1 and enter
-public class
-private sub
Dim request As WebRequest = WebRequest.Create("http://
hi.ripway.com/writetext/post.php?w="
&TextBox1.Text)
request.GetResponse()
Now start debug and enter some text in textbox1 and click on button1 then the data goes
to the website.
- Lesson-53
- New project-> Windows form application.
- Open toolbox and add button1,textbox1,textbox2,label1 and textbox3.
- Change text of button1 as calculate and label1 as total.
- Double click on button1 and enter
Double click button2 and enter
MessageBox.Show(addnumbers(TextBox1.Text,TextBox2.
Text))
MessageBox.Show(functions.addnumbers(TextBox1.Text,
TextBox2.Text))
Add another form as functions.vb.
-Module functions
Public bla As Integer = 10
Public bla2 As Integer = 20
-Public function addnumbers(By Val number1 As Integer,
By Val number2 As Integer)
Return number1 + number2
End Function
End Module
Now start debug then enter some numbers in two textboxs and click calculate then the
sum of two numbers will be shown.
- Lesson-54
- New project-> Windows form application.
- Add classes as classes.vb.
Public firstname As String
Public lastname As String
Public eyecolour As String
Public haircolour As String
Public Sub setvalues(ByVal first As string,ByVal last As string,
ByVal eye As string,ByVal hair As string)
firstname = first
lastname = last
eyecolour = eye
haircolour = hair
End Class
Now go to form1 and add button1 then double click button1 and enter
Dim bob As New Person
bob.firstname = "bob"
bob.lastname = "smith"
bob.eyecolour = "brown"
bob.haircolour = "black"
bob.setvalues("bob","smith","brown","black")
MessageBox.Show("Bobs hair colour is "&bob.haircolour)
Now start debug and click button1 then it shows all the above contents.
- Lesson-55
- New project-> Windows form application.
- Open toolbox and add button1 and listbox1.
- Double click button1 and enter
-public class
-private sub
Dim request As System.Net.HttpWebRequest = System.Net.
HttpWebRequest.Create("http://services.runescape.
com/m=itemd.b_rs/frontpage.ws")
Dim response As System.Net.HttpWebResponse = request.
GetResponse
Dim sr As System.IO.StreamReader = New System.IO.Stream
Reader(response.GetResponseStream())
Dim rssourcecode As String = sr.ReadToEnd
'<img name = "object" src="http://services.3155_obj_Sprite
.gif?id=19843"alt="Ingredients">
Dim r As New System.Text.RegularExpressions.Regex("<
img name=""object""src=""http://services.runescape
.com/m=itemdb_rs/.*""alt="".*"">")
Dim matches As MatchCollection=r.Matches(rssourcecode)
For Each itemcode As Match In Matches
ListBox1.Items.Add(itemcode.Value.Split("""").GetValue(5))
Next
Now start debug and click on button1 and then all items are shown in listbox.
- Lesson-56
- New project-> Windows form application.
- Open toolbox and add button1,button2,label1 and label2.
- Change label to 0 and double click button1 then enter
Dim i As Integer
Dim i2 As Integer
Dim thread As System.Threading.Thread
Dim thread2 As System.Threading.Thread
Private Sub countup()
Do Until i = 10000
i = i + 1
Label1.Text = i
Me.Refresh()
Loop
Private Sub countup2()
Do Until i2 = 10000
i2 = i2 + 1
Label2.Text = i2
Me.Refresh()
Loop
-private sub
thread = New System.Threading.Thread(Address Of countup)
thread2.Start()
Double click button2 and enter
thread2 = New System.Threading.Thread(Address Of
countup2)
thread2.Start()
Change label2 to 0 and double click form1 then enter
Me.CheckForIlegalCrossThreadCalls = False
Start debug and click on both buttons then both number will start.
- Lesson-57
- New project-> Windows form application.
- Open toolbox and add label1,label2,textbox1,textbox2,button1,button2.
- Also add webbrowser,richtextbox1.
- Change text of label1 as username,label2 as password and button1 as makerequest.
- Double click makerequest and enter
core&
- Lesson-58
- New project-> Windows form application.
- Open toolbox and add label1,label2,textbox1,textbox2,button1,button2.
- Also add webbrowser,richtextbox1.
- Also add button3,button4 and richtextbox2.
- Change text of label1 as username,label2 as password and button1 as makerequest.
- Double click makerequest and enter
Imports System.Net
Imports System.Text
Imports System.IO
-public class
Dim logincookie As Cookie Container
-private sub
Dim postData As String = "referer=http%3A%2F%2Fforums
.zybez.net%2Findex.php%3Fapp%3Dcore%26module%3
Dglobal%26section%3Dlogin&username="&TextBox1.Text
&"&password="&TextBox2.Text&"&rememberMe=1"
Dim tempcookies As New Cookie Container
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postData)
Dim postReq As HttpWebRequest = DirectCast(WebRequest.
Create("http://forums.zybez.net/index.php?app=core&
module=global§ion=login&do=process")
,HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.Cookie Container = temp Cookies
postReq.ContentType = "application/x.www.form.urlencoded"
postReq.Referer = "http://forums.zybez.net/index.php?app=
core&
core&
module=global§ion=login&do=process"
postReq.UserAgent = "Mozilla/5.0(Windows;U;Windows NT
6.1;ru;rv:1.9.2.3)Gecko/20100401Firefox/4.0
(.NETCLR3.5.30729)"
postReq.Content Length = byteData.Length
Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(byteData,0,byteData.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(),HttpWeb
Response)
tempCookies.Add(postresponse.Cookies)
logincookie = tempCookies
Dim postreqreader As New StreamReader(postresponse.
GetResponseStream())
Dim thepage As String = postreqreader.ReadToEnd
RichTextBox1.Text = thepage
Double click button2 and enter
WebBrowser1.Document Text = RichTextBox1.Text
No comments:
Post a Comment