A VB6 sample project for all members of vbforums that:
- Show CPU's Model Name
- Shows CPU's Percentage usage
- Shows how many cpu has the computer
- Shows system's free memory
Printable View
A VB6 sample project for all members of vbforums that:
- Show CPU's Model Name
- Shows CPU's Percentage usage
- Shows how many cpu has the computer
- Shows system's free memory
Well, I have an AMD Athlod XP and it shows I have an Intel Pentium :(
Really?
I didn't know it! I am trying to fix it...Thanks for this bug Manavo11! ;)
Here is the second version, because the first had some bugs as Manavo11 told already!
This version has these features:
1) CPU Usage
2) Cpu Exact model
3) Cpu identifier
4) Total Memory
5) Free Memory
6) Operating System Name
7) Operating System Exact Version
Now, its name should be changed, because it is not only CPU information! It has information for Memory and Operating System also, so, it's like a system Information utility!
Thanks manavo11 for your bug report!
:wave:
Finds it fine now :thumb:
However, I got an error in the tmrUpdate_Timer sub. On the lines :
VB Code:
memS = Left$(memS, InStr(1, memS, ",") - 1)
and
VB Code:
memT = Left$(memT, InStr(1, memT, ",") - 1)
which depends I guess what the decimal point is for the computer. For me, changing to a period instead of a comma made it work :)
Thanks Manavo11! I hope you like it! :) :) :) :) :)
By the way, you can use this to get the decimal point of the computer that your app is running on and avoid the error :)
VB Code:
Option Explicit Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long Const LOCALE_USER_DEFAULT = &H400 Const LOCALE_SDECIMAL As Long = &HE Private Sub Form_Load() MsgBox "Decimal point character : " & GetInfo(LOCALE_SDECIMAL) End Sub Private Function GetInfo(ByVal lInfo As Long) As String Dim Buffer As String, Ret As String Buffer = String$(256, 0) Ret = GetLocaleInfo(LOCALE_USER_DEFAULT, lInfo, Buffer, Len(Buffer)) If Ret > 0 Then GetInfo = Left$(Buffer, Ret - 1) Else GetInfo = "" End If End Function
Thanks Manavo11, but i prefer this way, because this i know! (It tried your way, and it works perfect)
:) :) :)
You prefer what way? The one that might cause an error? :ehh: :D BTW, a simpler way would be to use Int or CInt instead of InStr to get the integer part of the number ;)Quote:
Originally Posted by DarkX_Greece
Well, i prefer the way i know most! But i know that it sometimes causes some errors!
I am trying to find an other way to do it! Simple and also faster!
Can you please send me an example withorVB Code:
Int?VB Code:
CInt
:)
Int and CInt are functions that return the Integer part of a number and the rounded Integer part of the number you pass as an argument to the functions. For example
VB Code:
MsgBox Int(11.6) MsgBox CInt(11.6)
I use the following to return the Brand Name of the o/s:
VB Code:
Public Function getVersion() As String Dim osinfo As OSVERSIONINFO Dim retvalue As Integer osinfo.dwOSVersionInfoSize = 148 osinfo.szCSDVersion = Space$(128) retvalue = GetVersionExA(osinfo) With osinfo Select Case .dwPlatformId Case 1 If .dwMinorVersion = 0 Then getVersion = "Windows 95" ElseIf .dwMinorVersion = 10 Then getVersion = "Windows 98" End If Case 2 If .dwMajorVersion = 3 Then getVersion = "Windows NT 3.51" ElseIf .dwMajorVersion = 4 Then getVersion = "Windows NT 4.0" ElseIf .dwMajorVersion = 5 And .dwMinorVersion = 0 Then getVersion = "Windows 2000" ElseIf .dwMajorVersion = 5 And .dwMinorVersion = 1 Then getVersion = "Windows XP" End If Case Else getVersion = "Failed" End Select End With End Function
This code will have to be updated when future o/s are released (i.e. "Longhorn")
I am getting an error with the following code (See the lines Highlighted in Red):
VB Code:
Private Sub tmrUpdate_Timer() tmrUpdate.Enabled = False DoEvents Dim lCPULoad As Long Dim lCPUIndex As Long m_oCPULoad.CollectCPUData lbldata.Caption = "Processor Model: " & CPUModel & vbCrLf & InCPU & vbCrLf For lCPUIndex = 1 To m_lCPUs lCPULoad = lCPULoad + m_oCPULoad.GetCPUUsage(lCPUIndex) If Me.Visible Then lbldata.Caption = lbldata.Caption & "Processor " & Format(lCPUIndex, "@@") & ": " & Format(m_oCPULoad.GetCPUUsage(lCPUIndex), "@@@") & "%" & vbCrLf Dim memS As String, memT As String memS = objSysInfo.MemoryFree / 1024 [COLOR=Red]memS = Left$(memS, InStr(1, memS, ",") - 1)[/COLOR] '<==This Line memS = memS & " mb" memT = objSysInfo.MemoryTotal / 1024 [COLOR=Red]memT = Left$(memT, InStr(1, memT, ",") - 1)[/COLOR]'<==This Line memT = memT & " mb" lbldata.Caption = lbldata.Caption & "Memory Free: " & memS & vbCrLf & "Memory Total: " & memT lbldata.Caption = lbldata.Caption & vbCrLf & "Operating System: " & objSysInfo.WinName lbldata.Caption = lbldata.Caption & vbCrLf & "Current OS Version: " & objSysInfo.WinVersion End If Next lCPUIndex tmrUpdate.Enabled = True Me.Height = lbldata.Height + 500 Me.Width = lbldata.Width + 500 End Sub
Attached is an image of Form1
Look at my replies above... It's probably because you have a different decimal point character :)
Might be of interest to you - an adaption of the original functionality has been adapted into a Class and finally into a stand-alone UserControl:
VB - Showing the CPU graph like in Windows Task Manager
The Extreme CPU information project has been updated!
New version 3!
Added:
1) Graph report for the CPU(s) (Thanks to CVMichael)
2) Fixed some bugs with the form resize
3) Faster CPU information engine
Try it, and if you find any bugs, then please send a reply to this topic!
EDIT: I changed the RAR archive to ZIP archive due to some replies! :)
You should post as ZIP
Everyone has ZIP decompression programs, but not many have RAR decompression programs (like me)
I wanted to take a look at it, but I can't...
OK! Look my last post! I changed the RAR archive to ZIP! I think that it's ok now!
;)
Awesome man! :thumb:
How did you get that graph? (I've only been using VB for a couple of months)
I made it....Quote:
Originally Posted by piratescotty
What did you make it in?
:confused:Quote:
Originally Posted by piratescotty
Ammm, Visual Basic....
So how about answering my first question, HOW DID YOU MAKE THE GRAPH?
Open the project and LOOK at the code...Quote:
Originally Posted by piratescotty
What am I supposed to do, make a tutorial out of it ??
This is the original thread where it was asked:
http://www.vbforums.com/showthread.php?t=394347
Then I made a project that does it in the CodeBank:
http://www.vbforums.com/showthread.php?t=394360
And then DarkX_Greece updated his project with my code in here...
The main function that does the drowing is: DrawCPUUsage, so take a look at it, and see how it's done...
Wow. I know this doesn't help anyone much, but I just wanted to say thanx - this is a great program - I integrated the CPU class into my program and now it's great(er)!
I get a run timer error 5 in tmrUpdate_Timer at line,
memS = Left$(memS, InStr(1, memS, ",") - 1)
When I commented those lines out it seems to work OK.
btw, tested on a dual core Athlon 64.
The program flickers and is pretty annoying!
The CPU usage code looks interesting, a lot different then the approach I took with my CPU usage in Tray program.