noob needs some quick c# help

Soldato
Joined
15 Feb 2011
Posts
10,234
Location
Slough
i've got a double that i need to round (in any direction) to an integer and then convert to an int so that i can use it as the value of an array.
i.e. i want to be able to go myarray[mydouble][x]

i've tried using the convert to int32 function but this is giving me an out of bounds error when it really shouldnt, so i guess this just takes the binary double and crosses out double and writes int, resulting in a massive number that is way out of bounds.

if anyone could explain what i need to do that would be great, because its the last little thing i need to do before the big project gets handed in on friday

thanks :)

ps. we have never been taught C#, and we have only been taught the very basics of C++, so if you could explain things in morons terms then that would be great
 
Can you post a bit more info up about what you're trying to do?
The fact that you have a value as a double that you're trying to use as an Array index sounds wrong to me.

i'm trying to record the Z axis of the magnetic sensor against distance driven by our robot. the distance driven code needs to be a double as its extra precisionis needed elsewhere in our program (its a group project).

its all hooked up to some code i've "borrowed" from the internet which can export a 2D array into excel, and make a pretty 3D graph of the magnet sensor values. basically i'll be driving a bunch of stripes across some ground where "magnetic rocks" are buried because of a recent "volcanic explosion" (i'll be driving the rover over a large piece of MDF with some very strong magnets in it)

thanks chuck, i'll try your idea in the lab tomorrow morning :)
 
Last edited:
the excel code is quite happy with being sparsely populated. its not a great way of doing it but i've just made the array massive, and initialised all the values to 0 so i shouldnt run out of space, and all that happens is that there are a hell of a lot of 0s on the excel file

the distance travelled shouldnt go negative, so it shouldnt be trying to write into a negative space of the array

this is what the array looks like:
double myarray [XDistance][lane] = magnetic sensor value;
(obviously this isnt the exact code i'm usng, but it should give you an idea of what my code is doing)

its very possible that theres a bug somewhere in my code, or that i'm not using the right variable from my friends code which sorts out the motors and distance sensors (the guy very helpfully named his variables a, b, c, d, e, f and g, and has almost no comments anywhere :mad:)
 
the "lane" is an int, its just the Y co-ordinate. i'm manually changing that for each lane, so i made it an int to start with so that i dont need to convert it.

the magnet sensor values can be any number, positive or negative
 
Back
Top Bottom