Showing posts with label Arrays. Show all posts
Showing posts with label Arrays. Show all posts

Wednesday, 23 January 2013

VB.Net Basic Reading And Writing

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.

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