WHAT'S NEW?
Loading...

Create DLL in VB.Net


How to create DLL in VB.Net, using this simple line of code, you may understand what is the function of DLL in VB.Net and how it works. The purposed of this, once you have a DLL, you can call anytime your procedure if needed by adding reference in your project where your folder name DLL saves. DLL stand for Dynamic Link Library, a collection of subroutines stored on disk, which can be loaded into memory and executed when accessed by a running program.

Here are the steps
1.       Start Visual Basic, instead of windows form appear in your window, click Class Library and name it MyClassLibrary.
2.       Copy and Paste this code in your Class1
Public Class Class1
    Public Function Add(ByVal Num1 As Integer, ByVal Num2 As Integer)
        Dim result As Integer
        result = Num1 + Num2
        Return result
    End Function

    Public Function Subtraction(ByVal Num1 As Integer, ByVal Num2 As Integer)
        Dim result As Integer
        result = Num1 - Num2
        Return result
    End Function

    Public Function Multiplication(ByVal Num1 As Integer, ByVal Num2 As Integer)
        Dim result As Integer
        result = Num1 * Num2
        Return result
    End Function

    Public Function Division(ByVal Num1 As Integer, ByVal Num2 As Integer)
        Dim result As Integer
        result = Num1 / Num2
        Return result
    End Function
End Class
3.       Finally, Click Save All, make sure you save properly where you folder is located, because you can call anytime if needed in your project.
4.       Click Build MyClassLibrary
5.       Now, we’re already created DLL.
6.       Close your program.
The above code simply created to show you on how to create simple DLL in your project. You can create complex DLL code if you can manage the function of its control or you can download through internet and modify the code.
7.       Open Visual Basic and create new project, name it My Simple DLL, add 2 textbox and 1 button. Name your textbox1 as txtnum1 and textbox2 as txtnum2, and button1 as btncalculate.
8.       Now, we are going to add our DLL we’re already created to our project.
9.       In your solution explorer, double click My Project --> References --> Add --> and click Browse tab OR click  Project between Build and View, locate Add Reference  and click browse tab, and locate you folder where you DLL saves you’ve already created.
10.   <your folder name> --> bin --> Release --> <MyClassLibrary.dll>
11.   Finally, you’ve already add MyClassLibrary.dll in your project.
12.   Copy and Paste this code on your btncalculate.
Imports MyClassLibrary

Public Class Form1

   Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculate.Click
        Dim x As New Class1
        Dim HoldMyData As Integer

        HoldMyData = x.Add(txtnum1.Text, txtnum2.Text)
        MessageBox.Show(HoldMyData)

    End Sub
End Class
  Hope this very helpful…

Create Module and Class in VB.Net



How to create Module and Class in VB.Net? Both of them have capabilities to handled all controls and more or less the same functionality, however there’s something difference among them.
Obviously, the declaration of variables and how they construct the proper syntax, it depends on the programmer’s side. In this tutorial, I’ll show you the difference of Module and Class in constructing code, but the same output.

These code are used in Module and Class and place it on different button.

Public Class FrmModuleAndClass

    Private Sub btnmodule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodule.Click

        Dim myhold As String
        '________________________________________________________'
        'I declared variable myhold to hold mymodule,
        'the name of my module                                   '
        '________________________________________________________'
        myhold = mymodule.getdata(txtfnamemodule.Text, txtlnamemodule.Text)
        MessageBox.Show(myhold, "My Module")
        '----------------------------------------

        'above code call mymodule that returns parameters
    End Sub

    Private Sub btnclass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclass.Click

        Dim myhold As New myclassname
        '________________________________________________________'
        'I declared myhold variable to hold my new object name   '
        'myclassname, the name of my class                       '
        '________________________________________________________'

        Dim holdmydata As String
        '________________________________________________________'
        'above code holdmydata hold myclassname class            '
        '________________________________________________________'

        holdmydata = myhold.getdata(txtfnameclass.Text, txtlnameclass.Text)
        MessageBox.Show(holdmydata, "My Class")
        '----------------------------------------

        'above code call myclass that returns parameters
    End Sub
End Class
______________________________________________________
Code for my Module

Module mymodule

    Public Function getdata(ByVal Fname As String, ByVal Lname As String) 'this line of code return 2 parameter value

        Dim myname As String

        myname = Fname & " " & Lname
        Return myname

    End Function
End Module

Code for my Class

Public Class myclassname

    Public myname As String

    Public Function getdata(ByVal Fname As String, ByVal Lname As String) 'this line of code return 2 parameter value

        myname = Fname & " " & Lname

        Return myname

    End Function
End Class

My Sample Screen shot:


Have you noticed when you declared variable name? In Class, first you create Dim VarName as New ClassObjectName to tell visual basic that you are setting up a variable name, while Module there's no need to create, that's the difference. You could not write directory the code without declaring New ClassObjectName from the Class name. 

How to create Relative Reference in Excel using Macros



Here are the steps:
1.   In Sheet 1 column A3, B3, C3, and D3 type the following column name: Name of students, Subject, Grade, and Remarks.
2.   Use Relative Reference to start record the name of students. Change the name macro to Listofmystudents.
3.   Here are the list of names to record under the Name of students:

Joseph Zurg
Mark Trulz
Lawrence Falk
Matt Trickle
Nicole French
Cris Bruz
Angelic Cane
Yangez Markgauze
Nortdelle Howard
Manyalk Kyade


4.   Then click to Stop Recording.
5.   Now, you can run your relative macros somewhere in your sheets anywhere the cells is active.
6.   Under Subject column. Use Relative Reference to start record the student subject and name it Studentsubjects. Then type the following Subject.

Math
English
Programming
Science
English
Math
Programming
English
Science
Math

7.   Then click to Stop Recording.
8.   Now, you can run your relative macros somewhere in your sheets anywhere the cells is active.
9.   Under the Grade column. Again, use Relative Reference to start record the student grade and name it Studentgrade. Then type the following Grade.

90
74
85
71
96
80
91
70
89
72

10.   Then click to Stop Recording.
11.   Now, you can run your relative macros somewhere in your sheets anywhere the cells is active.

To create a Remarks, we want to record again using if statement. The purposed is, if you want to determine either the student’s Passed or Failed just simply run the macros, automatically the macros filled the remarks.

1.   Under Remarks column. Again, use Relative Reference to start record the student remarks and name it Studentsremarks. Then type the following formula.
2.   =IF(C4<75,"Failed","Passed") in D4 under Remarks column
3.   Then click to Stop Recording.
4.   Now, you can run your relative macros somewhere in your sheets anywhere the cells is active.

You can create your own layout separated on your actual work using macros and run it if needed.
HOW?
1.   In Sheet 2, run your macros name: Listofmystudents in C5, Studentsubjects in D5, Studentgrade in E5, and Studentsremarks in F5. Expand the width of each column that fit to your data.
2.   Now, we want to record our layout. Again, use relative reference to start record and name it Fillmyownlayout.
3.   Layout your own design, then click to Stop Recording if already done.
4.   Now, you can select the name of your Relative Macros to run somewhere in your Sheets anywhere the cells is active.

How to create Macros with Absolute and Relative References

An Excel Macro is a set of instructions that can be triggered by a keyboard shortcut, toolbar button or an icon in a spreadsheet. Macros are used to eliminate the need to repeat the steps of common tasks over and over.
Tasks such as adding or removing rows
 and columns, protecting or unprotecting worksheets, selecting a range of cells, or adding the current date to a spreadsheet. In Excel, macros are written in Visual Basic for Applications (VBA).

Recording MacrosWhen you record a macro, Excel stores information about each step you take as you perform a series of commands. You then run the macro to repeat, or "play back," the commands.

Here are the basic steps on how to create macros

1. In excel default tab noticed that there’s no Developer Tab appear in ribbon, in order to do that.
2. In Office Button, click office button and just below click Excel Options.
3. In an Excel Options, click on the Popular. If you notice we have 3 top options for working with windows.
4. Check the box show developer tab in the ribbon.
5. Now you have already a developer tab in your ribbon.


Let us recall what is Relative and Absolute Reference:

Relative Cell References that will change in relation to the new location of the formula. Relative references identify cells based on their relationship to the cell containing the reference.

Absolute Cell References that remain the same when a formula is copied to a new location. No matter where the formula or the values in the original cell are moved, the formula will continue to refer to the same cell.


These tutorials show on how to create simple Marcos with absolute and relative references.

Absolute Reference:

1.   Create column name, First name in A1 and Last name in B1.
2.   Now, we want to record our macros. In your tab ribbon, click the developer tab.
3.   Before we start typing the name. First, click Record Macros.
4.   When you noticed, another dialog windows appear. Name you macros as MacAbsoluteRecord. If you want for short cut key, it’s your choice. Then click OK.
5.   It’s time to add the data in your first name and last name. So, we have 3 input rows.
6.   Now, Stop Recording.
7.   To run macros. Click on sheet 2, Create column name, First name in A1 and Last name B1.
8.   In your developer tab, click macros and locate the name of your macros you’ve already created “MacAbsoluteRecord”.
9.   Click run.
10. If you want to run your macros anywhere in your sheets, the same column and rows that the record you’ve created will display, because absolute reference does not change whenever the formulas created in your worksheets.
11. You may able to run you macros as shortcut command based on your short cut key. Just like Ctrl + m.

Relative Reference:

1.   Before we start typing our data, we want to records first as relative reference. In order to do that, in your developer tab under Record Macros, click Use Relative References.
2.   When you notice, Use Relative Reference is now active and then click Record Macros. Name it, "MacRelativeRecord".
3.   Now, it time to record. In your column name, type Name and Gender. So we have 3 input rows in Name and Gender
4.   Then stop Recording.
5.   In your developer tab, click macros and locate the name of your macros you’ve already created “MacRelativeRecord”.
6.   Click anywhere in your sheets to run macros and select the name of your macros.
7.   Noticed when you run the relative reference, the first destination of your macros record is based on the intersection of column and row where the cell is active, because relative references change whenever the cell is active.


Here are the examples Screenshot
Absolute References:

            Relative Reference


How to create my own class in VB.Net


This simple line of codes and Screenshot determines the invalid type required in textbox. I created my own class to control the invalid typing of data required in textbox. Example, the textbox required only a data that accepts all string input and if the user’s prompt to input the numeric value, invalid message display that the field required only text input.
Here are the example Screenshot:
Message box display field is required.


Message box display numeric input is not allowed.
----------------------------------------------------------------------------------
Here are the codes:
This is the class Declaration
Public Class validator
    Private Shared title As String = "Invalid Entry"
    Public Shared Property mytitle()
        Get
            Return title
        End Get
        Set(ByVal value)
            title = value
        End Set
    End Property

    Public Shared Function ispresent(ByVal textbox As TextBox) As Boolean
        If textbox.Text = "" Then
            MessageBox.Show(textbox.Tag & " Field is required.", mytitle)
            textbox.Select()
            Return False
        Else
            Return True
        End If
    End Function
    Public Shared Function notrequirenumeric(ByVal textbox As TextBox) As Boolean
        If Microsoft.VisualBasic.IsNumeric(textbox.Text) Then
            MessageBox.Show(textbox.Tag & " Numeric is not allowed", mytitle)
            Return False
        Else
            Return True
        End If
    End Function
End Class
This is  the windows form application
Public Class FrmEnterData

    Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
                    End Sub

          Call isvalid() 'call my method name isvalid

    Private Function isvalid() As Boolean ' this is my method name isvalid that return value.
        Return validator.ispresent(txtinputdata) AndAlso validator.notrequirenumeric(txtinputdata)
    End Function
End Class
Steps on how to create my own class

1.  Open your Visual Basic.Net and add Windows form application
2.  Put 1 textbox and 1 button in your windows form
3.  To create a class, click the project menu and add windows form
4.  Noticed: the default name is the name of the form.
5.  Now,in your templates, locate the name Class
6.  The default name of your class is Class1.vb, you can change it.
7.  Finally, class is created and that’s the time you can create your own class.

Actually the code above is not appropriate for formative invalid input, rather it shows how to create class. I created code to detect if the users prompt to input invalid data. So, try this code.
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
         'for invalid numeric input
        Dim testChars() As Char = "0123456789".ToCharArray        If testChars.Contains(e.KeyChar) = False Or e.KeyChar = Chr(Keys.Back) Then
            e.Handled = False
            ErrorProvider1.Clear()        Else
            e.Handled = True
            ErrorProvider1.SetError(TextBox1, "Numeric is not allowed")        End If
         'for invalid letters input
        Dim test() As Char = "0123456789".ToCharArray        If Not test.Contains(e.KeyChar) = False Or e.KeyChar = Chr(Keys.Back) Then
            e.Handled = False
        Else
            e.Handled = True
            MessageBox.Show("Letter is not allowed")        End If
    End Sub