|
Nitegoddess wrote: numericUpDown_FirstIndx.Value = 0m;
numericUpDown_SecondIndx.Value = 0m;
Those lines would throw error while building. It only Accepts an Integer values. That letter next to 0 is BAD.
Nitegoddess wrote: if ((decimal)FirstIndx > numericUpDown_FirstIndx.Maximum)
Once again. this is incorrect usage of If statment. Therre is no need to convert int to decimal. Also do you want to prompt a user when he reaches the end with message or reset it to beginning?
Does that work for you. Have you tried running?
|
|
|
|
|
Yes I ran the program and it seemed to work without errors.
I took out the m's and changed the decimal to int like you said. It still seems to work the same. I don't think I need a msg box to let them know they have reached the beginning again but I know how to put that in if needed. I am now in the process of trying to test to see if the data was saved and if so how to get it to display in a msg box that is prompted in a form which is it's parent form. Do you know if the data is being saved and if so how I can create a button outside of the class that will allow me to access the data so it is displayed in a msgbox as:
Array[0,0] = 1.0
Array[0,1] = 3.8
Array[0,2] = 9.7
Array[1,0] = 5.2
Array[1,1] = 2.1
Array[1,2] = 5.8
for example.
From what I can tell it isn't being saved.
This is the code I am using for the button click on the other form:
Form_DefArr DefArr = new Form_DefArr();
if (DefArr.IndxArr == null)
{
MessageBox.Show("Sorry, no array to display");
return;
}
MyArray = DefArr.IndxArr;
string output = "";
for (int i = 0; i < MyArray.GetLength(0); i++)
for (int j = 0; j < MyArray.GetLength(1); j++)
output += "Element[" + i.ToString() + "," + j.ToString()
+ "] = " + MyArray[i, j].ToString() + "\n";
MessageBox.Show(output);
I say this because when I click it the MessageBox.Show("Sorry, no array to display") is displayed.
|
|
|
|
|
of course it won't display. You just defined DefArr with new instance. And didn't even show that form.
If you use DefArr.ShowDialog(), you will block executing code until you close the form. But as you showed your code, you create instance without actualy showing and running its script.
Didn't I Mentioned about Variable Lifetime?
Put a line public Form_DefArr DefArr; as you did with IndxArr. After that entire class can access that form.
Nitegoddess wrote: I took out the m's and changed the decimal to int like you said
In those if statements, you compared index value with NumericUpDown.value. Both values are integer but not double.
Also I Noticed your array[,] is defined as integer, however currently you put values such as 5.8 is a Double not Integer. Conversion from Double to Integer loses its accuracy.
I suggest you read some C# books. Did you program in any other language beside C#. C# is one of the easiest language.
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">Nitegoddess wrote:</div>Form_DefArr DefArr = new Form_DefArr(); if (DefArr.IndxArr == null) </blockquote>
My knowledge on this is limited, but I think that might be the problem. Try moving the if statement below the code the following:
MyArray = DefArr.IndxArr;
You define a brand new instance of that array and it has no set values yet. It then hits the if statement, sees it as true and does as told.
At least, I think this is how this is working. I am still working on figuring stuff like this out myself. You also seem to be willing to do a lot of the work yourself, just don't seem to have very good instruction as to some of this stuff. Get a Teaching Assistant or the instructor to be your new buddy, ask questions and make them work with you to go through this. While CP is an awesome resource, the local ones are the best since they can answer on the spot and have better interaction.
|
|
|
|
|
He access that array in a different form. As from the last code I assume he shows form after that, he uses a button on original form, where it defines another new instance of a form that doesn't have value set to that array. That way any variable will be either null or have values that was filled by a constructor. as I Get it, he accsess like this:
the below code is for just a show what is going on
public class Form1 : Form
{
public Form1(){}
Int32[,] IndxArr;
}
public class Form1 : Form
{
public buttonShowForm2_Click()
{
Form2 frm = new Form2();
frm.ShowDialog();
}
public buttonReadArray_Click()
{
Form2 frm = new Form2();
if (frm.IndxArr == null)
{
}
}
}
|
|
|
|
|
Right so how can I open a new form using one button and save the data created in it, so that i can use the data on the first form by clicking a different button?
|
|
|
|
|
as I got your email, you did it correctly AFAIK.
|
|
|
|
|
Yea, I see that now.
Form Define_Array is being created on a button click and that grabs the data.
But I don't see that data being passed back to what is supposed to read the array.
As we all know in the C# forums on CP, moving data from one form to another is asked at least once a day...
Yea, making a new form without that data being sent to it isn't going to work. I'll let you answer, you saw that and I didn't. You are much better able to do so.
|
|
|
|
|
Yeah I tried that and now I am getting an error during debugging. The error says: Object reference not set to an instance of an object. It is during the MyArray = DefArr.IndxArr; step
Here is the code:
namespace Assignment_1
{
public partial class Form_CreateArray : Form
{
public Form_DefineArray DefineArray;
int[,] MyArray;
public Form_CreateArray()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form_DefineArray DefineArray = new Form_DefineArray();
DefineArray.ShowDialog();
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button4_Click(object sender, EventArgs e)
{
MyArray = DefineArray.IndexArray;
if (DefineArray.IndexArray == null)
{
MessageBox.Show("Sorry, no array to display");
return;
}
string output = "";
for (int i = 0; i < MyArray.GetLength(0); i++)
for (int j = 0; j < MyArray.GetLength(1); j++)
output += "Element[" + i.ToString() + "," + j.ToString()
+ "] = " + MyArray[i, j].ToString() + "\n";
MessageBox.Show(output);
}
}
}
|
|
|
|
|
Acording to email I Got from you, did you clicked that button: button_CreateNewArray, since there you have created instance of Array. Put a breakpoint on Close() in second form and then look if in Quick Watch if Index array is populated. I can help you in about a hour, then I will be home ready to test your sample
|
|
|
|
|
Thanks I will try this, one question, which variable in the code do I add the watch too?
|
|
|
|
|
Whell aray of course, then use step out. Then you will land outside DefineArray.ShowDialog().
After that look in a quick view, if that Array has any walues
|
|
|
|
|
Yes the array contains all the data.
|
|
|
|
|
I want to know how can I save the NumericUpdown decimal value in windows registry and how to read it back to the NumericUpDown??
Note: I don't want to save it as String inthe registry
|
|
|
|
|
RegistryKey.Setvalue method takes in object for the value. Hence you should be able to save decimal directly to it. While getting it back, you can use the Key you set to retrieve the value and set that to NumericUpDown .
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
SetValue is not working with decimal.. when I save 0.548 it will save as 0 in a DWord format because DWord will only accept integer?
|
|
|
|
|
Well then, AFAIK, string is the only option you have.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
what baout saving it as binary? how can I do that?
|
|
|
|
|
How about to multiply your val?
Greetings
Covean
|
|
|
|
|
jrahma wrote: I want to know how can I save the NumericUpdown decimal value in windows registry and how to read it back to the NumericUpDown??
Reading from the registry and writing is done over the Registry classes.
jrahma wrote: Note: I don't want to save it as String inthe registry
The registry has no "decimal" datatype, AFAIK.
I are Troll
|
|
|
|
|
Why would you want to? I'd store it in a file.
The Registry is evil!
|
|
|
|
|
One of the design goals of .NET is to avoid using Registry. What prevents you from storing you settings in a settings file ?
|
|
|
|
|
now what if i still want to use the Registry?!
|
|
|
|
|
Then you are going against the design goals of the language you are coding in. Up to you, but not recommended.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
This coding is in C++\CLI:
System::Drawing::Bitmap ^pBitmap;
System::IntPtr intPtr = pBitmap->GetHbitmap();
//How to convert this IntPtr to HBITMAP
//HBITMAP hbitMap = intPtr
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|