Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB 2008 - Useful Code
#1
Hello everyone. I previously posted this tutorial on HF , but I recently left and joined SF. I thought that this may be useful to some beginners.


Make the computer talk

Code:
Dim sapi
sapi = CreateObject("sapi.spvoice")
sapi.Speak("TextHere")


Create a messagebox

Code:
MsgBox("TextHere")

Create A Message Box With A Yes + No Button

Code:
Dim Responce As Integer
Responce = MsgBox("Are You Sure", vbYesNo, "DELETE")
If Responce = vbYes Then
  MsgBox(" You Clicked Yes!")
Else
MsgBox("You Clicked No!")
End If

To change buttons,replace "vbyesno" with one of the following:

Code:
vbYesNoCancel
vbCritical
vbExcalmation
vbInformation
vbMsgBoxHelp
vbMsgBoxRight
vbOkOnly
vbRetryCancel
vbDefaultButton1
vbDefaultButton2
vbDefaultButton3
vbApplicationmodal
vbQuestion
vbOkCancel
vbAbortRetryIgnore

Start a process
Code:
Process.Start("notepad")
Process.Start("www.hackforum.net")

Kill a process

Code:
Dim RunningProcess As System.Diagnostics.Process = Process.GetProcessesByName("taskmgr.exe")(0)
RunningProcess.Kill()

Rename a file

Code:
My.Computer.FileSystem.RenameFile ("C:\Program Files\Mozilla Firefox\firefox.exe", "Anything.exe")

Delete a file

Code:
Dim FileToDelete As String
FileToDelete = "C:\File.exe"
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)

Copy a file

Code:
Dim FileToCopy As String
Dim NewCopy As String

FileToCopy = "C:\test.exe"
NewCopy = "C:\NewTest.txt"

If System.IO.File.Exists(FileToCopy) = True Then
System.IO.File.Copy(FileToCopy, NewCopy)

Delete a registry key

Code:
My.Computer.Registry.LocalMachine.DeleteSubKey("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SafeBoot")

Create a registry key

Code:
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
regKey.CreateSubKey("MyApp")
regKey.Close()

Over write a text file and then add text to it

Code:
Dim OverWrite As String = "C:\Documents and Settings\All Users\Desktop\Example.txt"
If System.IO.File.Exists(OverWrite) = True Then
Dim ObjWriter4 As New System.IO.StreamWriter(OverWrite)
ObjWriter4.Write("Text To Add")
ObjWriter4.Close()

Create an if statement (File Deletion)

Code:
Dim FileToDeleteWithAIfStatement As String
FileToDeleteWithAIfStatement = "C:\Windows\I386\regedit.exe"
If System.IO.File.Exists(FileToDeleteWithAIfStatement) = True The
System.IO.File.Delete(FileToDeleteWithAIfStatement)
End If

For loop

Code:
For MessageBox = 1 To 60
MsgBox(" This Will Loop Sixty Times!")

Next MessageBox

Hide your application

Code:
Me.Hide ()

Send an email with an attachment via SMTP Source

Code:
Dim message As System.Net.Mail.MailMessage

Dim smtp As New System.Net.Mail.SmtpClient("smtp.gmail.com", 587)


Dim attach As System.Net.Mail.Attachment


message = New System.Net.Mail.MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtMessage.Text)


If My.Computer.FileSystem.FileExists(txtAttachment.Text) Then message.Attachments.Add(attach)

smtp.EnableSsl = True


smtp.Credentials = New System.Net.NetworkCredential("yourUsername@yourmail.com", "password")

Try

smtp.Send(message)


MessageBox.Show("Well, the mail message appears to have been a success!", " Successful?", MessageBoxButtons.OK, MessageBoxIcon.Information)

Catch exc As Net.Mail.SmtpException

MessageBox.Show(exc.StatusCode.ToString, " Something Happened?", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try


Visual Basic 2008 tutorials:

Link 1
Link2

The history of Visual Basic:

Link1
Link2

Do not quote post do to size.Thank you.
Reply


Messages In This Thread
VB 2008 - Useful Code - by Apache - 11-28-2009, 01:03 PM
RE: VB 2008 - Useful Code - by Smed - 11-28-2009, 03:03 PM
RE: VB 2008 - Useful Code - by flAmingw0rm - 11-28-2009, 07:06 PM
RE: VB 2008 - Useful Code - by Red X - 12-04-2009, 05:57 PM
RE: VB 2008 - Useful Code - by thanasis2028 - 12-10-2009, 05:39 AM
RE: VB 2008 - Useful Code - by Red X - 12-10-2009, 01:46 PM
RE: VB 2008 - Useful Code - by HmanDude - 12-11-2009, 12:45 PM
RE: VB 2008 - Useful Code - by RaZoR03 - 04-18-2010, 12:47 AM
RE: VB 2008 - Useful Code - by trubufo - 04-28-2010, 04:23 PM
RE: VB 2008 - Useful Code - by TurB0 - 04-29-2010, 07:36 AM
RE: VB 2008 - Useful Code - by saumil - 06-23-2010, 08:44 AM
RE: VB 2008 - Useful Code - by macas5 - 05-01-2010, 07:45 AM
RE: VB 2008 - Useful Code - by NathanE - 05-01-2010, 02:10 PM
RE: VB 2008 - Useful Code - by Nemmyy - 05-12-2010, 09:12 PM
RE: VB 2008 - Useful Code - by Fragma - 05-13-2010, 01:37 AM
RE: VB 2008 - Useful Code - by Julie - 05-13-2010, 02:51 PM
RE: VB 2008 - Useful Code - by //Pretext™ - 05-18-2010, 09:20 AM
RE: VB 2008 - Useful Code - by Braco - 05-24-2010, 03:08 PM
RE: VB 2008 - Useful Code - by Zerk.Gamer.Coder - 05-24-2010, 04:05 PM
RE: VB 2008 - Useful Code - by eXosphere™ - 05-24-2010, 07:45 PM
RE: VB 2008 - Useful Code - by Vipermakd - 05-26-2010, 08:42 PM
RE: VB 2008 - Useful Code - by Cybr - 05-28-2010, 01:33 PM
RE: VB 2008 - Useful Code - by Matt™ - 05-29-2010, 09:08 AM
RE: VB 2008 - Useful Code - by Toχic - 06-01-2010, 10:42 AM
RE: VB 2008 - Useful Code - by shanker - 06-01-2010, 10:53 AM
RE: VB 2008 - Useful Code - by lorens13 - 06-03-2010, 12:38 AM
RE: VB 2008 - Useful Code - by mmki - 06-03-2010, 08:36 PM
RE: VB 2008 - Useful Code - by mmki - 06-22-2010, 04:11 AM
RE: VB 2008 - Useful Code - by Assists - 06-24-2010, 06:51 PM
RE: VB 2008 - Useful Code - by Julie - 06-24-2010, 07:51 PM
RE: VB 2008 - Useful Code - by Zubb - 07-19-2010, 02:06 PM
RE: VB 2008 - Useful Code - by Toxic Injection - 07-20-2010, 09:14 AM
RE: VB 2008 - Useful Code - by RedOwn - 07-21-2010, 06:31 PM
RE: VB 2008 - Useful Code - by Break - 12-22-2010, 01:34 PM
RE: VB 2008 - Useful Code - by ƃu∀ ıʞƃu∀ - 11-25-2012, 10:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get Country Code In 1 Line Of Code. wchar_t 13 4,073 11-28-2012, 06:49 AM
Last Post: Cubs
  [Pandora Incorporated] Visual Basic 2008 - Source Code Grabber [VIDEO TUTORIAL] Marik™ 13 4,197 05-23-2011, 06:41 PM
Last Post: KoBE
  [Pandora Incorporated]Visual Basic 2008 -MD5 Encryptor [VIDEO TUTORIAL] Marik™ 2 1,504 05-13-2011, 11:06 AM
Last Post: Imports System.Net
  [Pandora Incorporated] Visual Basic 2008 - Text To Speech [VIDEO TUTORIAL] Marik™ 1 1,476 04-14-2011, 05:37 PM
Last Post: Emily
  [Help] [VB.NET 2008] Textbox Contents Encryption. Example 4 3,734 02-23-2011, 01:16 AM
Last Post: Example

Forum Jump:


Users browsing this thread: 2 Guest(s)