Hi guys, I have a problem and would appreciate some guidance.

The problem I have is that on my design screen I have 5 progress bars (progressBarHour1,2,3,4,5) and also have an array with a size of [4] as seen below.

I would like the array to store values given by a weather reciever that takes data from a .dll and stores it in the array which works, but now how I'd like.

What I would like is for the array to store the rainfall (weatherSender.Rainfall) in the index of the array {here,here,here,here,here}, and store a new amount of rainfall again in [1,2,3,4], and so on untill the array is filled. I know my coding is messy, but I don't know how to have it store the data for a seperate occasion in each new index of the array. Sorry if none of this makes sense, I'll try and word it better if you don't understand.


private void precipArrayClass()
            precipArray = new int[4] {weatherSender.Rainfall,weatherSender.Rainfall,weatherSender.Rainfall,weatherSender.Rainfall,weatherSender.Rainfall}; //declaring the array to hold ints and has a size of 13

            if (labelRaining.Text != "False") // if the labels text is not equal to false do the following..
                labelPrecip.Visible = true; //make this label visibile
                labelInfoPrecipPerHour.Visible = true; //make this label visible
                labelPrecip.Text = weatherSender.Rainfall.ToString() + " mm"; //using the weather sender take the current rainfall and store it in labelPrecip


            if (labelInfoPrecipPerHour.Visible == false)
                progressBarHour1.Value = 0;
                progressBarHour2.Value = 0;
                progressBarHour3.Value = 0;
                progressBarHour4.Value = 0;
                progressBarHour5.Value = 0;
                progressBarHour1.Value = precipArray[0];//display value of position in array
                progressBarHour2.Value = precipArray[1];//display value of position in array
                progressBarHour3.Value = precipArray[2];//display value of position in array
                progressBarHour4.Value = precipArray[3];//display value of position in array
                progressBarHour5.Value = precipArray[4];//display value of position in array

Okay I am looking at you array. You declare it with size 4, but then try to add 5 elements

Here's something to remember with arrays. When you declare it "new int[4]" you are saying we have indexes [0, 1, 2, 3]. The size is 4, but index 0 counts as one.

Try This.

precipArray = new int[5] {weatherSender.Rainfall,weatherSender.Rainfall,weatherSender.Rainfall,weatherSender.Rainfall,weatherSender.Rainfall};

However since you are doing this, you don't have to specify the size, instead you can do something like this

precipArray = new int[] {weatherSender.Rainfall,weatherSender.Rainfall,weatherSender.Rainfall,weatherSender.Rainfall,weatherSender.Rainfall};

Note you don't need the # as the follow up values allow you to assign the size.

This help?

Be a part of the DaniWeb community

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