This is a good question because I'm not sure any of those really describes Windows messaging well. Sort of interesting given that it's the primary means of communication in the Windows desktop environment. I guess the rational behind this is that you can't really pass along data across messages, you can pass commands/messages and references.
I used to use messages a lot within an application to communicate but it's a bit different when dealing internal to an application because you can pass data by reference easily. Externally, you can only do that if the data is in a place that is accessible to both applications or meets certain restrictions (as described here[^]).
I am wondering if it's possible to create a DataTable object in one button handling event, and use it in another button handling event without getting error C2065: 'Datatable object' : undeclared identifier
As a solution of last resort i've made an attempt (see below) which is unsuccessful.
You should declare the object in your Form class and initialise it in the constructor or FormLoad event. It is then available to every other event handler or method within that class, whether public or private. This is basic C++ and nothing specific to CLI or Form apps.
My first suggestion would be: "don't write compound statements like that". As you can see they are almost impossible to figure out when they go wrong. Use interim values so you can check each stage of the code, like:
string dataReturn = dbdataset->Columns["DataReturn"]; // assuming this item is a string valuedouble doubleValue = System::Convert::ToDouble(dataReturn); // convert to double, but check for errorsdouble squareRoot = sqrt(doubleValue);
lblvol->Text = Convert::ToString(squareRoot);
Easier and clearer, and simple to step through with the debugger when errors occur.
Thanks for the advice. I will try it and let you know. Any idea why string type does not work from my side as opposed to your post? I am currently going it to see if people have encountered a similar issue.
might be a missing #include... as something is not logic here. as a matter of fact while typing any type double, float, char they are highlighted in blue therefore you could define any variable anywhere in the code based on those type.
however while typing string, the latter does not seem to be recognized at all (not even highlighted). string is considered as plain text and thus unrecognized
double, float, char are basic types which are part of the language, while string does not exist, but String (with capital S) is a class. If I spelt it with a lower case s before, then I apologise, as that is C# rather than C++.
The string class is an instantiation of the basic_string class template that uses char (i.e., bytes) as its character type, with its default char_traits and allocator types (see basic_string for more info on the template).
I will therefore work on your previous post and revert back to you tomorrow. Cheers
Thanks. I've made a simple console app and can confirm that the String class does work and you could create string variables such as string codeproject without problem. However,based on facts it looks like a different story when dealing with c++/cli.
Back to the main standard deviation calculation, i think it could not work as a columns can't directly be assigned to a type and treated like a variable (see below). it could have worked in vba by selecting the column range and perform the built-in functions: c++ sqrt() or math::sqrt().
Hence the solution of last resort: iterate through each row and perform the calculation in several steps (get the mean from "DataRet" column first, then carry out ... ) unless a you have a better idea. Cheers
Error C2440: 'initializing' : cannot convert from'System::Data::DataColumn ^' to 'double'