mcerk Posted January 18, 2005 Posted January 18, 2005 (edited) OK, the subject is a little strange, but anyway. I have a custom control that takes user data. But I'm not sure how to wait until user fills his textbox and presses button. MyControl is placed on Form1. Ok, here is example code 'i'm calling MyControl's GetUser method. It returns True or false. 'the code is located in Form1 If MyControl.GetUser = true '..... Else '...... End if '............ '*** '........ ---------------------------------------------- 'ok, and here is code for MyControl's GetUser method 'located in MyControl Public Functin GetUser() as Boolean 'here I have to wait until user fills textbox (located on MyControl) and presses button (allso located on MyControl). 'so, when button is pressed the function shluld continue and return desired value If textbox.text <> "Matej" then Return True Else Return False End If End Function OK. I think that my question is quite understandable. I have to stop in the middle of code and wait until the button is pressed. Is it possible? tx Matej Edited January 18, 2005 by mcerk Quote
mhildner Posted January 18, 2005 Posted January 18, 2005 Can't you just fire the MyControl.GetUser() call from the button click event? Quote
techmanbd Posted January 18, 2005 Posted January 18, 2005 there is probably something better than this, but here is something I just thought of 'declare variable at the beginning of program dim boolWait as boolean 'this goes where you want to wait boolwait = true do while boolWait application.doevents loop 'in the button sub when you press the button boolWait = false Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
mcerk Posted January 18, 2005 Author Posted January 18, 2005 I can not call it from Form1 in that case. I have to fire method from Form. The button is, as I said on the control.... If I would call it from Form1, Textbox.text value would be in that case "". the problem is, that I do not want the code to continue to '*** (Form1) until user typed his name Is it possibly to somehow wait in the middle of code and continue when Button_Click event occures? (if a procedure in control stops, code continues to run in the form and goes to '***....) PS: (see above post for '*** section) Quote
mcerk Posted January 18, 2005 Author Posted January 18, 2005 there is probably something better than this, but here is 'this goes where you want to wait boolwait = true do while boolWait application.doevents loop boolWait = false this looks nice, I'm sure it is not only solution, but I can try it. do you know how much resources (cpu, ram) takes this action? is it a lot, or is it not noticable? tx m Quote
IngisKahn Posted January 18, 2005 Posted January 18, 2005 There's no reason to keep code "running". Just use the Click event of the button. Windows programs work using events (messages). Quote "Who is John Galt?"
mcerk Posted January 18, 2005 Author Posted January 18, 2005 I know that. But How can I use click event? You have to imagine, that I'm calling control from form1 (let's say from Form_Load). So I Call method: MyControl.GetUser (and in the control's aspect of view this is just a function) so, when this function finishes the code continues to next step (in the form) and that is what I don't want hm. it's hard to actually display it, but I think I did it better on top of the page in the question. Quote
mcerk Posted January 18, 2005 Author Posted January 18, 2005 I can do it by declaring Public Event ReturnValue(AllowLogin as boolean) in the control. And then Fireing it from needed location in the control. I can then catch it in a Form1. But this is not so elegant solution....... Quote
IngisKahn Posted January 18, 2005 Posted January 18, 2005 That is, in fact, the standard way of doing things. Quote "Who is John Galt?"
mcerk Posted January 19, 2005 Author Posted January 19, 2005 Ok, but there are similar examples in vb. if you start Form2 from Form1 by dim f as new form2 f.show ...the code will continue but if you start it as dialog f.showdialog then the code stops and continues when form is closed... is it possible to do something similar with control? Quote
IngisKahn Posted January 19, 2005 Posted January 19, 2005 A UserControl is part of a form, just like a Button. There's no way to show it modally. If you want to show a modal form then go ahead, otherwise you need to use events. It's exactly the same as it was in VB6 Quote "Who is John Galt?"
*Experts* DiverDan Posted January 20, 2005 *Experts* Posted January 20, 2005 Not knowing what your user control is or does, but you can set a Public Properity event that is accessed with the button click and proceed from there. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.