get ip address

November 28, 2008 by admin  
Filed under VB.net

get ip address with VB.net

Module Module1

Sub Main()
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
Console.WriteLine(CType(h.AddressList.GetValue(0), Net.IPAddress).ToString)
End Sub

End Module

FileStream example

November 27, 2008 by admin  
Filed under VB.net

opening and reading a file using the FileStream with VB.net

Imports System.IO

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim objStream As New IO.FileStream("d:\BOOT.txt", IO.FileMode.Open)
Dim objReader As New IO.StreamReader(objStream)
Dim strBuffer As String

strBuffer = objReader.ReadToEnd

objReader.Close()
objStream.Close()

MsgBox(strBuffer)
End Sub
End Class

use a process to open a fie in notepad

November 5, 2008 by admin  
Filed under VB.net

This example shows us how to to open a fie in notepad using C#

Imports System.Windows.Forms ‘add a reference to this Project/Add Reference

Module Module1

Sub Main()
Try
‘change the file to be opened
System.Diagnostics.Process.Start("notepad.exe", "C:\testfile.txt")
Catch
MessageBox.Show("Error cannot load notepad")
End Try

End Sub

End Module

list serial ports

November 4, 2008 by admin  
Filed under VB.net

This VB.net example shows how to list all serial ports

Module Module1

Sub Main()
For Each portName As String In My.Computer.Ports.SerialPortNames
Console.WriteLine(portName)
Next

Console.ReadLine() ‘wait for user input
End Sub

End Module

random numbers

November 3, 2008 by admin  
Filed under VB.net

This example shows how to produce random numbers in VB.net

Imports System.IO

Module Module1

Sub Main()
Dim generator As New Random
Dim randomValue As Integer
Dim count As Integer

For count = 1 To 10
randomValue = generator.Next(1, 100)
Console.WriteLine(randomValue)
Next
Console.ReadLine() ‘wait for user input
End Sub

End Module

Next Page »