Post: VB.Net Snippets (Learn So VB Noobz)
11-26-2012, 05:43 PM #1
Sloth
Banned
(adsbygoogle = window.adsbygoogle || []).push({}); This thread is going to be dedicated to little snippets of code that do certain things which you can implement into your project.

Should I release the sources to these?

If you need some help with coding in VB then just skype me.

Enjoy.

[multipage=Snippets]
Please note that I am not going to the trouble of creating a project with it already implemented for you.

Remember to reference your imports.

HWID Generator

    
Imports System.Management
Public Class Form1
Dim HWID As String = String.Empty
Dim mc As New ManagementClass("win32_processor")
Dim moc As ManagementObjectCollection = mc.GetInstances()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

For Each mo As ManagementObject In moc
If HWID = "" Then
HWID = mo.Properties("processorID").Value.ToString()
TextBox1.text = HWID
Exit For
End If
Next
Exit Sub
End Sub
End Class



Check Whether a Website is Down or Not

    
Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
If My.Computer.Network.Ping(TextBox1.Text) Then
If Label1.Visible = False Then
Label1.Visible = True
End If

Label1.ForeColor = Color.LimeGreen
Label1.Text = "Online!"

Else
If Label1.Visible = False Then
Label1.Visible = True
End If

Label1.ForeColor = Color.Red
Label1.Text = "Offline!"
End If
Catch ex As Exception
End Try
End Sub
End Class




CodeDom Compiler (This one is special)

    
Imports System.CodeDom.Compiler
Imports Microsoft.VisualBasic
Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim icc As CodeDomProvider = New VBCodeProvider()
Dim parameters As New CompilerParameters()
parameters.GenerateExecutable = True
parameters.OutputAssembly = OutputPE
'Compiling parameters
parameters.ReferencedAssemblies.Add("System.dll")
parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll")
parameters.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
parameters.ReferencedAssemblies.Add("System.Data.dll")
parameters.ReferencedAssemblies.Add("System.Deployment.dll")
parameters.ReferencedAssemblies.Add("System.Drawing.dll")
parameters.ReferencedAssemblies.Add("System.Xml.dll")
parameters.CompilerOptions = "/filealign:0x00200 /optimize+ /platform:anycpu /debug- /target:winexe"
Dim results As CompilerResults = icc.CompileAssemblyFromSource(parameters, InputSource)
'Check if any errors
If results.Errors.Count > 0 Then
For Each CompErr As CompilerError In results.Errors
MessageBox.Show((("Line number " & CompErr.Line & ", Error Number: ") + CompErr.ErrorNumber & ", '") + CompErr.ErrorText & ";")
Compile(code.text, "ProgramName.exe")
Next
End If
End Sub
End Class



Program AutoUpdater.

Please use the .VBProj extension file as the solution is for VS 2010
You must login or register to view this content.


If you want more Quote me with what you want.
Last edited by Sloth ; 12-19-2012 at 08:27 PM.

The following 2 users say thank you to Sloth for this useful post:

Ronye West, Zack.
12-04-2012, 08:02 PM #2
Sloth
Banned
Pl0x Comment?
12-04-2012, 08:08 PM #3
CyberNomadic
Web Developer
Pretty cool. But add more snippets.
12-04-2012, 08:37 PM #4
Sloth
Banned
Originally posted by NomadsBoy View Post
Pretty cool. But add more snippets.

Added a CodeDom Compiler
12-08-2012, 10:59 PM #5
Sloth
Banned
Comment for Auto Updater Code
12-09-2012, 12:04 PM #6
Originally posted by KronosCloud View Post
Comment for Auto Updater Code


you going to upload it? and have you got time to send the pack of the themes
12-19-2012, 08:28 PM #7
Sloth
Banned
I have added autoupdater

---------- Post added at 08:28 PM ---------- Previous post was at 08:27 PM ----------

Originally posted by HD View Post
you going to upload it? and have you got time to send the pack of the themes


I'll go and grab the themes and Update the URL
12-19-2012, 09:45 PM #8
Originally posted by KronosCloud View Post
I have added autoupdater

---------- Post added at 08:28 PM ---------- Previous post was at 08:27 PM ----------



I'll go and grab the themes and Update the URL


thanks alot!

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo