Wednesday, May 15, 2013

VB.NET Option Explicit

Today I will tell you about using the Option Explicit statement. The Option Explicit has two modes. On and Off mode. If Option Explicit mode in ON , you have to declare all the variable before you use it in the program . If not , it will generate a compile-time error whenever a variable that has not been declared is encountered .If the Option Explicit mode is OFF , Vb.Net automatically create a variable whenever it sees a variable without proper declaration

By default the Option Explicit Statement is always On.

Option Explicit Off
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
someVariable = "Option Explicit ON"
MsgBox(someVariable)
End Sub
End Class


Here "someVariable" is not declared , because the Option Explicit Of , without any compiler error you can continue the program.

Saturday, May 4, 2013

Using Nothing Syntax in VB.NET




When coding in VB.NET you will sometimes want to declare a variable or a string as Nothing. There is a really way to do this and it takes about 1 line of code. Here is how you can do it.


 Sub Main2()
 Dim sString As String = Nothing

 If sString = Nothing Then
     Msgbox("You've got nothing")
 End If

You can also ofcourse combine Nothing with an If-else statement which will help you test to see if the string is actually Nothing.

Saturday, April 27, 2013

How to use the ProgressBar control!

Today I am going to show you how to use the progress bar control in VB.NET.


This is fairly simple to do and really takes only 1 line of code.

ProgressBar1.Value = ProgressBar1.Value + 55

This will increment the ProgressBar's value by 55 from whatever value it is. As you can see this is very simple and will be very useful for you. :D



Wednesday, April 24, 2013

[VB.NET] Declaring Constants

Today I am going to show you how to declare constants in VB.NET.

We are going to be working with this example program today.


Module constantsNenum
   Sub Main()
      Const PI = 3.14149
      Dim radius, area As Single
      radius = 7
      area = PI * radius * radius
      Console.WriteLine("Area = " & Str(area))
      Console.ReadKey()
   End Sub
End Module
This program will show you basically how to declare constants.


Dim radius, area As Single
This line of code declares that radius and area should be Single numbers.


radius = 7
This basically says that radius = 7.


area = PI * radius * radius

This declares that the variable are is PI * radius * radius.

And then at the end this outputs the area :D

Sunday, April 21, 2013

Using Variables in VB.NET

Today I am going to show you an easy way to use variable in your VB.NET application.



The easiest way to do this is using the statement "Dim". This will make it so you can declare all of your variables...so for example

Dim mystring as String

This will declare the variable as a String....and you can also do something like this....

Dim mystring as String = "hello"

This will actually give the variable mystring a value which in this case is "hello"

But let's say you want to declare something other than a string...like an integer for example...this can be easily done by setting the variable to an integer instead of a String like this...

Dim mynumber as Integer = 13



When declaring Integer's you do not need to use strings as it is automatically detected...

I hope this tutorial helped you learn a little more about variables in VB.NET!

Wednesday, April 17, 2013

For Loops in VB.NET

This first type of loop we'll look at is called a For Loop. It is the most common type of loop you'll use when you program. We'll use one to add up our 4 numbers, and then discuss the code. Study the following. In fact, create a new Project. Add a button to your new Form. Double click your new button and type the following code for it:


Dim answer As Integer
Dim startNumber As Integer
answer = 0
For startNumber = 1 To 4
answer = answer + startNumber
Next startNumber
MsgBox answer

Run the program, and see what happens when you click the button. The number 10 should have been displayed in your message box.



[VB.NET] If-Then Statements

What is conditional logic? Well, it's something you use in your daily life all the time, without realising you're doing it. Suppose that there is a really delicious cream cake in front of you, just begging to be eaten. But you are on a diet. The cake is clearly asking for it. So what do you do, eat the cake and ruin your diet? Or stick to your diet and let somebody else have that delicious treat? You might even be saying this to yourself.

An example would be. If I eat the cake Then my diet will be ruined.

Here is an example of using if-then statements


Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim firstname As String
firstname = "Bill"
If firstname = "Bill" Then MsgBox("firstname is Bill")
End Sub

Run the program and see what happens. You should get a Message Box with the words "firstname is Bill" in it.What we did was to set up a string variable and put the name "Bill" into it. When then used conditional logic to test what was in the variable. In fact, we used an If statement. 

We said: If the variable called firstname holds the value "Bill" Then display a Message Box

Saturday, April 13, 2013

How to detect an ENTER click in VB.NET!

This can be easily be used to detect an enter click in VB.NET! It only takes a couple lines of code. Here is how you can do it.


Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Select Case (keyData)
            Case Keys.Enter
                ButtonX4.PerformClick()
                Return True

        End Select
        Return MyBase.ProcessDialogKey(keyData)
    End Function

This is a real value tutorial when you want to learn visual basic coding. Next Tutorial coming soon!

Friday, April 12, 2013

[VB.NET] How to save data to the registry.

Today I will show you how to sava data to your registry. I will show you the following things.

- Check if a registry key value exists.
- Create sub keys and add values to them.




 Checking if a registry key is set

If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Drivers", "Hash", Nothing) Is Nothing Then
'Your Code Here
End If

Be sure to change the "HKEY_CURRENT_USER\Drivers" and "Hash" to whatever you want.

Creating a new sub key

To create a subkey all you have to do is this.

My.Computer.Registry.CurrentUser.CreateSubKey("Hash") 

Change the "Hash" to whatever you want

Adding a value to your new sub key

Dim Hash as String = "yourhashkeyvalue"
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Drivers", "Hash", Hash)

So this code will input the value of Hash ("yourhashkeyvalue") and input that into the has subkey.


If you are looking for a good registry cleaner then be sure to check out this site.


How to Create Variables in VB .NET


With Visual Basic, and most programming languages, what you are doing is storing things in the computer's memory, and manipulating this store. If you want to add two numbers together, you put the numbers into storage areas and "tell" Visual Basic to add them up. But you can't do this without variables.
So a variable is a storage area of the computer's memory. Think of it like this: a variable is an empty cardboard box. Now, imagine you have a very large room, and in this room you have a whole lot of empty cardboard boxes. Each empty cardboard box is a single variable. To add two numbers together, write the first number on a piece of paper and put the piece of paper into an empty box. Write the second number on a piece of paper and put this second piece of paper in a different cardboard box.
Now, out of all your thousands of empty cardboard boxes two of them contain pieces of paper with numbers on them. To help you remember which of the thousands of boxes hold your numbers, put a sticky label on each of the two boxes. Write "number1" on the first sticky label, and "number2" on the second label.
What have we just done? Well, we've created a large memory area (the room and the cardboard boxes), and we've set up two of the boxes to hold our numbers (two variables). We've also given each of these variables a name (the sticky labels) so that we can remember where they are.
Now examine this:
Dim number1 As Integer
Dim number2 As Integer
number1 = 3
number2 = 5

That's code from Visual Basic Net. It's VB's way of setting up (or declaring) variables.
Here's a breakdown of the variable Declaration:
Dim

Short for Dimension. It's a type of variable. You declare (or "tell" Visual Basic) that you are setting up a variable with this word. We'll meet other types of variables later, but for now just remember to start your variable declarations with Dim.

number1

This is the cardboard box and the sticky label all in one. This is a variable. In other words, our storage area. After the Dim word, Visual Basic is looking for the name of your variable. You can call your variable almost anything you like, but there are a few reserved words that VB won't allow. It's good practice to give your variables a name appropriate to what is going in the variable.


As Integer
We're telling Visual Basic that the variable is going to be a number (integer). Well meet alternatives to Integer later.

Number1 = 3


The equals sign is not actually an equals sign. The = sign means assign a value of. In other words, here is where you put something in your variable. We're telling Visual Basic to assign a value of 3 to the variable called number1. Think back to the piece of paper going into the cardboard box. Well, this is the programming equivalent of writing a value on a piece of paper
Now that you have a basic idea of what variables are, let's write a little piece of code to test them out. First, though, let's have our first look at the coding window.
To make life easier, we're going to put a button on our form. When our button is clicked, a little message box will pop up. Fortunately, there's no coding to write for a button, and very little at all for a message box.

Wednesday, April 10, 2013

[VB.NET] Integrating a proxy system into your application

This is a nice and simple tutorial on how to integrate a proxy system into your application. With these easy steps we will have you up and running with your own proxy integration, that will allow you to change your ip in your application. 

Step 1) Add a brand new module to your visual basic project as seen in the image below, name it Proxy.vb and click add




Step 2) Add this code to your proxy module. This is what your code should look like after you are done.


Module Proxy
    ' The structure we use for the information
    ' to be interpreted correctly by API.
    Public Structure Struct_INTERNET_PROXY_INFO
        Public dwAccessType As Integer
        Public proxy As IntPtr
        Public proxyBypass As IntPtr
    End Structure

    ' The Windows API function that allows us to manipulate
    ' IE settings programmatically.
    Private Declare Auto Function InternetSetOption Lib "wininet.dll" _
    (ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, _
     ByVal lpdwBufferLength As Integer) As Boolean

    ' The function we will be using to set the proxy settings.
    Public Sub RefreshIESettings(ByVal strProxy As String)
        Const INTERNET_OPTION_PROXY As Integer = 38
        Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
        Dim struct_IPI As Struct_INTERNET_PROXY_INFO

        ' Filling in structure
        struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
        struct_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy)
        struct_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("local")

        ' Allocating memory
        Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))

        ' Converting structure to IntPtr
        System.Runtime.InteropServices.Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
        Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
    End Sub
End Module

Step 3) To easily Change your proxy within your application ....all you need to do is this code.

Proxy.RefreshIESettings("proxy:ip") 'Make sure your ip looks like "111.111.1.1:80"






Hopefully this guide has belped you and if you need any help let me know.

A next tut might be how to spoof your browser and referrer and how to make it look like you are using different internet browsers.




How do I get going with Visual Studio Professional?

I get alot of people who wonder how they can start off coding with vb.net, and they have no idea what to even install their first time coding. You are going to want the following software :



Visual Studio Professional (2012) - http://www.microsoft.com/visualstudio/eng/downloads

This is the best software to help you learn visual studio and to become a master in vb.net or many languages on the web.

1) You are going to want to start off by installing the visual studio program from the link above. It is a very easy install process and it takes about 10-15 minutes to install.

2) Make sure when you first start off running the program you select a blank form as a vb project.

You can get a ton of visual studio training and guides online if you are not sure about what to do and hopefully this guide helped you a little bit.

Some Great Resources

Youtube Video to help with install:


Thanks for reading this quick guide and hopefully I helped you!

Cool Background for Visual Studio!

Cool Background image I found for Visual Studio.


Original Src here: http://www.cnmeonline.com/wp-content/uploads/2013/03/visualstudio-wallpaper-05.jpg

GetElementsByTagName VB.NET Tutorial

You can easily get code within tags by using this very simple code.


Dim PageElements3 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input") 
            For Each CurElement As HtmlElement In PageElements3
                If CurElement.GetAttribute("id") = "strFirstName" Then
                    WebBrowser1.Document.GetElementById("strFirstName").Focus()
                    CurElement.InnerText = datastringbefore(0)
       End If
Next

Where input = the tag you want to search for
     and
Where id = the attribute of the tagname you are searching for

Hope you guys enjoyed this quick tutorial.

[VB.NET] How to generate a random number

This can be easily done with this simple code.


Dim RandomClass As New Random()
Dim RandomNumber As Integer
RandomNumber = RandomClass.Next(1, 7) 'We want a number between 1 and 7

Just be sure to substitute the 1 and 7 with any values you would like.

Using the GetBetween() Function


For this tutorial I will show you how to use the GetBetween() function to grab specific data between tags from a particular source.

You can do this easily by inputting this code...

Dim data As String = GetBetween(sourcecode, "<h3>", "</h3>") 'Set the tags you want to use
Dim datastringbefore() As String = Split(data, " ") 'We want to split the data where there is a space
Dim firstname As String = datastringbefore(0) 'This will get the first data item from the string

If we chose datastringbefore(2), it would select the text after the space.

How to wait for a webbrowser to finish loading.

This can easily be done with 3 lines of code.

 Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
                    Application.DoEvents()
 Loop

What this does it run the application events until the webbrowser.readystate is complete.