Library tutorials & articles

Leverage the .NET Framework with Visual Basic.NET

DataTypes & Operators

Data Types

The following is based on the preliminary VB.Net documentation:

VB type .NET type Size Range
Boolean System.Boolean 4 bytes True/False
Byte System.Byte 1 byte 0-255 (unsigned)
Char System.Char 2 bytes 0-65535 (unsigned)
Date System.DateTime 8 bytes 01-Jan-0001 to 31-Dec-9999
Decimal System.Decimal 12 bytes 28 digits
Double System.Double 8 bytes +/-1.797E308
Integer System.Int32 4 bytes +/-2.147E9
Long System.Int64 8 bytes +/-9.223E18
Object System.Object 4 bytes Any Type
Short System.Int16 2 bytes -32,768 to 32,767
Single System.Single 4 bytes +/-3.402E38
String System.String 10 bytes + (2 * CharacterCount) 2 billion characters
Structure (Inherits from System.ValueType) Sum of members Sum of members

Notes

  • VB.Net can also define variables using the .NET names as in:
    Dim x As Int32
    Dim u As UInt16 ' Unsigned 16-bit integer
  • Note that math operations are not supported on unsigned values
    Dim b As SByte ' Signed byte
  • The Single and Double types are standard floating point formats and subject to the inherent accuracy issues. For example, 3.5+0.5=3.9999999999999999.....
  • The Decimal type may be a better choice for some applications.
  • Currency is no longer supported and the Decimal type is usually the best substitute.
  • Variant is no longer supported although Object can now be used to hold any type.
  • User-defined types have been replaced by structures.
  • The Date type is no longer stored as a Double so direct manipulation is not permitted.

Arithmetic Operation Shortcuts

VB.Net supports a shorthand syntax for arithmetic operations that will be familiar to any C programmer but may seem a little strange to non-C programmers.

Using this shortened syntax allows expressions like x=x+1to be written as x+=1. In general, the syntax

{variable} = {variable} {operator} {expression}

is shortened to:

{variable} {operator} = {expression}

Some more examples to help clarify:

Standard syntax Shortened syntax
x = x + y x += y
x = x - z x -= z
x = x * 2 x *= 2
x = x ^ 3 x ^= 3
x = x / k x /= k
s1 = s1 & s2 s1 &= s2

Note that the "standard" syntax is still valid and that the new syntax is simply another option.

Comments

  1. 05 Oct 2004 at 17:33

    re-install your prerequisites cd this will correct the problem.

  2. 05 Oct 2004 at 17:23

    to create an actual installation cd-rom for your application you would copy the entire contents of the Release folder to writable cd-rom at this point. If the target computers don't include the .net framework, you should also copy the .net framework redistributable file (dot-netfx.exe), which the user will have to install separately. You need a cd-rw drive to do this.

  3. 10 Mar 2004 at 13:12

    hello, I developed application in visual basic .net and when i tried to run this application in other computers then setup file prompt me message to first install the .net framework in the computer then installation will start so after installing the .net framework in other computer, my setup or application worked fine but .net framework file size is almost 23 MB that is very big to distribute with my application or to ask from the user to download this file. My application size is only 4MB. Well, i conclude that VB.net is not useful if some one want to distribute his small application to many hundred computers because it require .net framework (23 MB) that is very difficult to download. So i am moving back to VB6 for my application developemnt. If you have any idea that i should stick to VB.net then please let me know, I need help. It is very difficult for me to write code again for VB6. bye

  4. 03 Jun 2003 at 16:42

    You probably figured this out by now but for anyone else with the same or similar problem looking for the old VB6 control array then you need to delegate the Event to a helper method.


    The helper method must have the same signature as the event being delegated
    Usually along the lines of  “Event Name”
    (ByVal sender As Object, ByVal e As System.EventArgs)



    to demonstrate create a new windows project and add 4 radio buttons to the form or another control if you prefer( Alter the code to suit )
    and add the following code to the form


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
           AddHandler RadioButton1.Click, AddressOf RadioChanged
           AddHandler RadioButton2.Click, AddressOf RadioChanged
           AddHandler RadioButton3.Click, AddressOf RadioChanged
           AddHandler RadioButton4.Click, AddressOf RadioChanged


       End Sub


       Private Sub RadioChanged(ByVal sender As Object, ByVal e As System.EventArgs)
           MsgBox(CType(sender, RadioButton).Name)
       End Sub



    OK this a bit useless as most people would not use radiobuttons in this manor


    Add a number of textboxes to the form about 10 would be ok
    Then add this code to the form load event


          Dim ctrl As Control
           For Each ctrl In Me.Controls
               If TypeOf ctrl Is TextBox Then
                   AddHandler ctrl.Validating, AddressOf ValidateTextFields
               End If
           Next
           ctrl.Dispose()
           ctrl = Nothing



    and add this method


    Private Sub ValidateTextFields(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
           e.Cancel = CType(sender, TextBox).Text = String.Empty
           If e.Cancel = True Then
               MessageBox.Show("TextField " & CType(sender, TextBox).Name & " Must Be Completed", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
           End If
       End Sub



    You should now have a simple ( all be it poor for user input, but it is only a demo of a concept) validation on all textboxes


    Why not add it to the handles clause of the first textboxes validation event
    Like
    Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    Handles TextBox1.Validating, TextBox2.Validating


       End Sub


    This will work but you can not remove the handler at a later stage Add the following to the ValidateTextFields method after the previous if statement



      If CType(sender, TextBox).Name = "TextBox1" Then
               RemoveHandler TextBox1.Validating, AddressOf ValidateTextFields
           End If



    This should remove the handler and the validation



    I Hope this helps
    Cheers
    James



  5. 02 Apr 2003 at 16:14

    In my current project I have to check the state of a number of radio buttons. For example if I have to check the state of 100 buttons do I have to do each one individually, e.g.


    if radState0.checked = true then sum += 1
    ....
    ....
    if radSate99.checked = true then sum += 1


    or can I do it in a loop e.g.


    for i = 0 to 99
    if radState(i).checked = true then sum += 1
    next i


    Please excuse the naivity of the question but I am starting from the ground up.


    Regards


    Bob

  6. 25 Feb 2003 at 16:11

    When I ran into this problem it was due to the fact that i was on a different machine and some of the files included in References for my VB6 app weren't installed and registered on the new machine.  Is it possible that some of the files that your VB6 app needs were uninstalled or unregistered when you uninstalled VB6?

  7. 24 Jan 2003 at 04:42

    I have a project designed and implemented using VB6.0 and Oracle 8i.Recently I unistalled Visual studio 6.0 and installed .NET.Now when I try to open my project through the .NET IDE it invokes the update wizard.However the updation does not succeed as the process reports several missing file.Can anyone help me out in updating the above project to .NET platform.Why are the errors encountered?
    Thanks
    Shant

  8. 14 Jun 2002 at 13:57

    I don't understand the reason why the size of Bool type in VB.Net is of 4 bytes (as by article of G.Gnana Arun Ganesh). Can somebody explain?

  9. 01 Jan 1999 at 00:00

    This thread is for discussions of Leverage the .NET Framework with Visual Basic.NET.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related jobs

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!