C
C#10mo 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
Angius10mo ago
Looks like Selected is null I don't see you setting Selected anywhere
Array
ArrayOP10mo ago
Right !! @ZZZZZZZZZZZZZZZZZZZZZZZZZ
No description
Angius
Angius10mo ago
There you have it, then. A "nothing" cannot have a length
Array
ArrayOP10mo 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
Angius10mo 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
ArrayOP10mo 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
ArrayOP10mo 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
Angius10mo 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
ArrayOP10mo ago
I did this and it worked
No description
No description
Angius
Angius10mo ago
It would set all items in the Selected array to false, yes
Array
ArrayOP10mo ago
No description
Array
ArrayOP10mo ago
Yay I got it to work for this portion Thank you @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius10mo ago
I didn't do much, admittedly, but you're welcome
Array
ArrayOP10mo ago
You notice how I named it //size colours Array? Do you have any ideas for a better headercomment name
Angius
Angius10mo ago
If I had to have a comment there, it would probably be "initializing the arrays"
Array
ArrayOP9mo 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();
}
Want results from more Discord servers?
Add your server