-
Dead Timer
I am using this code below to display the current memory free on the computer and the total memory on computer (Virtual Memory that is...) When I put it in there to update with the timer..it just sits there and doesn't update. I even open up several huge programs and still get the same result. I have the timer enabled..and also have its Interval set at 1. What is wrong? Also..I want to show the percentage of free memory..how can I convert the number i get below to a percentage?
Code:
Private Sub Form_load()
SetWindowPos hwnd, conHwndTopmost, 100, 100, 400, 141, conSwpNoActivate Or_
conSwpShowWindow
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
'Free Memory
MemFreeLabel.Caption = modMemory.GetVirtualMemoryFree(True)
'Total Free
MemTotalLabel.Caption = modMemory.GetPhysicalMemoryTotal(True)
End Sub
Thanks
-
the Percentage will be
Code:
lblPecentFree.Caption = CInt(100 * MemFreeLabel.Caption / MemTotalLabel.Caption) & "%"
-
The problem may be lying in the timer interval. By firing the event very millisecond, it may not have enough time to finish executing before the thread is forgottrn, and the labels wouldnever change. Try setting the interval to something higher like one second(interval of 1000).
-
Are your labels just sitting there saying Label1 or are they showing the value at the start and then not changing it?
I'm not sure you completley understand what virtual memory is. I've tried to eplain it Here
When you get the amount of Virtual Memory Free you get back how much virtual memory is left unallocated in your process
When you get the total amount of physical memory you are getting the total amount of RAM your compter has.
When you first start your app VB will allocate all the memory it needs for the variables you use, VB will only allocate extra virtual memory if you use a Dynamic array or a variable length string, if whenever your timer fires you havn't changed the size of any strings or Dynamic arraysthe amount of virtual memory will stay the same, running large programs outside your App won't change the amount of Virtual memory your app has allocated. (NB strings inside standard windows controls such as textboxes and Labels aren't stored in your process, they are stored elswhere, so they won't affect how much Free VM you have)
Try putting a checkbox on your form and adding this
[code]Private Sub Check1_Click()
Static MyArr() As Byte 'A dynamic Array
If Check1.Value Then
Redim MyArr(0 To 5000)
Else
Redim MyArr(0 To 0)
End If
End Sub[code]
See if there's a difference in the VM reading when you check uncheck the textbox.
-
try adding the next line:
DoEvents
to your Timer1_Timer() routine.