#pragma endregion
private: System::Void Generate_Click(System::Object^ sender, System::EventArgs^ e) {
//declare variables
int X, Y, Z;
string Output + " "=;
srand ( time(NULL) );
//X = rand
//Y = rand
//Z = rand
//Output = X + " - " + Y + " - " + Z
X = txtOuput->Text->rand() % 8999 + 1000;;
Y = txtOutput->Text->rand() % 8999 + 1000;;
Z = txtOutput->Text->rand() % 8999 + 1000;;
Output = X + " - " + Y + " - " + Z;
Output->Text = Output.ToString("C");
}
What my program does, is when you click the button "Generate" It generates three numbers, X, Y, and Z, and stores them into a string to output to a textbox. How ever, I'm getting a ton of errors which in the end, makes me feel dumb about learning Win32. Any comments would be helpful, thanks.
Miscellaneous.
I'm using Microsoft Visual C++ 2010
Windows Form Application
Little knowledge on Win32
Try something like this for the method, I'm not entirely sure the syntax is all correct, but it's close.
1 2 3 4 5 6 7 8 9 10 11 12
// Assuming you have a TextBox Control named Output
System::Void Generate_Click(System::Object^ sender, System::EventArgs^ e)
{
// Seed the random generator
srand ( time(NULL) );
int X = rand() % 8999 + 1000;
int Y = rand() % 8999 + 1000;
int Z = rand() % 8999 + 1000;
// Set the Text property
Output->Text = X.ToString() + " - " + Y.ToString() + " - " + Z.ToString();
}
By the way, what you're coding there is called C++/CLI - it's Microsoft's custom C++ <-> .NET mess hybrid, but believe me when I say it's quite a bit nicer to build GUIs with than the native Win32 API.
1>------ Build started: Project: Random_Gen, Configuration: Debug Win32 ------
1> Random_Gen.cpp
1>c:\users\matt\desktop\random_gen\random_gen\Form1.h(111): error C2064: term does not evaluate to a function taking 1 arguments
1>c:\users\matt\desktop\random_gen\random_gen\Form1.h(117): error C2065: 'Output' : undeclared identifier
1>c:\users\matt\desktop\random_gen\random_gen\Form1.h(117): error C2227: left of '->Text' must point to class/struct/union/generic type
1> type is ''unknown-type''
1> Random_Gen1.cpp
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The best I can go on with that output (not seeing your full source code) is that your text box control isn't named "Output". Go into the designer and change the text box's name field to Output
If you paste the entire source I can tell you exactly what's wrong.
Line 41 -> What's the timer for? I think you want to seed the random generator with the current time, which won't happen because your timer (srand) has the same name as the functions in ctdlib.h: http://cplusplus.com/reference/clibrary/cstdlib/
To fix that, remove your timer.
Line 117 -> Output doesn't exist, you need to use your text box as the variable (see line 42)