OK,
I am trying to make a Lottery game in Microsoft Visual C++ 2005 Express Edition with windows application format that randomizes 6 numbers, 1-40. I've made the # randomizer, but i cannot get the number to show up on a textBox.
Here is the code that is "bad".

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
textBox1->Text = randNumGen->Next(0,41); 
}

And here is the Output.

error C2664: 'void System::Windows::Forms::Control::Text::set(System:string ^)' : cannot convert parameter 1 from 'int' to 'System:string ^'
No user-defined-conversion operator available, or
No standard conversion exists from the boxed form of the arithmetic type to the target type

PLEASE HELP ME FIX THIS PROBLEM!!

I'm guessing that randNumGen->Next() returns a number, correct? What you'll need to do is convert this into a string before assigning textBox1->Text to it.

What you'll need to do is convert this into a string before assigning textBox1->Text to it.

And how do i do that lol!?

I'm guessing that randNumGen->Next() returns a number, correct?

All i know is that the randNumGen IS the number and the ->Next(blah, blah) is the boundry or limit of the random number.

>And how do i do that lol!?
I'm not very knowledgeable in Windows programming, so if I screw this up, don't blame me...

After a little bit of researching, it seems as if the System String has overloaded the = operator for only C strings. So then I guess the easiest way would be to use sprintf:

#include <cstdio>
char myString[10];
sprintf(myString, "%d", yourRandomNumberHere);
yourTextBoxHere = myString;

If there is a built-in function that I'm not aware of, please forgive me.

private: System::Void button1_Click( System::Object^ sender,
                                                       System::EventArgs^ e) 
{
  textBox1->Text = __box( randNumGen->Next(0,41) )->ToString();
}

Vijayan121, thx for your help except once I built it, the output was:

error C4980: '__box' : use of this keyword requires /clr:oldSyntax command line option

SO..
Have any suggestions with that?
:S
--
Joeprogrammer,
That didn't quite work but you cleared up alot of things about strings and about that overloading problem.
:)

private: System::Void button1_Click( System::Object^ sender,
                                                       System::EventArgs^ e) 
{
  textBox1->Text = ( (int^)randNumGen->Next(0,41) )->ToString();
}

this will only work with clr 2.0 or later (requires implicit boxing).
(alternatively, you could use the compiler option oldSyntax)

Thank You!!!!
Its Actully Working!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.