Dim cpuLoad As Integer = CDec(Performancecounter1.NextValue.ToString())
        cpuLoad = 100 - cpuLoad
        Label1.Text = cpuLoad.ToString() & "%"
        On Error Resume Next
        ProgressBar1.Value = cpuLoad.ToString

in this why we need to write as "cpuLoad = 100 - cpuLoad" ? and what is the use of converting the integer to a string ?

Hi,

Not being the person who wrote the code I cant be 100% sure BUT I can take an educated guess.

  1. The cpuLoad = 100- cpuLoad I think it could be that thePerformancecounter1.NextValue.ToString() could be giving you the available resource as a percentage so 100 minus this figure would be the amount used..

  2. cpuLoad.ToString() Probably because the value is being used to make up a string that will be the Label1 text. This isn't really needed in VB.NET as it will automatically be converted to a string but in other languages such as C# (maybe the original programmer copied and adapted C# code,) you must explicitly convert the Integer value to a String or it will throw an error. Some will also argue this is good programming practice especially if you will in the future be looking at using other languages too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.