How to stop code from running?

mcerk

Regular
Joined
Nov 1, 2004
Messages
78
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

Visual Basic:
'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
 
Last edited:
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
 
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)
 
techmanbd said:
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
 
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.
 
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.......
 
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?
 
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
 
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.
 
Back
Top