Generating Random Numbers
VB.Net provides a very easy way to generate random numbers by providing a seed value. Because the randomness of the number depends on the seed value that you plant and therefore, to obtain a truly random number at unpredictable sequence, the seed must also be a truly random number itself. Hence to get the seed to be truly random, programmers usually use a value converted from the current date and time. As such, the random number is then generated.
Dim Dice As Integer
Dim Rand As New Random(Val(DateTime.Now.Second)) '<- convert current time seconds to a value to be used as seed
Dice = Val(Rand.Next(1,6).ToString()) '<-- provide the lower and upper limit of 1 and 6 of a dice
The random number generated will be between 1 and 6
That shows how random numbers are generated in VB.Net
VB.NET - Generate Random Numbers
Posted by Fluffy | 12:27 AM | generate random numbers, VB.NET | 2 comments »VB.NET Declaration of Variable Types
Posted by Fluffy | 3:27 PM | Declaration of Variable Types, VB.NET | 0 comments »Declaration of Variable Types in VB.net
There are 5 types of variable declaration types in VB.net, they are Dim, Redim, Static, Public or Private. Although VB.net allows these declarations to appear just anywhere within the body of the codes, it is best to declare all the variables at the beginning (best practices). Below briefly describes the 5 types of variable declaration and what they are used for:
Dim
Used to declare variables. Whenever the procedure is called, the variable value is reset to default value. For instance, an integer declaration will become zero, and a string declaration will be reset to empty string.
The ReDim keyword is only used to redimension an array.
Static
Used to declare and hold the values in the variables. For instance, each time the procedured is called, the data stored in the variable is retained.
Public
Used to declare variables within a module. The variable can be accessed and called anywhere in the project.
Private
Used to declare variables within a module. The variable is only accessible and called within the same module.
Merry Christmas & Happy New Year 2009
Posted by Fluffy | 5:49 AM | happy new year 2009 | 0 comments »VB Egg wishes you merry christmas & a happy new year 2009..
Jagged Arrays
Jagged arrays is a multidimentional array in VB.NET. Jagged arrays are also known as array of arrays where the the length of each array can be different. For instance, the first array can have 8 items, the second array can have 6 items and the third array can have 3 items and so on. Jagged array can be useful in many circumstances where the number of items differs for each arrays such as in recipes. For example, Food A is made up of 8 ingredients, Food B is made up of 6 ingredients while Food C is made up of 3 ingredients etc.
The codes below illustrates the application of jagged arrays.
Dim Food(2)() ' declare 3 types of foods
Food(0) = New String() {"Salt","Egg","Butter") 'first food is made up of the 3 ingredients
Food(1) = New String() {"Egg","Sugar","Butter","Flour","Banana","Water"}
Food(2) = New String() {"Carrot","Cabbage","Mayonaise","Lettuce"}
'if we were to output the selected item below
Msgbox(Food(1)(2)) 'the result will be "Butter"
Hope this helps you understand the use of jagged arrays in VB.NET better.
Arrays in VB.NET
Arrays are very important programming constructs that allow us to store data during programming and runtime. Various types of data can be stored depending on which datatype is declared. For instance, we will create an example to declare an array to store 5 kinds of fruits Banana, Orange, Apple, Papaya and Strawberry. So we would declare the array as follows :
Dim Fruits(4) as String
Here we have declared the Fruit arrays as string datatype. If we intend to store numeric values, then we will have to declare the array as Integer or Double. Also, the reason we declare the Fruits array as having an index of (4) is because all arrays are zero-based, meaning the array index starts from zero. Hence in this example we will have (0), (1), (2), (3), and (4). We have a total of 5 arrays to store data.
To store the fruit names into the arrays, we will do the following :
Fruits(0) = "Banana"
Fruits(1) = "Orange"
Fruits(2) = "Apple"
Fruits(3) = "Papaya"
Fruits(4) = "Strawberry"
After that, to test the data, we can run the following codes :
MsgBox("The " & Fruits(3) & " is very sweet.")
and the result we get is : The Papaya is very sweet.
For instance somewhere in the application, we decided that we wanted to allow the user to include 2 additional fruits Watermelon and Cherry. We can always allow that by using ReDim.
See the example below:
ReDim Fruits(6)
Guess what, the array has been resized to allow the storing of 7 data. Remember that array is zero-based? Hence, now we have (0),(1),(2),(3),(4),(5),(6). However the initial data that we stored, the Banana, Orange, Apple, Papaya and Strawberry fruits are all gone after we resize the array. In order to preserve the initial data, we need to specified it with the word Preserve as follows:
ReDim Preserve Fruits(6)
Now the initial fruits are preserved and we just add on like this to the arrays
Fruit(5) = "Watermelon"
Fruit(6) = "Cherry"
Back to VB Egg
Registering Visual Basic Express Edition
Posted by Fluffy | 2:59 AM | register visual basic vb express, VB.NET | 0 comments »Register Visual Basic Express
By installing the free version of Visual Basic Express Edition, be it VB2003, VB2005 or the latest VB2008 and above, it will function as an unregistered copy and will only work for about a month before it disable itself. Therefore you need to register it in order to continue developing VB projects and applications beyond this grace period. Registration is easy as the program will prompt you to register everytime you start the application. It will show how many remaining days until you are not able to use it. You need to register with a valid email address. To register, click the link 'Register Now' and enter your email address. If you do not have an email address yet, you can easy get one for free like hotmail, gmail and yahoo mail.
Once registered, a registration key will be provided to you. Just copy and paste the registration key you obtained into the designated field in the registration section of the application and viola! Registration is complete.
Back to VB Egg
Visual Basic Express Edition 2008
Posted by Fluffy | 2:35 AM | VB.NET, Visual Basic Express Edition 2008 | 0 comments »Visual Basic Express Edition 2008
Visual Basic Express Edition 2008 is a free version of the latest Visual Basic 2008. It is the ideal tool for building object-oriented programming applications in the minimum time possible. It contains all the basic features of the Visual Basic minus the reporting functionality such as Crystal Reports and Microsoft Reporting and other 3rd party database connections. Visual Basic Express Edition is available for free download at Microsoft Website or you can download directly at :
http://www.microsoft.com/express/vb
Back to VB Egg
Vbx / VB10
VB10 or Visual Basic 2010 or sometimes even called VBx is the next version of Visual Basic after 2008 ( VB9 ). As it is still very early to tell exactly what it is going to be like at this stage, we do have some rough idea on it at this point of time.
It will probably features many great enhancements of the VB9 version and with focuses on creating or developing Silverlight applications. Silverlight is a new light weight edition of the .NET Framework which allows developers to create rich applications in .NET languages.
It is believed that the idea is to allow developers to develop the client side's applications with .NET enabled languages instead of using javascript, and therefore making it possible for the client and server side of the web applications to be developed under the same language.
Applications developed in VB10 is also fully compatible with the previously developed VB9, VB8 and VB7 versions.
Back to VB Egg
VB.NET : Data Grid View
Posted by Fluffy | 3:19 AM | datagrid datagridview data grid view, VB.NET | 0 comments »Using Datagridview in VB.NET
If u have followed my previous post (method to store the overtime pay data into a datatable), you will now see how to use DataGridView to show the data that you have stored on the screen.
First, on the Visual Basic designer interface, drag the DataGridView from the toolbox to the form. The toolbox can be seen on the left hand side sidebar. If you still can't find it, go to View section on the toolbar, and the select toolbox.
Secondly, drag a button control onto the form as well.
Thirdly, double click on the Button control and the code behind the button will prompt.
Then, type the following code. This code instruct the DataGridView to display data from the first table in the dataset. A zero indicates the first table.
Me.DataGridView1.DataSource = ds.Tables(0)
Lastly, start run the code and click on the button that you just added. You should now see the data in the datatable displayed.
Back to VB Egg
VB.NET : DataSet, DataTable, DataRow and DataColumn
Posted by Fluffy | 2:54 AM | dataset datatable datacolumn datarow data table row, VB.NET | 0 comments »Understanding DataSet, DataTable, DataRow and DataColumn in VB.NET
VB.NET allows the users to use a very convenient way to store data that is, to store into virtual tables. I will briefly explains how all these objects (dataset, datatable, datarow, datacolumn) interconnects. A virtual table is also known as a datatable, which is stored into a dataset. So, it can be said that a dataset is a collection of datatables. In other words, a dataset can hold many datatables. So what makes up a datatable? Well, a datatable is make up of many datarows, which of course depends on how many records a datatable might have. Datacolumn then, represents the columns of a datarow.
Below is a simple example to show you how to program with these objects and to show you how they worked. It is a simple code to store the number of hours an employee is doing overtime and how much the employee is paid for the duration. Assuming the hourly rate is set to 20 dollars per hour.
Public Sub OverTime(ByVal No_Of_Hours As Integer)
'declare dataset
Dim ds As New DataSet
'declare datatable as dt
Dim dt As New DataTable("dt")
'declare datarow
Dim dr As DataRow
'declare the datacolumns
Dim dct1 As New DataColumn("dcHour")
Dim dct2 As New DataColumn("dcTime")
'hourly rate of overtime pay
Dim HourlyRate As Double = 20
'declare the datatype of the datacolumns
dct1.DataType = GetType(Integer)
dct2.DataType = GetType(Double)
'add the datacolumn, column1 and column2 into the datatable
dt.Columns.Add(dct1)
dt.Columns.Add(dct2)
'create a new row for the datatable
dr = ds.Tables("dt").NewRow
'insert the data into the datarows (column1 and column2)
dr("drHour") = No_Of_Hours
dr("drAmount") = No_Of_Hours * HourlyRate
'add newly created row into the datatable
ds.Tables("dt").Rows.Add(dr)
'add the datatable into the dataset
ds.Tables.Add(dt)
End Sub
And, now we have successfully inserted the data (number of hours & overtime pay amount) into the datatable in the dataset.
Back to VB Egg
VB : Volume to Surface Area Converter Function
Posted by Fluffy | 7:02 PM | VB.NET, VB6, volume to surface area converter | 0 comments »Convert Volume to Surface Area in Visual Basic
Here's a simple VB function that i have included to demonstrate the conversion of amount volume to the surface area of the sphere container.
How to use this function :
For instance, we want to convert the VOLUME of 4000 cm3 (about a gallon) of a sphere to its SURFACE AREA, we can use the function below to access its formula.
For Example :
SurfaceArea = VolumeToSurfaceArea( 4000 )
SurfaceArea = 1218.75
Hence the surface area is 1218.75 cm2
Private Function VolumeToSurfaceArea(ByVal Volume As Double) As Double
' Sphere Volume to Surface Area
Dim R As Double
R = ((Volume * (3 / 4) * (7 / 22)) ^ (1 / 3))
Return (4 * (22 / 7) * R * R)
End Function
Back to VB Egg
VB.NET : Round Up & Round Down Functions
Posted by Fluffy | 8:38 PM | roundup and rounddown functions, VB.NET | 3 comments »RoundUp and RoundDown Functions in VB.NET
There are two very important functions that VB.NET lacks, they are : RoundUp and RoundDown functions. these two important functions are not readily available for use and as such, i have included both the functions here for you to play with.
Just copy & paste the codes below anywhere into your VB.NET projects and you are ready to access RoundUp and RoundDown functions. With these functions, rounding in Visual Basic has never been easier!
Happy Programming!
Public Function RoundUp(ByVal InputVal As Double) As Double
' Round Up Function
Try
Dim Deci As Long = InStr(1, CStr(InputVal), ".", CompareMethod.Text)
If Deci > 0 Then
Return (CDbl(Mid(CStr(InputVal), 1, Deci)) + 1)
Else
Return (InputVal)
End If
Catch
MsgBox(Err.Description, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "RoundUp Error")
End Try
End Function
Public Function RoundDown(ByVal InputVal As Double) As Double
' Round Down Function
Try
Dim Deci As Long = InStr(1, CStr(InputVal), ".", CompareMethod.Text)
If Deci > 0 Then
Return (CDbl(Mid(CStr(InputVal), 1, Deci)))
Else
Return (InputVal)
End If
Catch
MsgBox(Err.Description, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "RoundDown Error")
End Try
End Function
Back to VB Egg
Beginner's Lesson On VB.NET
This is beginner's vb.net lesson #1 on how to output a "Hello World" messsage by creating a simple program.


3. Double click on the button that you just dragged on the form. See picture below.

4. The code will then appear. Type the following code into the empty space between, as illustrated in the image below.
MsgBox("Hello World", MsgBoxStyle.OkOnly)
5. Test Run the application by pressing F5 key. Click on the button as shown in the picture below and a message box will stating "Hello World" will then appear.

----- End of tutorial. ------
Back to VB Egg
VB.NET Installation
This is an article about preparing and installing VB.NET software into your PC.
In this article, Express Edition is used for installation.
Express Edition is just great for beginners and novices compared to other editions. Generally the difference is that Express Edition has numerous limitations which is not much of a concern for new learners. The major limitations are, generally this editions is limited to the support of SQL and Access database only. Another limitations is the lack of reporting tools and functions.
Nevertheless, to begin the installation progress, click the links below to obtain the software.
VB.NET Express Edition is available for free download at :
http://www.microsoft.com/express/vb
SQL Express Edition can be downloaded separately at :
http://www.microsoft.com/express/sql
* Note: .NET framework is automatically included during the installation process. .NET framework is required in running any VB.NET applications.
Once the download is finished, follow the steps on the screen to complete the installation process. You may be required to reboot your PC after the installation process.
Back to VB Egg
Different versions of Visual Basic
Posted by Fluffy | 8:40 AM | Different versions of visual basics, VB.NET, VB6 | 0 comments »Versions of Visual Basics
.NET editions
1. Visual Basic 2002
Released in 2002. This is the first version released to software developers and many of them have found it to be a completely different languange and not paid much attention to it. This version is also known as VB 7.0.
2. Visual Basic 2003
An improvement of the previous version, particularly to the performance and reliability of the IDE and runtime. Also known as VB7.1.
3. Visual Basic 2005
Released to take advantage of .NET Framework 2.0. Microsoft has also created an Express Edition which is a free development environment edition for novices and learners.
This version is also known as VB8.0.
4. Visual Basic 2008
Released together with .NET Framework 3.5, Microsoft has added many new features such as LINQ support, lambda expressions and XML literals. Microsoft too, has created an Express Edition for this version. a.k.a. VB9.0.
5. Visual Basic 2010
Code named "VBx", or sometimes also known as VB10.0, this version has yet to be released. It is expected that this version will offer support for Dynamic Language Runtime and is planned to be part of Silverlight 2.0.
Visual Basic 6.0 and earlier are now officially known as Visual Basic Classic or VB Classic. These versions of Visual Basic are now incompatible with .NET versions.
Back to VB Egg
Advantages of .NET platform
Posted by Fluffy | 7:56 AM | .net platform framework advantage advantages, VB.NET | 0 comments ».NET Platform Advantages
Microsoft .NET is a software development platform based on virtual machine architecture. There are 3 main advantages of developing software under the Microsoft .NET platform:
1. Language Independent
Software applications can integrate with one another even though they are developed using different languages (such as VB, C++, C#, etc.).
2. Platform Independent
.NET applications can run on any operating system as long as .NET framework installed.
3. Hardware Independent
.NET applications can run on any hardware configurations whether it is web-based, windows based, web services or mobile applications etc.
Back to VB Egg
What is Visual Basic .NET?
Visual Basic .NET, or simply VB.NET is an entirely new version of the legacy Visual Basic 6.0. VB.NET is an object-oriented programming language designed and implemented to run on Microsoft .NET framework. As it is an entirely evolutionalized new version of Visual Basic, it is completely different and is not backward compatible with its predecessors. Thus, many software developers are facing a hard time migrating, integrating and redeveloping their software programs to take advantage of this latest .NET environment. Visual Studio .NET's Integrated Development Environment (IDE) is the main platform that many developers use to develop their software applications.
Back to VB Egg
Welcome to VB Egg.
Your ultimate site for Visual Basic Classic, VB6, VB.NET and VBx resources, codes and guides.
Back to VB Egg
