Welcome Guest [Log In] [Register]
Welcome to Abstracted.View. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
System information; Visual Basic.NET
Topic Started: Jul 9 2006, 08:11 PM (269 Views)
Hacker-X
Dedicated Member
[ *  *  *  * ]
Some aspects of this tutorial require a laptop computer!

Today you'll learn how to find out whenther your computer is or isn't plugged into AC power using the If and Then statement. You'll also learn how to get current percentage of your battery remaining, you'll use the shell command to open a wireless network utility, find your local IP address. Timers play a big part in this tutorial so hopefully understand the basics of timers.

What you'll need are 3 timers, default names set the interval to 10. You must also have 4 labels and 4 frames, default names of each will do. You'll need to add 2 components: Microsoft SysInfo Control 6.0 and Microsoft Winsock Control 6.0 (SP5). Now that we've got that out of the way rename the winsock control to "sock" (without the quotes) and don't rename SysInfo1. Right now would be a good time to find you wireless network utility, just right click the shortcut and click properties and copy the target. Now that you've found your wireless utility and copied the target just make a command button with the caption "View wireless networks." Switch to code view and add this code:

Code:
 

Private Sub Command1_Click() 'When the user clicks on the button the wireless utility will start up

Shell ("C:\WINDOWS\system32\rundll32.exe shell32.dll,,Control_RunDLL C:\WINDOWS\system32\bcmwlcpl.cpl")

'The above is the target of the wireless utility (you will have to change it!)

End Sub


On to battery life percentage, we want live information, also known as dynamic text and in order to do that we need to make use of one of the timers. Make a label keep the default name. Switch to code view and add this:

Code:
 

Private Sub Timer1_Timer()

Label1.Caption = "Current battery life: " & SysInfo1.BatteryLifePercent & "%"

'The above line will change the caption of label1 to show "Current battery life: X%"
'ofcouse replacing X with the actual battery life

End Sub


Here comes the fun part, the part when you get to use the if and then statements but in order to understand this you must first understand binary, binary is what your computer parses everyday, sets of ones and zeros, this is how data is set on the internet or to any computer. Ones mean "on" and zeros mean "off" you can apply this concept to the SysInfo and figure out whether or not the computer is or isn't plugged into AC (alternating current), as oppsed to DC (direct current) a battery is direct current. The code:

Code:
 

Private Sub Timer2_Timer()

If SysInfo1.ACStatus = 1 Then 'If the SysInfo1 says that the AC status is on...

Label2.Caption = "Your computer is plugged in." 'Then the label's caption will read "Your computer is plugged in."

Else 'And if the AC status is not 1 then it has to be 0...

Label2.Caption = "Your computer is not plugged in." 'Thus, the label's caption will read "Your computer is not plugged in."

End If 'The if command has to end

End Sub


To get your local IP address just add this code:

Code:
 

Private Sub Timer3_Timer()

Label4.Caption = ("IP address: " & sock.LocalIP) 'This line will change the caption to the IP address

End Sub


You must now enable all of these timers, so the labels captions can update, when the form loads, VB 6 makes it too easy. The code:

Code:
 

Private Sub Form_Load()

Timer1.Enabled = True

Timer2.Enabled = True

Timer3.Enabled = True 'Enable all 3 timers so the information is live.

Label4.Caption = ("Local host name: " & sock.LocalHostName) 'This'll get your local host name.

End Sub


Full code:

Code:
 

Private Sub Form_Load()
Timer1.Enabled = True
Timer2.Enabled = True
Timer3.Enabled = True
Label3.Caption = ("Local host name: " & sock.LocalHostName)
End Sub

Private Sub Command1_Click()
Shell ("C:\WINDOWS\system32\rundll32.exe shell32.dll,,Control_RunDLL C:\WINDOWS\system32\bcmwlcpl.cpl")
End Sub

Private Sub Timer1_Timer()
Label1.Caption = "Current battery life: " & SysInfo1.BatteryLifePercent & "%"
End Sub

Private Sub Timer2_Timer()
If SysInfo1.ACStatus = 1 Then
Label2.Caption = "Your computer is plugged in."
Else
Label2.Caption = "Your computer is not plugged in."
End If
End Sub

Private Sub Timer3_Timer()
Label4.Caption = ("IP address: " & sock.LocalIP)
End Sub


Here is a screenshot of what I came up with:

Posted Image
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Visual Basic · Next Topic »
Add Reply