Progress bar and percent label - vb.net

First and foremost: Yes I have searched and checked these:
* VB - progress bar not incrementing correct amounts?
* Progress bar and percents
Question: What is the best way to do a progress bar and a label for "percent" complete?
My Scenario: I have a check list box that I am looping thru and processing each item.
What I have tried: The first search result says to use the count as the max, as seen here:
ProgressBar1.Maximum = ListBox1.Items.Count
ProgressBar1.Increment(1)
This will work for the progress bar BUT not the text label, also if the items exceed 100, you will obviously get something like
231% Complete
etc..
My Idea was to use an IF statement and check to see if the total items is greater/less than 100 but thats where I have some issues.
This is my code, but please advise on what would be the best solution.
My Code:
Sub PercentComplete(ByVal Total As Long)
Dim Notch As Integer = 100 / Total
If Total > 100 Then
'If the total is greater than 100
Dim intPctText As Integer = Math.Round(Total / Notch, 10)
lblPct.Text = intPctText & "%"
Else
'If the total is less than 100
lblPct.Text = Notch.ToString & "%"
End If
End Sub

Related

Sum of the first 100 even and odd number?

I need some help getting this code to work. I need the code to calculate the first 100 even and odd numbers. The code below shows the even portion, but I assume they both will work the same way, just with different numbers. I know that the first 100 even numbers are 2 to 200 or 0 to 200?, and the first 100 odd numbers are 1 to 199. (I also need to use while loops, would I use a separate while loop to determine how the code calculate the sum?)
here is the code.
Dim sum, count As Integer 'the sum and count are changing and they must be a whole number.
Const num As Integer = 2
'now we must deveolp a while loop/equation that adds every number lower or equal to 100 together.
While count Mod 2 <= 200 'while the count is smaller or equal to 100,
count =
sum += count 'The sum will be add or equaled to the count
count += 1 'The count will be added to equaled to 1
End While
Console.WriteLine("The Sum of the first 100 even numbers is: {0}!", sum) 'This is the text the user sees, which tells them that the sum of the first 100 numbers will be 5050.
Console.ReadLine()
End Sub
As usual the math portion is giving me trouble. I feel like I have the right idea, but I cant execute it properly.
Dim sumEven, sumOdd As Integer
Dim even = 2
Dim odd = 1
While even <= 200 AndAlso odd <= 200
sumEven += even
sumOdd += odd
even += 2
odd += 2
End While
Console.WriteLine("The Sum of the first 100 even numbers is: {0}!", sumEven)
Console.WriteLine("The Sum of the first 100 odd numbers is: {0}!", sumOdd)

How Do I Count When Numbers Do Not Show Up

I have numbers from 1 to 25, four numbers will show up daily. I need to put a +1 on each of the four numbers and need to put a -1 on each of the 21 numbers didn't show up.
The four numbers that come up daily will be inputted in four different text boxes. The count being positive or negative needs to go on 25 separate text boxes labeled 1 thru 25.
I have tried "if textbox <> number, then count -= 1" but I get a count of -4 because it doesn't see the number in any of the four text boxes.
I only need a daily count not a textbox count. Sorry I don't have any code started and would greatly appreciate if someone can point me in the right direction. I'm doing this on Visual Studio 2012.
Thank you all for responding. Here is some code I've started but the count is not correct. My four input text boxes are in GroupBox2. Four numbers from 1 to 25 will draw daily like a lottery. The four numbers drawn will have a value of +1 each all others -1. I need to find the age of each number 1 thru 25. If a number has a +3 then that means that number has drawn 3 consecutive days. If a number has a -15 then that means that number has not drawn for the past 15 days.
Dim tb As New TextBox
Dim ctrl As Control
Dim Counter As Integer
For Each ctrl In GroupBox2.Controls
tb = ctrl
If tb.Text = 1 Then
Counter += 1
ElseIf tb.Text <> 1 Then
Counter -= 1
TextBox464.Text = Counter
End If
If tb.Text = 2 Then
Counter += 1
ElseIf tb.Text <> 2 Then
Counter -= 1
TextBox463.Text = Counter
End If
If tb.Text = 3 Then
Counter += 1
ElseIf tb.Text <> 3 Then
Counter -= 1
TextBox462.Text = Counter
End If
If tb.Text = 4 Then
Counter += 1
ElseIf tb.Text <> 4 Then
Counter -= 1
TextBox461.Text = Counter
End If
Next
We will need more information about how your going to approach it to be able to help you further, but as for your problem with this If Textbox <> number Then count -= 1 you can use something like this since your only going to be having numbers on the textboxes If Cint(Textbox.Text) <> number then count -= 1 since your using just Textbox its attempting to evaluate it as a control and not the property that your looking for, you need to read from its .Text Property, However since its evaluated as a String and not an Integer it will throw an error exception, thats why the Cint() is included (This may also be used to convert it to integer Ctype(number, Integer) Not sure if there is an execution speed difference or not, however Cint() is a faster way of writing it.) it will try and convert the String into an Integer and when its converted into an integer it can be evaluated like one using <>. No one is going to write a whole solution out for you, but while you attempt to create it yourself and more information can be added we are more than happy to help you with problems along the way.

VB.net battery life percentage

I tried many methods trying to make a small programs which shows the battery percentage (the value is displayed on a progressbar).Can anyone help me?
Dim power As SystemInformation.PowerStatus = SystemInformation.PowerStatus
Dim percent As Single = power.BatteryLifePercent
' Display the ProgressBar control.
pBar1.Visible = true;
' Set min and max
pBar1.Minimum = 0
pBar1.Maximum = 100
' Set the current value
pBar1.Value = percent * 100
Then you just need to refresh with a timer or something else.

Use an InputBox to enter prices of 4 items

I'm new to VB. Today I'm working on entering 4 prices for items to purchase using an input box. I need to create a counter in a loop. The only 2 buttons on the form "Enter Prices" and "Exit". So far this is the code I have (see below). I know something is off. When I run it, I'm allowed to enter 4 numbers. But at the end, when the message box comes up to show my total, it just gives me my last number I entered. I know I've got to change a few things, as I need my numbers to be in currency. Any suggestions as to where I need to go from here to get this up and running?
Private Sub btnPrices_Click(sender As Object, e As EventArgs) Handles btnPrices.Click
'Declare a variable as counter and accumulator
Dim intcount As Integer = 1I
Dim intAccumulator As Integer = 0I
'Declare and intialize variable
Dim strInput As String = ""
'Number of Items
Const intNUM_PRICES As Integer = 4
'Pre-test loop will keep iterating as long as the expression is ture.
Do While intcount <= intNUM_PRICES
'Get price of each item purchased
strInput = InputBox("Enter Price " & intcount, "Price Needed")
'Add 1 to the counter
intcount += 1
Loop
'Look at the value placed in the
MessageBox.Show("Your combined Price for all 4 items is: " & strInput)
End Sub
You've only got one variable for the input and each time you call InputBox you replace the previous value each time. If you want a total then you have to add the values, so you need to add the current input to the previous total each time, not replace it. Make sure that you convert the input to a number and use a numeric variable, because adding strings will actually join them, not add them mathematically.

Adding previously selected items from listbox for a total?

I'm doing this program for a class; I have a listbox with values from 0-10 which are 'scores' which get recorded every time the user selects a new score (and clicks the button of course). I need to do the following;
an average of the scores, which I get through an accumulator and the counter
a number of scores, which I get through a counter
get the total scores (this is what's giving me trouble)
here's the code I have for this so far :
intScore = Convert.ToDecimal(lstScores.SelectedItem)
'the counter and accumulator
intTotal = intTotal + 1
decScoreAccumulator += intScore
' here's what calculates the average
If intScore > 0 Then
decScorAvg = decScoreAccumulator / intTotal
End If
Here's an image of it : http://i.stack.imgur.com/aomQO.png
The number and average I can get to work, since its just using the accumulator and the counter. But no matter what I do, I can't add the values selected for the total. So does anyone know how I can get it to give me total of all the selected scores?
You're code looks good, and you look like your doing everything correctly. You even already have the total in your current code:
decScoreAccumulator += intScore
Because you're adding the score each time to decScoreAccumulator, this variable has the total you're looking for (assuming it's not confined to the scope of the button click). HTH. Good luck!