hi all Has someone got sample codes (including description) on how to create an Inputbox in C++? Thanks in advance
User 11196121
Posts
-
Create InputBox using VS2010 C++? -
c++ Windows Form app: How to grant public access to DataTable object?No worries Richard, and please note that I do thank you for your overall support. Cheers
-
c++ Windows Form app: How to grant public access to DataTable object?Thanks Richard. i've therefore coded the calculation of standard deviation (see below). However results differ from Excel from the 3rd decimal point.Do you have any idea, as i have done it meticulously? I remembered someone working on sql server told me that depending on datatype used, computing 1/2 lead to a value close to 0.5 but still not 0.5. Do you think it might be an explanation, here? Cheers
int obs;
double mu, Ssigma, Svari, sum=0,sumsqr=0;for (int i=1;i-1<dbdataset->Rows->Count-1;i++){ dbdataset->Rows\[i-1\]\["DataRet"\]=(System::Convert::ToDouble(dbdataset->Rows\[i-1\]\["Population"\])/System::Convert::ToDouble(dbdataset->Rows\[i\]\["Population"\])-1); sum = sum + System::Convert::ToDouble(dbdataset->Rows\[i-1\]\["DataRet"\]); obs = (dbdataset->Rows->Count-1); mu = sum /obs; sumsqr=sumsqr + pow((System::Convert::ToDouble(dbdataset->Rows\[i-1\]\["DataRet"\])-mu),2); Svari=sumsqr/(obs-1); Ssigma=sqrt(Svari); lblvol->Text = Convert::ToString(Ssigma);
-
c++ Windows Form app: How to grant public access to DataTable object?Hi Richard 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'
DataTable^dbdataset=gcnew DataTable();
DataColumn^rt_col=gcnew DataColumn();
rt_col->ColumnName = "DataRet";
rt_col->DataType=System::Type::GetType("System.Double");
dbdataset->Columns->Add(rt_col);sda->Fill(dbdataset); double varet = dbdataset->Columns\["DataRet"\]; //already double type, no need System::Convert::ToDouble double vola = sqrt(varet); lblvol->Text = Convert::ToString(vola);
-
c++ Windows Form app: How to grant public access to DataTable object?Thanks Richard for the feedback, and no worries.
Quote:http://www.cplusplus.com/reference/string/string/?kw=string[^]
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
-
c++ Windows Form app: How to grant public access to DataTable object?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 bizzare... Cheers
-
c++ Windows Form app: How to grant public access to DataTable object?Richard, 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. Best,
-
c++ Windows Form app: How to grant public access to DataTable object?alright.cheers.
-
c++ Windows Form app: How to grant public access to DataTable object?Cheers Richard. Please very quick question: do you know why the below code compiled but tirggered an error msg box
Unable to cast object of type System.Data.DataColumn to type System.IConvertible
lblvol->Text=System::Convert::ToString(sqrt(System::Convert::ToDouble(dbdataset->Columns["DataReturn"])));
I was just aiming at computing the standard deviation of my return series held in ["DataReturn""]. can't see anything wrong as sqrt () is a built-in function from
#include "math.h"
Cheers
-
c++ Windows Form app: How to grant public access to DataTable object?Hi All 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.
public ref class Form1 : public System::Windows::Forms::Form
{
public:
//int row;
DataTable^db=gcnew DataTable();
Form1(void)Thx
-
Perform operations on c++ DataTableHi Richard, First and foremost, sincere apologies for a naivety mainly attributable to inexperience Yet. I acknowledge that the code posted is perfectly fine. While adapting to my needs, performing the loop before the below piece of code has resulted in blank "Ret" columns, confused me, and triggered some skepticism.
sda->Fill(dbdataset);
Now all look fine, and I'd like to thank you very much for your assistance. I spent the weekend on this mater whereas it took you barely few minutes from your side to bring a concrete solution. Hence I am indeed impressed, and hope to become a day a c++ pundit like you so as to give back by helping others on forums too.
Cheers
Member 11230372
-
Perform operations on c++ DataTableThanks again Richard. Could this suggestion be translated into codes for implementation? then I will surely learn from your post as this is much more concrete. cheers
-
Perform operations on c++ DataTablePlease Richard a quick look at my previous post (also copied below)
"No, it still makes no sense. You add an extra column to your table and then you say you need to store information in extra rows. Choose one or the other."
I've added an extra ret column
DataColumn^rt_col=gcnew DataColumn();
rt_col->ColumnName = "Ret";
rt_col->DataType=System::Type::GetType("System.Double");
dbdataset->Columns->Add(rt_col);
Then I need to fill the rows of this new column "Ret" based on the values held in "Population" column.
1st value of "Ret" should equal = log( 1st value of Population / 2nd value of Population)
2nd value of "Ret" = log (3rd value of Population / 4th value of Population)
....ps: please let me reiterate that both "Ret" and "Population" are columns from the datable object dbdataset.
Cheers
** in vba it will take me <3 minutes to perform it but I am stuck in c++ (part of the learning process I suppose ) Again thanks for the help
-
Perform operations on c++ DataTable"No, it still makes no sense. You add an extra column to your table and then you say you need to store information in extra rows. Choose one or the other." I've added an extra ret column
DataColumn^rt_col=gcnew DataColumn();
rt_col->ColumnName = "Ret";
rt_col->DataType=System::Type::GetType("System.Double");
dbdataset->Columns->Add(rt_col);Then I need to fill the rows of this new column "Ret" based on the values held in "Population" column. 1st value of "Ret" should equal = log( 1st value of Population / 2nd value of Population) 2nd value of "Ret" = log (3rd value of Population / 4th value of Population) .... ps: please let me reiterate that both "Ret" and "Population" are columns from the datable object dbdataset. Cheers ** in vba it will take me <3 minutes to perform it but I am stuck in c++ (part of the learning process I suppose ) Again thanks for the help
-
Perform operations on c++ DataTableThanks for your proactivity Richard, which is really appreciated. after adding an extra column "Ret" my table is looking like: Ret |Population|ID|... Hence my purpose is to fill Ret rows with values from "Population" column for instance: Row["Ret"][0] = log (row["Population"][0] / row["Population"][1] ... hope it helps Cheers Member 11230372
-
Perform operations on c++ DataTable:doh:
-
Perform operations on c++ DataTableHi Richard First of all thanks for the assistance. Basically what I am trying to achieve can be described as follows: 1-creating a database connexion, run a query and store the result in my Datatable's object dbdataset(see code below). city table has 5 columns 2-adding an extra column "ret" to dbdataset
MySqlCommand^CmdDataBase = gcnew MySqlCommand("select * from world.city",conDataBase);
try{
conDataBase->Open();
MySqlDataAdapter^sda= gcnew MySqlDataAdapter();
sda->SelectCommand=CmdDataBase;
DataTable^dbdataset=gcnew DataTable();
DataColumn^rt_col=gcnew DataColumn();
rt_col->ColumnName = "Ret";
rt_col->DataType=System::Type::GetType("System.Double");
dbdataset->Columns->Add(rt_col);3-fill "ret" rows based on values from column "Population"
DataRow^rt_row;
for (int row=0;row<dbdataset->Rows->Count;row++) { rt\_row=dbdataset->NewRow(); rt\_row\["Ret"\]=log(System::Convert::ToDouble(rt\_row\["Population"\]\[row\])/System::Convert::ToDouble(rt\_row\["Population"\]\[row-1\])); //rt\_row\["DataReturn"\]=System::Convert::ToDouble(dbdataset->Rows\[row\]\["Population"\])/System::Convert::ToDouble(dbdataset->Rows\[row-1\]\["Population"\]); dbdataset->Rows->Add(rt\_row);
1- and 2- are fine but I am completely stuck on 3. Hope you understand better my goal through this explanation. cheers member 11230372
-
Perform operations on c++ DataTableThanks Nareesh for the advice, although it does not help in solving the main issue: "Performing operations on DataTable" by referencing multiple columns Best, Member 11230372
-
Perform operations on c++ DataTableThanks Bryce for your prompt feedback. Look forward to getting Christian Grauss' assistance on this issue, after spending a few days to sort it out by myself. Cheers
-
Perform operations on c++ DataTableSure. Also posted i to "general programming" -> c/c++/mfc after realizing it. cheers