Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get input from user in function

Status
Not open for further replies.

raydona

Programmer
May 12, 2005
27
GB
I have the following event handlers for a button and a text box:

private: System::Void button_Click(System::Object^ sender, System::EventArgs^ e)
{ function(0);
}
private: System::Void textBox_Validating(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e)
{ if(!CheckIfTextBoxNumeric(textBox))
e->Cancel = true;
}
bool CheckIfTextBoxNumeric(TextBox^ myTextBox1)
{ //checks text input only contains numbers
//returns true if so
}
void function(int select)
{ int result = 0;
//validate text is digit
try
{ result = Convert::ToInt32(insrtMnytxtBox->Text); ----- line A
}
catch(Exception^ myException)
{ cstmrInfolabel->Text = "Exception : ",myException->Message;
}
//rest of code
}
When program execution reaches line A in function, program does not pause for text input from user, that is, program does not allow user the chance to enter numbers. In C++ it would be the equivalent of cin >> result; How can I cause the program to pause so that the user has a chance to enter something.
 
I thought the equivalent of cin>>result was Console.Read or Console.ReadLine. Shouldn't have anything to do with text boxes.
 
I think you are getting mixed up with Console and WinForm apps?

In windows app (Textboxes Buttons etc) the user enters data and creates an event by clicking something (usually). This event will complete and then some feedback is displayed in a status bar or label i.e. like, “Save Completed” or “Please supply an address with the contact” etc. In this instance.

Step 1 the form would be displayed with a label asking the user to supply a number.
Step 2 the button validate (button in this case) would then be clicked. The validating code would run and then a message would be displayed at the end of the click event supplying information on how the validation went. Hope this helps


Age is a consequence of experience
 
Sorry, my question was not very clear. When the button is clicked function(0) is invoked in which, the code is not shown, a label with text: "Enter an integer" is displayed.
After that appears the statements:
try
{ result = Convert::ToInt32(insrtMnytxtBox->Text);
}
catch(Exception^ myException)
{ cstmrInfolabel->Text = "Exception : ",myException->Message;
}
It is these statements that are being bypassed. In C++ if I had written cin >> result; program execution would have suspended until the user typed in an integer. That is what is not happening here.
I have added a label, again not shown, with text: "You have not entered anything" just before function(0) terminates. It is this label that is being displayed after the first label. The above statements are being bypassed. I would like to know how to suspend program execution in between the two labels being displayed, that is the second label must not be shown until characters are entered. In short I would like to force text button event to take place.
 
you could try (i think, not at my PC at the min)
Code:
MyButtonName.PerformClick();

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top