PDA

View Full Version : Is there a way to tell a program to do something a special amount of times? Help?


najkiie
01-07-2009, 06:19 PM
Hey there, i was just wondering if there is a way to tell my program to do a command a special amount of times (amount of times specified in a textbox)?
And each time it does it i want it to add the value of "1" to a textbox.


I tried this method... but after doing the command once it wont continue doing it, and it doesn't add "1" each time to a textbox :(


txtAmount is a textbox, if the user puts in lets say '3' and then click "start" i want the txtTimes to add "1" to itself and execute a command , and then check if the value is the same as txtAmount, if its NOT the same i want it to continue executing the command and adding "1" to itself.. If it is, i just want it to show a msgbox.



If txtTimes = txtAmount then

msgbox"Finished", vbInformation, "Title.."

else

do
command here..

txtTimes.text = val(txtTimes.text) + "1"

loop

End If



If i don't use the "loop" command in there it wont do the command at all :S



This method should work right? If not, tell me how to do it, and tell me what i did wrong.

Thanks, -Nike =D
____________________
Please respond, and if there is any other methods that are easier, please give me a code example. =)

I posted this on microsoft's VB Express forums, but nobody replied :/

I'm coding this in Visual Basic Express 2008 if i forgot to tell you that before.

_________________
Problem solved =D

I used this method.

For index As Integer = 1 To count
' Do your stuff here
NextThanks anyways tho =)

-=eibweN=-
01-12-2009, 05:05 AM
i can tell you how this happends in C++ :

int times = 5 ; //how much times to run the function;

int func();
{
MessageBoxA(0,"Hello","Hi",0);
}

for(int i=0;i<(times+1);i++)
{
func(); //the function that you want to execute
}


//This is another method:
int timesrunned = 0;
int timestorun = 5; // how much times u want the function to run
Begin:
timesrunned++;
func();

if(timesrunned <(timestorun+1))
{
goto Begin;
}