For...Next...Loop averages
-
sexta-feira, 6 de julho de 2012 22:15in a project where you imput current high temp. Ionly have 1 input for temp and don't understand how to write For...Next...Loop that will give averages of week, month, and year.
Todas as Respostas
-
sexta-feira, 6 de julho de 2012 22:33iguess my question is how do i set it to list the inputs and give out averages of 7,30, and365 on seperate readonly output boxes. I need an understanding not a complete code or answer. This is for an online class
-
sexta-feira, 6 de julho de 2012 23:05
here is what i have.
Public Class FrmMain
Dim intHighTemp, intHumidity As Integer
Dim strCurrentCondition As String
Dim intWeekAverge, intMonthAverage, intYearAverage As Integer
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
strCurrentCondition = CStr(txtCurrentCondition.Text)
If IsNumeric(txtCurrentHighTemp.Text) Then
intHighTemp = CInt(txtCurrentHighTemp.Text)
Else
MessageBox.Show("Temperature must be numeric")
End IfIf IsNumeric(txtCurrentHumidityLevel.Text) Then
intHumidity = CInt(txtCurrentHumidityLevel.Text)
Else
MessageBox.Show("Humidity must be numeric")
End IfIf intHighTemp >= 100 Then
txtCurrentCondition.Text = ("Heat advisory is in effect")
ElseIf intHighTemp >= 90 And intHumidity >= 50 Then
txtCurrentCondition.Text = ("Heat advisory is in effect")
ElseIf intHighTemp >= 90 And intHumidity < 50 Then
txtCurrentCondition.Text = ("Weather is nice")
ElseIf intHighTemp > 32 And intHighTemp < 90 Then
txtCurrentCondition.Text = ("Weather is nice")
ElseIf intHighTemp <= 32 Then
txtCurrentCondition.Text = ("Cold advisory is in effect")
End Ifup to here code works finebut i have 3 read onlys textbox that has to give average of last 7, 30, and 365 inputs. Trying to mimic the textbook from here week only shows the current input in temperature textbox. I'm a noob at this and the following code is based off the book but i know i need to give instruction to save temp values and give averages.
Dim w As Integer
Dim intWeekAverage As Integer = 0
For w = 1 To 7
intWeekAverage = intHighTemp / 7Next
txtWeekAverage.Text = CInt(intHighTemp) -
sexta-feira, 6 de julho de 2012 23:36
To compute an average you must collect the data. For example:
At class level:
Private Temps As New List(Of Integer)
In sub button_click:
Temps.Add(intHighTemp) UpdateAverage()And...:
Private Sub UpdateAverage() Dim reverse = DirectCast(Temps, IEnumerable(Of Integer)).Reverse txtAvg7.Text = reverse.Take(7).Average.ToString("0.0") txtAvg30.Text = reverse.Take(30).Average.ToString("0.0") txtAvg365.Text = reverse.Take(365).Average.ToString("0.0") End SubOr the last Sub (alternative):
Private Sub UpdateAverage() Dim reverse = DirectCast(Temps, IEnumerable(Of Integer)).Reverse Dim func = Function(days As Integer) (reverse.Take(days).Average.ToString("0.0")) lblAvg7.Text = func(7) lblAvg30.Text = func(30) lblAvg365.Text = func(365) End Sub
Armin
- Editado Armin Zingler sexta-feira, 6 de julho de 2012 23:39
-
sexta-feira, 6 de julho de 2012 23:45
BTW,
"IsNumeric" is not the appropriate function to check for Integer input. Use Integer.TryParse instead.
In "CStr(txtCurrentCondition.Text)" the Cstr() is not required as Text is already a String.
I think you should also insert a "Return" after each messagebox.
Armin
-
sábado, 7 de julho de 2012 00:13i am bound by the book and assignment sheet. IsNumeric has to be there and I have to use a For..Next Loop and Do Until to get calculations. This is ITT Tech and introduction to programming using visual basic by Wiley Pathways. haven't got to .tryParse yet. somehow i missed the Select Case for txtCurrentCondition.Text.
- Editado jsmith237 sábado, 7 de julho de 2012 00:15
-
sábado, 7 de julho de 2012 00:59
You need to define your process more precisely. You can look at existing programmes to see how yours might work.
The text is showing only the current temperature becasue that is one of the several entries that will be required for averaging. The task you have been set is to get multiple entries using the one text box and some sort of loop.
For instance, you could first ask the user how many values they are going to input, and then create a loop that keeps asking them for more input until they have entered the nominated number of values. You would need an 'Add' button for the user to indicate one more entry has been made and shoul be added to the list.
Or, you could set up Add and End buttons. Each time the user selects Add you add the current value in the text box to your list of entries. If the user selects End then you do your calculation. That would be a typical Windows application. I can't think how you would use a Do / Until loop in that design.
Or, you could use a Do / Until loop, using the Add button but testing each time if the user enters a special value (like 0 or 9999) and exit the loop and do the calculation when you detect that value. That would be typical for a DOS program (which, from the sound of it, might be where that text is coming from).
When you have decided on the user interface procedure, you can start to build the components.
-
sábado, 7 de julho de 2012 01:11current temp is the only value i need to average. trying to create list for calculate button to store value and give averages of values stored.humidity is only for heat advisory if temp>90 and humid>50. i need to store values and retreive the average temp only of the last 7,30,365 days or average of all until after all have been fullfilled. say on input day 120 i need average from list of 114-120, 91-120, and all values for days until i reach input 365.
-
sábado, 7 de julho de 2012 01:16My code does just that. If you can not use the Average function, replace it by a loop adding the values and dividing the sum by the count.
Armin
-
sábado, 7 de julho de 2012 01:21
This is what you have stated: "...has to give average of last 7, 30, and 365 inputs."
Your first task is to get those inputs. That's the user interface description that you have to decide on, as I indicated above. You need to choose one of those options or something similar. If you choose the first one, then you could assume that the user will enter 365 values. But if you provide an option when you might get a different number of values, then you either (a) work with what you get or (b) tell the user to continue until you get all 365. You need to make those decisions before you start coding.
-
sábado, 7 de julho de 2012 01:36
Dim reverse = DirectCast(Temps, IEnumerable(Of Integer)).Reverse
Dim func = Function(days As Integer) (reverse.Take(days).Average.ToString("0.0"))txtWeekAverage.Text = func(7)
txtMonthAverage.Text = func(30)
txtYearAverage.Text = func(365)changed lbls because assignment has to textboxs.
error codes
'Reverse' is not a member of 'system.....Of Integer)
3 func not declared
and Expression expected Function
the rest went in without a problem how to these errors is next
-
sábado, 7 de julho de 2012 01:46the textbox for temp is meant for user to input that days high. when you hit calculate it gives condition of weather and stores the temp. next day input temp and when you hit calculate it gives you condition and averages the two days. and soforth. if i knew how i would send you the project folder and see what you about design to code.
-
sábado, 7 de julho de 2012 01:48
This is what you have stated: "...has to give average of last 7, 30, and 365 inputs."
sorry meant output
-
sábado, 7 de julho de 2012 01:51
sorry meant output
That makes less sense for me. Is this application taking readings from some device?
-
sábado, 7 de julho de 2012 02:02
Which VB version do you use and what's the target framework version? (here: VB 2008+FW 3.5). "Reverse" is an extension method. The project must also have a reference to system.core.dll, and the namespace System.Linq must be imported.
Instead of calling the extension method, you can call the ToArray method of the List(Of Integer), then call Array.Reverse on the array to get the same result.
Reversing is not necessary if you write a loop on your own and process the last items instead of the first items.
Armin
-
sábado, 7 de julho de 2012 02:02
That makes less sense for me. Is this application taking readings from some device?
one input to a list
three outputs 7day average, 30day average, 365day average. the humidity and condition from code don't count for this part of it.
there is another input which you input a number betwween 1 and 365 to the stored temp for that day but right now this project is supposed to use For...Next and Do Until loops
- Editado jsmith237 sábado, 7 de julho de 2012 02:03
-
sábado, 7 de julho de 2012 02:28
one input to a list
A little more detail would be really helfpful.
Are you saying that you already have your list? If so, what is it?
Or are you still describing what you need to do?
-
sábado, 7 de julho de 2012 02:40
no when i hit calculate the first time i need it to store the temperture to an empty list. when opened the next day for new tempature adds that to the list and need my three outputs to retrieve and average the temps for a week,month,year. I am new to this and am. i need my input to start the listone input to a list
A little more detail would be really helfpful.
Are you saying that you already have your list? If so, what is it?
Or are you still describing what you need to do?
-
sábado, 7 de julho de 2012 02:42
fromVisual studio 2005 .netframework SsDK 2.0 is all i know. its the last ITT gives to use. Ithink it not that capable for that but the loop is what i have been trying to write, i just don't understand itWhich VB version do you use and what's the target framework version? (here: VB 2008+FW 3.5).
- Editado jsmith237 sábado, 7 de julho de 2012 02:49
-
sábado, 7 de julho de 2012 04:15
OK. Forget about Calculate for the first time - you can't calculate anything until you have your list. Your task is to create your list.
Create a form with a text box for your input called txtTemp, a button calld btnAdd and a listbox called lstTemps.
Add this code:
Public Class Form1 Dim Temps As List(Of Integer) = New List(Of Integer) Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click If IsNumeric(txtTemp.Text) Then Temps.Add(CInt(txtTemp.Text)) ShowList() Else MessageBox.Show("Temperature must be numeric") End If End Sub Private Sub ShowList() lstTemps.Items.Clear() For I As Integer = 0 To Temps.Count - 1 lstTemps.Items.Add((I + 1).ToString & ": " & Temps(I).ToString) Next End Sub End ClassIs that the sort of thing you need to create your list? If so then you need to decide whether the next task is to create the average, or to save that information so that it is available the next time you run the program.- Sugerido como Resposta Mark Liu-lxfModerator segunda-feira, 9 de julho de 2012 06:49
-
sábado, 7 de julho de 2012 22:10
both and keep saving the the information each time to be recalled by day. seven days in a row. if i input temp each day ineed it to store temp and on another txtbos give average for seven days. until seven just need average of current temps added to list. i also need it to do it 30 and 365 days. if day eight is enteed i need it to average only the last 7 but i also have to be able to retrieve a specific in another box. if i enter 6 under day it should show the 6th input temperture. my instructions so far mention nothing on list or files. just has to For...Next, DoWhile, and DoUntil Loops. this is a week 2 project for introduction to web programming technics before this all we had was constants and enumeration. list and such don't come til later in the textbookIs that the sort of thing you need to create your list? If so then you need to decide whether the next task is to create the average, or to save that information so that it is available the next time you run the program.
-
sábado, 7 de julho de 2012 22:18
You can't do two things at once, so 'both' is not an answer.
Did the code provided match what you need to enter data into a list?
-
sábado, 7 de julho de 2012 22:56
You can't do two things at once, so 'both' is not an answer.
Did the code provided match what you need to enter data into a list?
save information so it can be averaged. the code-icould not find the proper declaration for lsttemp. when i tried to declare it errored and said item.add is not something(sorry did this morn and have been trying to get my car fixed and back on the road)
save for single day recall of any day input in seperate box but that is later-haven't got that far yet
-
sábado, 7 de julho de 2012 23:03
There is no lstTemp. The instruction was:
"Create a form with a text box for your input called txtTemp, a button calld btnAdd and a listbox called lstTemps."
-
segunda-feira, 9 de julho de 2012 13:27
OK Acamar,
btnAdd is btnCalculate. added code and inputs go into list but now I need to get averages from last entry back 7 days,30,365.
it will put in inputs but if i close program, list clears. I need list to hold values even after program is closed.
-
segunda-feira, 9 de julho de 2012 13:59
Program dvelopment is a step by step process. It is important to fous on one task at a time.
Now that you can add values to the list it is possible to create an average. For the 7-days average you will need a button called btnAverage7. This might change before you are finished, but for now you need it. Also, add a label called lblAverage7.
Add the following code:
Private Sub btnAverage7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAverage7.Click If Temps.Count < 7 Then MsgBox("Not enough entries to calculate 7-day average") Exit Sub End If Dim Total As Double For I As Integer = Temps.Count - 7 To Temps.Count - 1 Total += CDbl(Temps(I)) Next Dim Average As Double = Total / 7.0 lblAverage7.Text = Average.ToString End SubCreate your btnAverage30 and btnAverage365 and their labels, and create the code for those buttons by adapting the above code.- Editado AcamarMicrosoft Community Contributor segunda-feira, 9 de julho de 2012 14:01 sp
-
segunda-feira, 9 de julho de 2012 14:22I have the feeling this is solved for three days already - but I can have a wrong feeling.
Armin
-
segunda-feira, 9 de julho de 2012 22:10Moderador
Wow second ITT Tech horror story of the day... I just heard earlier about a poor fellow in a micro processor programming class be taught assembly on an 8051... and now here you are forced to learn VB.Net using VS2005.
It may be impossible to help since the "assignment" will not allow good coding practice, and we are missing information.
You keep mentioning "store the value", but I do not see any instruction on how the data was to be saved and recalled, there are any variety of ways to do this and I'm sure the assignment calls for one in particular.
There is also mention of "web programming" and I'm not sure how that fits into the Windows Forms project you appear to be writing.
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
-
terça-feira, 17 de julho de 2012 08:00
that is my one complaint about this class. I'm another student on the same assignment, but this is becoming a theme with this class. the assignments they give are often vague, and lack specifics on exactly what they want accomplished. Plus for an introductory class they seem to give assignments beyond the scope of what we've actually learned so far.
the class has yet to give instruction on how to save, and recall data. they have just touched on if...then...else statement, for....next, do...until, do...while.
for practicality this program should pull data from else where to compute this information, but this class is anything but practical so far.
the assignments seem to jump further ahead then where we are actually at in the class.
-
terça-feira, 17 de julho de 2012 09:52
To calculate an average from 365 days of data obviously requires a process to save and restore data, and even a 30 day average involves more work than is reasonable for something that is merely trying to demonstrate some particular coding concepts.
Saving and restoring that data requires only a few lines of code, but it does not involve any concepts that would be useful in the devlopment of the required skills at this stage of the process. If you need to see how it's done, post the relevant portion of the code that you already have.
-
quinta-feira, 26 de julho de 2012 16:37
Don't mind that i switched I to d and INT ton DEC tried to get averages in decimal form but for all this screwed code w
Public
Class Form1
Dim Temps As List(Of Decimal) = New List(Of Decimal)
' i know it still is not decimal but even after changing int to dec it still wouldn't let me change list string to decimal so allaverages are strings
Private Sub ShowList()
lstTemps.Items.Clear()
For D As Decimal = 0 To Temps.Count - 1
lstTemps.Items.Add((D + 1).ToString &
":" & Temps(D).ToString)
Next
End Sub
Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
If IsNumeric(txtTemp.Text) Then
Temps.Add(
CDec(txtTemp.Text))
ShowList()
Else
MessageBox.Show(
"Temperature must be numeric")
End If
If IsNumeric(txtHumid.Text) Then
Else
MessageBox.Show(
"Humidity must be numeric")
End If
Select Case txtTemp.Text
Case 90 To 99
If txtHumid.Text >= 50 Then
txtCondition.Text = (
"Heat Advisory")
ElseIf txtHumid.Text <= 49 Then
txtCondition.Text = (
"Weather is fine")
End If
'had to add case 11 due to 11-20 showed heat advisory eventhough it falls under -100to32
Case 11 To 20
txtCondition.Text = (
"Cold Advisory")
Case 33 To 89
txtCondition.Text = (
"Weather is fine")
Case 100 To 200
txtCondition.Text = (
"Heat Advisory")
Case -100 To 32
txtCondition.Text = (
"Cold Advisory")
End Select
End Sub
Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAverage.Click
If Temps.Count < 7 Then
MsgBox(
"Not enough entries to calculate 7-day average")
Exit Sub
End If
Dim Total7 As Decimal
For D As Decimal = Temps.Count - 7 To Temps.Count - 1
Total7 +=
CDec(Temps(D))
Next
Dim Average7 As Decimal = Total7 / 7.0
txtAverage7.Text = Average7.ToString
If Temps.Count < 30 Then
txtAverage30.Text = (
"Not enough entries to calculate monthly average")
Exit Sub
End If
Dim Total30 As Decimal
For D As Decimal = Temps.Count - 30 To Temps.Count - 1
Total30 +=
CDec(Temps(D))
Next
Dim Average30 As Decimal = Total30 / 30.0
txtAverage30.Text = Average30.ToString
If Temps.Count < 365 Then
txtAverage365.Text = (
"Not enough entries to calculate yearly average")
Exit Sub
End If
Dim Total365 As Decimal
For D As Decimal = Temps.Count - 365 To Temps.Count - 1
Total365 +=
CDec(Temps(D))
Next
Dim Average365 As Decimal = Total365 / 365.0
txtAverage365.Text = Average365.ToString
End Sub
End
Class
orks
now all thats left to enter a day # and retrieve that number for daily high temp, like i enter 8 and get the 8th temp in list. this the assignment- Create a program that includes If...Then...Else and Select Case decision-making statements.
- Create a program that performs repetitive tasks, using For...Next, Do While...Loop, Do Until...Loop, and While...End While statements
Assignment Requirements:
Wagner Cable Company wants you to create an application for their cable install department which allows them to keep up with weather advisories based on temperature and humidity. A heat advisory should be issued if the temperature is over 90 degrees with humidity over 50%. A heat advisory should also be issued if the temperature is over 100 degrees regardless of humidity. A cold advisory should be issued if the temperature is below 32 degrees regardless of humidity.
If no advisory is in effect, the program should output "Weather is nice." Create a flowchart to meet the requirement. Write the Visual Basic code, using TextBox controls for the input and output values.
Next, you are going to modify the program to calculate the average high temperature over a week, a month, and a year. Data will be input to the program, followed by the GetDailyHighTemp function being called. The function will accept an Integer value between 1 and 365.
Write the code using For...Next loops.
Write the code using Do Until loops. -
quinta-feira, 26 de julho de 2012 16:42oh and this was a week 2 project thats still not done to specs of a 6 week course that i will more than likely fail come Sunday at midnight wish I had someone to sit down and show me but noone around here even deals with vb anymore and don't care enough to remember it. because of this I'm so lost that I'm 16 projects behind.How screwed am I. completely screwed as I see
-
quinta-feira, 26 de julho de 2012 16:59
Could you please do us a favor and use the "insert code" icon
at the top of this message editor to insert source code? Thanks.
Also switch Option Strict On and fix the errors. It's not compilable.
Armin
- Editado Armin Zingler quinta-feira, 26 de julho de 2012 17:00
-
quinta-feira, 26 de julho de 2012 18:22
thank you Armin that option strict hit the problem with the first part. i was told that by default it is on and had my instructer told me to change in week 2 when i first this in i would not have got discuraged and about gave up. twice i have sent her the full project. now i still have to get daily value like the last says on the assignment. and then this is done.Option Strict On Public Class Form1 Dim Temps As List(Of Integer) = New List(Of Integer) Private Sub ShowList() lstTemps.Items.Clear() For I As Integer = 0 To Temps.Count - 1 lstTemps.Items.Add((I + 1).ToString & ":" & Temps(I).ToString) Next End Sub Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click If IsNumeric(txtTemp.Text) Then Temps.Add(CInt(txtTemp.Text)) ShowList() Else MessageBox.Show("Temperature must be numeric") End If If IsNumeric(txtHumid.Text) Then Else MessageBox.Show("Humidity must be numeric") End If Select Case CInt(txtTemp.Text) Case 90 To 99 If CInt(txtHumid.Text) >= 50 Then txtCondition.Text = ("Heat Advisory") ElseIf CInt(txtHumid.Text) <= 49 Then txtCondition.Text = ("Weather is fine") End If Case Is >= 100 txtCondition.Text = ("Heat Advisory") Case Is <= 32 txtCondition.Text = ("Cold Advisory") Case Else txtCondition.Text = ("Weather is fine") End Select End Sub Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAverage.Click If Temps.Count < 7 Then MsgBox("Not enough entries to calculate 7-day average") Exit Sub End If Dim Total7 As Decimal For I As Integer = Temps.Count - 7 To Temps.Count - 1 Total7 += CInt(Temps(I)) Next Dim Average7 As Double = Total7 / 7.0 txtAverage7.Text = Average7.ToString If Temps.Count < 30 Then txtAverage30.Text = ("Not enough entries to calculate monthly average") Exit Sub End If Dim Total30 As Decimal For I As Integer = Temps.Count - 30 To Temps.Count - 1 Total30 += CDec(Temps(I)) Next Dim Average30 As Double = Total30 / 30.0 txtAverage30.Text = Average30.ToString If Temps.Count < 365 Then txtAverage365.Text = ("Not enough entries to calculate yearly average") Exit Sub End If Dim Total365 As Decimal For I As Integer = Temps.Count - 365 To Temps.Count - 1 Total365 += CDec(Temps(I)) Next Dim Average365 As Double = Total365 / 365.0 txtAverage365.Text = Average365.ToString End Sub End Classif anyone can constantly chat with me over the next 3-4 days I might haVE a chance to pass. this threw me for a loop. please if you can help send me an email with number or contact info through Facebook.com/Jonathan Smith or email me at freedomthrugrace@gmail.com -
quinta-feira, 26 de julho de 2012 19:04
Thx for posting it formated now. As I do not remember every detail of this thread, I apologize in advance if I repeat what's already been said.
Before I get to the actual question, I always have a first glance at the code. First, the code looks quite good. Then I look at the question that you have. Which one is it? Or did you just want to post your current version so that we can continue from here in the next few days?
EDIT: If I am to look at every line...:
- I do not like IsNumeric. It's poorly documented, it's a VB6 relict, and it does more than you need. And maybe it's even inappropriate. Example: If you input "3.4", it returns true. That's correct, but you need an Integer value. CInt then converts the input to 3 even though the input was not a valid integer. That's why I'd suggest to call Integer.TryParse instead. Then you have one function call instead of Isnumeric+CInt.
- In Sub btnEnter_Click, you have CInt(txtHumid.Text) and CInt(txtTemp.Text) twice. Convert once only, then reuse the value twice.
- In btnAverage_Click, you're mixing Double and Decimal. And, if you sum up Integer values, the sum will be an Integer, too because it still doesn't have decimal places.
- You could write a function the calculates the average of the past N days, where N being a parameter of the function. Then call it three times (passing 7, 30 and 365).
- CInt(Temps(I)) isn't necessary because Temps() are already Integers.
Armin
- Editado Armin Zingler quinta-feira, 26 de julho de 2012 19:50
-
quinta-feira, 26 de julho de 2012 19:15
now i have textbox txtDay that a number 1-365 can be entered to get temp for that day. temp will be shown in read only textbox called txtDailyHigh when button btnGetDailyHigh is clicked. say i enter 8 in txtDay and on the list the 8th temp can be sent txtDailyHigh.
-
quinta-feira, 26 de julho de 2012 19:51
Ok. What's the problem? :)now i have textbox txtDay that a number 1-365 can be entered to get temp for that day. temp will be shown in read only textbox called txtDailyHigh when button btnGetDailyHigh is clicked. say i enter 8 in txtDay and on the list the 8th temp can be sent txtDailyHigh.
Armin
-
quinta-feira, 26 de julho de 2012 22:14
say i enter 8 in txtDay and on the list the 8th temp can be sent txtDailyHigh.
Take a look at the code you are using to manage your list of temperatures, and how you are using that list to calculate an average for a range of days. You already have everything in place to do exactly what is descibed above.
-
quinta-feira, 26 de julho de 2012 22:19like i said i am new to this and need 3 day crash course to learn 6 weeks of info and don't know how to write it to input reference num to get that nums temp.
-
quinta-feira, 26 de julho de 2012 22:20
Don't mind that i switched I to d and INT ton DEC tried to get averages in decimal form but for all this screwed code w
Why? Average was already a double:
Dim Average As Double = Total / 7.0
lblAverage7.Text = Average.ToStringIf you wanted the display formatted to two decimal places then you need to format the result, not change the type.
You also changed the temperatures to decimal, but your test for user input requires that they are integers.
-
sexta-feira, 27 de julho de 2012 00:24
JS,
This thread has 39 (now 40) responses and in it you're dealing with two pro's. Obviously we have a log jam here!
I'm not saying that acrimoniously and I hope that you don't take it that way; it's not what I meant.
I haven't read through all of it - but now that you've been dealing with it nearly a month, can you explain concisely what you have and what you want to do?
There is a solution to be had and I suspect it's not nearly as complex as you're presently thinking that it is.

Please call me Frank :)
-
sexta-feira, 27 de julho de 2012 04:56
This thread has 39 (now 40) responses and in it you're dealing with two pro's. Obviously we have a log jam here!
OP has posted what is in place at the moment, and the task is as described above - "say I enter 8 in txtDay and on the list the 8th temp can be sent txtDailyHigh".
It's not a log jam - just a slow process when it needs to be taken in very small steps.
-
sábado, 28 de julho de 2012 19:19
JS,
I have put something together that I hope might help you learn by using your explanation of what the program is supposed to do. This isn’t – by a long shot – the only way that it can be done, but it’s one way.
Main Program
The program is quite simple really, although a bit of explanation is in order. When the program is first turned on, the user will see this:

When they enter the temperature (°F.) and relative humidity (%) in the appropriate textboxes, the program will validate their entry to first ensure that it can be converted to a type integer.
If it fails that test, then the program will use an ErrorProvider to let them know that their entry is unacceptable and will “lock them in” and not allow them to leave the textbox until they’ve either entered valid data or cleared the textbox entirely.
If it passes the test of being valid type, it next checks that the converted value is within a reasonable range for what it is. They are as follows:
- The temperature has to be no lower than -50°F. and no higher than 135°F.
- The relative humidity has to be no lower than 0 and no higher than 100.
This is shown in the following:


Once it passes all tests, the Enter button is then enabled:

When they click that, the values of temperature, humidity, conditions, and the date/time will be entered into a list and also written to a text file which stores all entries (this file is read back in when the program first starts).
The most recent entry’s values are displayed in the text of the status bar at the bottom of the form. Once they click the button, the two textboxes are disabled and a countdown timer is started. You can see the status of the countdown time in the lower right here:

This countdown timer runs for one minute so that no entries are closer to each other than 60 seconds.
Statistics
The statistics available are as follows:
- Last 30 minutes
- Last hour
- Last day
- Last 30 days
- Last 90 days
- Last 365 days
These are availed to the user by way of menu strip items:

As you can see there, the program looks through the history to see what’s available and, using that, decides which (if any) of those menu items to enable.
When one of the menu items is clicked, the program looks through the history and then performs the calculations which then displayed on a second form:


I’ll let you peruse the code for yourself and ask questions if you have any. The code isn’t commented so if you’re confused, then ask. I would also encourage you to use the vast documentation of reference information built into the forum.:

I have the code on two pages of my website as shown here:
I also have the entire project folder zipped up and uploaded here if you want to experiment with it.
Take it a bit at a time; there’s nothing there that’s really “advanced” at all, but at first (and particularly when you’re just starting out), it can be overwhelming. True though that is, you can learn it.
Just stick with it and in a year’s time, you’ll amaze yourself with how much more you understand about it all!
I hope this helps some.

Please call me Frank :)

