Difference between revisions of "Visual Basic .net"

From ScienceZero
Jump to: navigation, search
(Datatypes)
Line 41: Line 41:
 
==RS-232==
 
==RS-232==
 
==Datatypes==
 
==Datatypes==
<table cellspacing="0" cellpadding="4" border="1">
+
{|  class="wikitable"
<tr>
+
! VB type
<td valign="top"><b>VB type</b></td>
+
! .net type
<td valign="top"><b>.net type</b></td>
+
! Size
<td valign="top"><b>Size</b></td>
+
! Range
<td valign="top"><b>Range</b></td>
+
|-
</tr>
+
| <code>Boolean</code>
<tr>
+
| <code>System.Boolean</code>
<td valign="top"><code>Boolean</code></td>
+
| 4 bytes
<td valign="top"><code>System.Boolean</code></td>
+
| True or False
<td valign="top">4 bytes</td>
+
|-
<td valign="top">True or False</td>
+
| <code>Byte</code>
</tr>
+
| <code>System.Byte</code>
<tr>
+
| 1 byte
<td valign="top"><code>Byte</code></td>
+
| 0 to 255 (unsigned)
<td valign="top"><code>System.Byte</code></td>
+
|-
<td valign="top">1 byte</td>
+
| <code>Char</code>
<td valign="top">0 to 255 (unsigned)</td>
+
| <code>System.Char</code>
</tr>
+
| 2 bytes
<tr>
+
| 0 to 65535 (unsigned)
<td valign="top"><code>Char</code></td>
+
|-
<td valign="top"><code>System.Char</code></td>
+
| <code>Date</code>
<td valign="top">2 bytes</td>
+
| <code>System.DateTime</code>
<td valign="top">0 to 65535 (unsigned)</td>
+
| 8 bytes
</tr>
+
| January 1, 1 CE to December 31, 9999
<tr>
+
|-
<td valign="top"><code>Date</code></td>  
+
| <code>Decimal</code>
<td valign="top"><code>System.DateTime</code></td>
+
| <code>System.Decimal</code>
<td valign="top">8 bytes</td>
+
| 12 bytes
<td valign="top">January 1, 1 CE to December 31, 9999</td>
+
| +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is +/-0.0000000000000000000000000001  
</tr>
+
|-
<tr>
+
| <code>Double</code>
<td valign="top"><code>Decimal</code></td>
+
| <code>System.Double</code>
<td valign="top"><code>System.Decimal</code></td>
+
| 8 bytes  
<td valign="top">12 bytes</td>
+
| -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values  
<td valign="top">+/-79,228,162,514,264,337,593,543,950,335 with no decimal point; +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is +/-0.0000000000000000000000000001  
+
|-
</td>
+
| <code>Integer</code>
</tr>
+
| <code>System.Int32</code>
<tr>
+
| 4 bytes  
<td valign="top"><code>Double</code></td>
+
| -2,147,483,648 to 2,147,483,647  
<td valign="top"><code>System.Double</code> </td>
+
|-
<td valign="top">8 bytes </td>
+
| <code>Long</code>
<td valign="top">-1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values  
+
| <code>System.Int64</code>
</td>
+
| 8 bytes  
</tr>
+
| -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807  
<tr>
+
|-
<td valign="top"><code>Integer</code> </td>
+
| <code>Object</code>
<td valign="top"><code>System.Int32</code> </td>
+
| <code>System.Object</code> (class)  
<td valign="top">4 bytes </td>
+
| 4 bytes  
<td valign="top">-2,147,483,648 to 2,147,483,647 </td>
+
| Any type can be stored in a variable of type <code>Object</code>
</tr>
+
|-
<tr>
+
| <code>Short</code>
<td valign="top"><code>Long</code> </td>  
+
| <code>System.Int16</code>
<td valign="top"><code>System.Int64</code> </td>
+
| 2 bytes  
<td valign="top">8 bytes </td>
+
| -32,768 to 32,767  
<td valign="top">-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 </td>
+
|-
</tr>
+
| <code>Single</code>
<tr>
+
| <code>System.Single</code>
<td valign="top"><code>Object</code> </td>
+
| 4 bytes  
<td valign="top"><code>System.Object</code> (class) </td>
+
| -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values  
<td valign="top">4 bytes </td>
+
|-
<td valign="top">Any type can be stored in a variable of type <code>Object</code> </td>
+
| <code>String</code>
</tr>
+
| <code>System.String</code> (class)  
<tr>
+
| 10 bytes + (2 * string length)  
<td valign="top"><code>Short</code> </td>
+
| 0 to approximately two billion Unicode characters  
<td valign="top"><code>System.Int16</code> </td>
+
|-
<td valign="top">2 bytes </td>
+
| User-Defined Type (structure)  
<td valign="top">-32,768 to 32,767 </td>
+
| (inherits from <code>System.ValueType</code>)  
</tr>
+
| Sum of the sizes of its members  
<tr>
+
| Each member of the structure has a range determined by its data type and independent of the ranges of the other members  
<td valign="top"><code>Single</code> </td>
+
|}
<td valign="top"><code>System.Single</code> </td>
+
<td valign="top">4 bytes </td>
+
<td valign="top">-3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values  
+
</td>
+
</tr>
+
<tr>
+
<td valign="top"><code>String</code> </td>
+
<td valign="top"><code>System.String</code> (class) </td>
+
<td valign="top">10 bytes + (2 * string length) </td>
+
<td valign="top">0 to approximately two billion Unicode characters </td>
+
</tr>
+
<tr>
+
<td valign="top">User-Defined Type (structure) </td>
+
<td valign="top">(inherits from <code>System.ValueType</code>) </td>
+
<td valign="top">Sum of the sizes of its members </td>
+
<td valign="top">Each member of the structure has a range determined by its data type and independent of the ranges of the other members  
+
</td>
+
</tr>
+
</table>
+
  
 
==Strings==
 
==Strings==

Revision as of 09:11, 27 December 2009

Graphics

Files

Reading text files line by line:
Dim f1 As Long
dim filestring as string

f1 = FreeFile()
FileOpen(f1, My.Application.Info.DirectoryPath & "\filename.txt", OpenMode.Input)
Do Until EOF(f1)

filestring=LineInput(f1)

Loop
FileClose(f1)
Note: My.Application.Info.DirectoryPath & "\filename.txt" may be replaced by "C:\some_path\file.txt"


Writing text files line by line:
Dim f1 As Long

f1 = FreeFile()
FileOpen(f1, My.Application.Info.DirectoryPath & "\filename.txt", OpenMode.Output
Print(f1, "This is line 1")
Print(f1, "This is line 2")
FileClose(f1)

Arrays

Threading / Parallel

Loops

Conditionals

Math

RS-232

Datatypes

VB type .net type Size Range
Boolean System.Boolean 4 bytes True or False
Byte System.Byte 1 byte 0 to 255 (unsigned)
Char System.Char 2 bytes 0 to 65535 (unsigned)
Date System.DateTime 8 bytes January 1, 1 CE to December 31, 9999
Decimal System.Decimal 12 bytes +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is +/-0.0000000000000000000000000001
Double System.Double 8 bytes -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values
Integer System.Int32 4 bytes -2,147,483,648 to 2,147,483,647
Long System.Int64 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Object System.Object (class) 4 bytes Any type can be stored in a variable of type Object
Short System.Int16 2 bytes -32,768 to 32,767
Single System.Single 4 bytes -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values
String System.String (class) 10 bytes + (2 * string length) 0 to approximately two billion Unicode characters
User-Defined Type (structure) (inherits from System.ValueType) Sum of the sizes of its members Each member of the structure has a range determined by its data type and independent of the ranges of the other members

Strings

Finding text in a string:
InStr("this is a string", "is")
returns (character position number) 6. This function returns 0 when not found.