VB.Net Basic Reading And Writing
Imports System.IO
' Drag and Drop OpenFileDialog1 onto your form.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenFileDialog1.ShowDialog
End Sub
' Go to Designer and click the OpenFileDialog1 on the bottom.
' Go to the settings on the right.
' you will see a lightning bolt.
End Class
' Click on the lightning bolt.
' Double Click on 'FileOk'
you will see a code snippet like this.
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
' Type this,
If File.Exist(OpenFileDialog1.FileName) Then
Dim ByteArray() As Byte = File.ReadAllBytes(OpenFileDialog1.FileName)
' Now we have the file in Bytes. Best Way to open it.
' Lest Save this File in a Different Location.
File.WriteAllBytes(InputBox("File Name"), ByteArray)
Else
MsgBox("File Does Not Exit")
End If
End Sub
' Simple use File. to get Files.
' or Directory. to get Folders.
Showing posts with label Variables. Show all posts
Showing posts with label Variables. Show all posts
Wednesday, 23 January 2013
VB.Net Arrays & Booleans
VB.Net Arrays & Booleans
Getting Started with Arrays. Simple Arrays:
Dim TempStringArray() As String = Split("Name1,Name2,Name3", ",")
' Result, TempStringArray(0) = "Name1", TempStringArray(1) = "Name2", TempStringArray(2) = "Name3".
Arrays start at 0 so a array of (Arrays(3)) Length is 4...
Booleans are very helpful.
Boolean can have 3 responses (True, False, Nothting(Null) or VbNull)
you can have an Array of any Object Types... etc
Dim TempIntArray(9) As Integer
' Getting the Length of a Array, there are to ways, Ubound() = the Length - 1
' Or TempIntArray.Length = 10
' Example:
' Ubound(TempIntArray) = 9
' TempIntArray.Length = 10
etc...
For I As Long = 0 To Ubound(TempIntArray)
TempIntArray(i) = i
Next
Getting Started with Arrays. Simple Arrays:
Dim TempStringArray() As String = Split("Name1,Name2,Name3", ",")
' Result, TempStringArray(0) = "Name1", TempStringArray(1) = "Name2", TempStringArray(2) = "Name3".
Arrays start at 0 so a array of (Arrays(3)) Length is 4...
Booleans are very helpful.
Boolean can have 3 responses (True, False, Nothting(Null) or VbNull)
you can have an Array of any Object Types... etc
Dim TempIntArray(9) As Integer
' Getting the Length of a Array, there are to ways, Ubound() = the Length - 1
' Or TempIntArray.Length = 10
' Example:
' Ubound(TempIntArray) = 9
' TempIntArray.Length = 10
etc...
For I As Long = 0 To Ubound(TempIntArray)
TempIntArray(i) = i
Next
Vb.net For Statements & Loops
For Statements:
The Basic For Statement Looks like this:
Dim i As Long = 0
Dim x As Long = 0
For i = 0 To 10
x +=2
Next
MsgBox(x.ToString)
While Statements
Dim i As Long = 0
Dim ExitMe As Boolean = False
While ExitMe = False
i +=1
If i = 10 Then
ExitMe = True
End If
End While
Do Until
Dim i As Long = 10
Do Until (i < 0)
i-=1
loop
The Basic For Statement Looks like this:
Dim i As Long = 0
Dim x As Long = 0
For i = 0 To 10
x +=2
Next
MsgBox(x.ToString)
While Statements
Dim i As Long = 0
Dim ExitMe As Boolean = False
While ExitMe = False
i +=1
If i = 10 Then
ExitMe = True
End If
End While
Do Until
Dim i As Long = 10
Do Until (i < 0)
i-=1
loop
Vb.net If Statements
VB.Net If Statements
Example:
Dim X As Boolean = False
If X = False Then
Stop
Else
Exit Sub
End If
Dim Y As Long = 0
If Y = 0 Then
Stop
End If
Dim Z As DataBase = Nothing
If Z Is Nothing Then ' Answer is True.
Stop
End If
Dim L As Integer = 2
If L = 1 Or L = 2 Then ' Answer is True. Because L is 2
Stop
End If
Dim P As Long = 1
If P <> 0 Then
' True
End if
Dim O As Long = 9
If O >= 9 Then
' True
End If
Example:
Dim X As Boolean = False
If X = False Then
Stop
Else
Exit Sub
End If
Dim Y As Long = 0
If Y = 0 Then
Stop
End If
Dim Z As DataBase = Nothing
If Z Is Nothing Then ' Answer is True.
Stop
End If
Dim L As Integer = 2
If L = 1 Or L = 2 Then ' Answer is True. Because L is 2
Stop
End If
Dim P As Long = 1
If P <> 0 Then
' True
End if
Dim O As Long = 9
If O >= 9 Then
' True
End If
VB.net Basic Variable Types
VB.net Variable Types:
To get started the first Variable type you will use is a Type Call "String", a string contains display variables, for example. VB.Net Contains 6 Characters, another Type is "Char" a char is a single Display Value for a Byte of Data. Example "a" is a char, Another type is Byte, byte is a numeric value for a Display Value. There are 0 - 255 Ascii Characters and Bytes in a default Ascii Table. Another Type is Integer, a numeric Value -2.142 billion To 2.142 billion.
Example:
Dim TempString As String = cStr("TempString")
Dim TempChar As Char = cChar("c")
Dim TempByte As Byte = cByte(10)
Dim TempInteger As Integer = 10
To get started the first Variable type you will use is a Type Call "String", a string contains display variables, for example. VB.Net Contains 6 Characters, another Type is "Char" a char is a single Display Value for a Byte of Data. Example "a" is a char, Another type is Byte, byte is a numeric value for a Display Value. There are 0 - 255 Ascii Characters and Bytes in a default Ascii Table. Another Type is Integer, a numeric Value -2.142 billion To 2.142 billion.
Example:
Dim TempString As String = cStr("TempString")
Dim TempChar As Char = cChar("c")
Dim TempByte As Byte = cByte(10)
Dim TempInteger As Integer = 10
Subscribe to:
Posts (Atom)
