25.5.11

Working with Excel Worksheet


Hi Everybody,
I would like to discuss one of the most common FAQs regarding how we can work excel worksheet with VB.NET 2010 Windows application? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

1-) We are creating a new Windows Application Project (battery_check)




2-) Sample excel files(c:\customers.xls worksheet name:data)





3-) We are designing this windows form in a similar way to the picture below




4-) We are writing this code


Imports System.Data
Imports System.Data.OleDb
Public Class Form1


Private Sub show_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles show_btn.Click

' Create connection
Dim my_connection_string As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\customers.xls; Extended Properties=""Excel 8.0;HDR=YES"""
Dim my_Connection As New OleDbConnection(my_connection_string)
my_Connection.Open()


' get data from worksheet.
Dim myCommand As New OleDbCommand("Select * From [data$]", my_Connection)

' create a database reader
Dim myReader As OleDbDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

'get all datas
Do While myReader.Read

MsgBox("Customer Name: " & myReader(0), vbInformation, "Excel Worksheet")
Loop


' close the reader
myReader.Close()
' close the connection
my_Connection.Close()


End Sub
End Class

5-) Lets run application




Have a great day

Yener Turkeli
yenerturkeli@v-basic.net

21.5.11

Windows Remaining Battery with VB.NET

Hi Everybody,
I would like to discuss one of the most common FAQs regarding how we can see remaining battery with VB.NET 2010 Windows application? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

We are able to use System.Windows.Forms.SystemInformation class in order to get detail information about system. Lets see a sample with systeminformation class

1-) We are creating a new Windows Application Project (battery_check)





2-) We are designing this windows form in a similar way to the picture below



3-)We are writing this code

Private Sub show_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles show_btn.Click
Dim system_information As System.Windows.Forms.SystemInformation
MsgBox((system_information.PowerStatus.BatteryLifePercent * 100) & " %", vbInformation, "Battery Check")

End Sub

4-) Lets run application and click button




5-) Lets check battery status on windows




Yener Turkeli
yenerturkeli@v-basic.net

16.5.11

Working with Environment Class

Hi Everybody,
I would like to discuss one of the most common FAQs regarding how we can see domainname, username, machine name etc with VB.NET 2010 console application? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

1-) We are creating a new Console Application Project (environment_class)



2-)We are writing this code

Imports System.Security
Imports System.Security.Principal.WindowsIdentity

Module Module1

Sub Main()

'get domain name
Console.WriteLine("Domain Name: " & Environment.UserDomainName)

'get username
Console.WriteLine("UserName: " & Environment.UserName)

'get logical driver only first one
Console.WriteLine("First logical drives: " & Environment.GetLogicalDrives(0))

'get logical driver second one
Console.WriteLine("Second logical drives: " & Environment.GetLogicalDrives(1))

'get machine name
Console.WriteLine("Machine Name: " & Environment.MachineName)

'wait for user action
Console.ReadLine()





End Sub



End Module

3-) Lets run the application

1.5.11

Working with Registy (VB.NET)

Hi Everybody,
I would like to explain most common question within this essay , how we can work Windows Registry Setting(Write, Read, Create ) with VB.NET 2010 console application? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

1-) We are creating a new Console Application Project (registry_setting)



2-) We are writing this code

Imports Microsoft.Win32

Module Server

Sub Main()


'define registrykey
Dim my_reg As RegistryKey

'get your local registy value
my_reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\My_Application\\1.0", True)

'if registry key is not , create new one
If my_reg Is Nothing Then
my_reg = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\My_Application\\1.0")


End If



If (Not my_reg Is Nothing) Then

'get value from registry
Console.WriteLine("My_Value: " & my_reg.GetValue("My_Value", 0))

my_reg.SetValue("My_Value", "First")

Console.WriteLine("My_Value: " & my_reg.GetValue("My_Value", 0))

my_reg.SetValue("My_Value", "Second")

Console.WriteLine("My_Value: " & my_reg.GetValue("My_Value", 0))

my_reg.Close()
End If







'wait for user action
Console.ReadLine()
End Sub

End Module

3-)Lets run the application




4-) Lets Check Regedit




Have a great day

Yener Turkeli
yenerturkeli@v-basic.net