Beginner VB

Moderators: None (Apply to moderate this forum)
Number of threads: 1244
Number of posts: 2990

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
repeating a procedure Posted by satsoc on 5 Apr 2002 at 7:50 AM
i have to make a program with an option that after it finishes we can repeat the procedure all over again.Something like :
repeat? (Yes,No).if yes then we clear the screen and start the procedure again.

Any help?
Report
Re: repeating a procedure Posted by hobby on 5 Apr 2002 at 8:34 AM
: i have to make a program with an option that after it finishes we can repeat the procedure all over again.Something like :
: repeat? (Yes,No).if yes then we clear the screen and start the procedure again.
:
: Any help?
:

Start your program with a function call (maybe void main() or initParameters). Then at the end of the procedure, display a messagebox:
retVal = msgbox("Do you want to repeat?",vbYesNo,"Repeat?")
if retVal = vbYes
    ClearParameters  ' Clear variables and reset properties
    InitParameters   ' Start over
else
    End              ' End the program
end if


This way, you can reset whatever you need to in ClearParameters and can call one procedure to start over again. You can probably compress the statements into fewer lines, but this is for clarity.

Report
Re: repeating a procedure Posted by satsoc on 5 Apr 2002 at 10:32 AM
This message was edited by the satsoc at 2002-4-5 14:35:53

This message was edited by the satsoc at 2002-4-5 14:18:16

: : i have to make a program with an option that after it finishes we can repeat the procedure all over again.Something like :
: : repeat? (Yes,No).if yes then we clear the screen and start the procedure again.
: :
: : Any help?
: :
:
: Start your program with a function call (maybe void main() or initParameters). Then at the end of the procedure, display a messagebox:
:
: retVal = msgbox("Do you want to repeat?",vbYesNo,"Repeat?")
: if retVal = vbYes
:     ClearParameters  ' Clear variables and reset properties
:     InitParameters   ' Start over
: else
:     End              ' End the program
: end if
: 

:
: This way, you can reset whatever you need to in ClearParameters and can call one procedure to start over again. You can probably compress the statements into fewer lines, but this is for clarity.
:
:

newbie question but shouldn't i call the function into a variable?because when i declare the function main(),for example,into a sub
then i have error messages.where do you think should i use this code?

ok man.i've got it.

thanks for your help





Report
Re: repeating a procedure Posted by hobby on 8 Apr 2002 at 7:56 AM
: This message was edited by the satsoc at 2002-4-5 14:35:53

: This message was edited by the satsoc at 2002-4-5 14:18:16

: : : i have to make a program with an option that after it finishes we can repeat the procedure all over again.Something like :
: : : repeat? (Yes,No).if yes then we clear the screen and start the procedure again.
: : :
: : : Any help?
: : :
: :
: : Start your program with a function call (maybe void main() or initParameters). Then at the end of the procedure, display a messagebox:
: :
: : retVal = msgbox("Do you want to repeat?",vbYesNo,"Repeat?")
: : if retVal = vbYes
: :     ClearParameters  ' Clear variables and reset properties
: :     InitParameters   ' Start over
: : else
: :     End              ' End the program
: : end if
: : 

: :
: : This way, you can reset whatever you need to in ClearParameters and can call one procedure to start over again. You can probably compress the statements into fewer lines, but this is for clarity.
: :
: :
:
: newbie question but shouldn't i call the function into a variable?because when i declare the function main(),for example,into a sub
: then i have error messages.where do you think should i use this code?
:
: ok man.i've got it.
:
: thanks for your help
:

The void Main() is a Sub that VB uses if there isn't a form. It can be set in the Project Properties box. But you can call the code from anywhere, but it should be done after you perform your procedure.

Private Sub Main()
    InitParameters ' InitParameters is a Sub
    ' or retVal = InitParameters if InitParameters is a function
End Sub

Private Function DoStuff() as boolean
   ' Do procedure stuff here

   if Msgbox("Do you wanna repeat?",vbYesNo) = vbYes then
      InitParameters
      DoStuff
   End if
   
   ' Finish code here, clear variables, can be in a separate function
End Function




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.