C
C#4mo ago
Array

Help with Arrays in my code?

https://paste.mod.gg/giovsrlllnke/0 Having a bit of an issue with my code. Working on an assignment where I have to load code in from a textfile and it's supposed to load in blocks. My teacher has detailed some header comments on the process, but I keep getting this error When I load in the file
private void mnuFileLoad_Click(object sender, EventArgs e)
{
//todo
//load the file and store it into the colour array file
//set all the colours to be unselected
//select a file
OpenFileDialog oFD = new OpenFileDialog();
if (oFD.ShowDialog() == DialogResult.OK)
{



//file selected so open to read it
StreamReader oSR = new StreamReader(oFD.OpenFile());
int Records = int.Parse(oSR.ReadLine());
//size Colours array
Colours = new int[Records];
//loop through each line to store mark in array
for (int i = 0; i < Colours.Length; i++)
{
Colours[i] = int.Parse(oSR.ReadLine());


}



}
private void mnuFileLoad_Click(object sender, EventArgs e)
{
//todo
//load the file and store it into the colour array file
//set all the colours to be unselected
//select a file
OpenFileDialog oFD = new OpenFileDialog();
if (oFD.ShowDialog() == DialogResult.OK)
{



//file selected so open to read it
StreamReader oSR = new StreamReader(oFD.OpenFile());
int Records = int.Parse(oSR.ReadLine());
//size Colours array
Colours = new int[Records];
//loop through each line to store mark in array
for (int i = 0; i < Colours.Length; i++)
{
Colours[i] = int.Parse(oSR.ReadLine());


}



}
looking at this portion, I'm not sure how to set all my code to be unselected
BlazeBin - giovsrlllnke
A tool for sharing your source code with the world!
No description
16 Replies
Angius
Angius4mo ago
Looks like Selected is null I don't see you setting Selected anywhere
Array
Array4mo ago
Right !! @ZZZZZZZZZZZZZZZZZZZZZZZZZ
No description
Angius
Angius4mo ago
There you have it, then. A "nothing" cannot have a length
Array
Array4mo ago
I have to make the colours un selected, so I have to find a way to sort of use that selected variable and assign it to the colors array and make it false Probably is, I;m not sure how to Or rather, how do I give it a length? Or maybe I can just make selected false? @ZZZZZZZZZZZZZZZZZZZZZZZZZ sorry to ping, but any chance you can hep me out
Angius
Angius4mo ago
You do not give it a length You need to set it to... something if you want to use it That something might have a length, if it's some sort of a collection, for example
Array
Array4mo ago
I think I need to create a new array of bool and store it in Selected maybe? I'm a bit lost on how to do this though
Array
Array4mo ago
Or any ideas on what I should set it to? The idea is that the blocks on the textfile display
No description
No description
Angius
Angius4mo ago
It really doesn't need like you need any sort of Selected here, judging by the text you sent Like, this seems to be basically it Just gotta hook the Colors array to... something to display them
Array
Array4mo ago
I did this and it worked
No description
No description
Angius
Angius4mo ago
It would set all items in the Selected array to false, yes
Array
Array4mo ago
No description
Array
Array4mo ago
Yay I got it to work for this portion Thank you @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius4mo ago
I didn't do much, admittedly, but you're welcome
Array
Array4mo ago
You notice how I named it //size colours Array? Do you have any ideas for a better headercomment name
Angius
Angius4mo ago
If I had to have a comment there, it would probably be "initializing the arrays"
Array
Array4mo ago
Because I did worked with the Selected thing Gotcha Thank you
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
//todo
//mouse click detects if an array element selected
//set the element selected in Selected array to true



//call this.Refresh() if an element is selected
this.Refresh();
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
//todo
//mouse click detects if an array element selected
//set the element selected in Selected array to true



//call this.Refresh() if an element is selected
this.Refresh();
}