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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access Do-Loop problem

Status
Not open for further replies.

u382514

Programmer
Apr 7, 2004
7
0
0
US
Ok, so try this one on for size. I've created a do/while loop in my program. For some reason when I run the program, it seems to skip right through the do/loop...this is what it looks like...

do
PSReturn = ehllapicopypstostring(start$,1,13)
loop while PSReturn <> 0

Ehllapi.. returns a 4 when it is waiting on the sytem (long story) and only fully copys the string in the system when PSReturn passes a 0. It's obviously passing a 4 in the program, but it doesn't stay within the loop. Anybody have these kind of problems? Is it possible that the the ehllapi.. is not passing the value quick enough???


-Brandon-
 
u382514,

what type of variable is PSReturn? it appears to be a string and it appears you are using an integer in you logic.
try stepping through the code and when you get to the loop line put your mouse pointer over PSReturn to see what value is stored there.

regards,
longhair
 
Um, there is no while.. a do while loop is a conditional statement, so if a condition doesn't even exist, then it will never enter the loop. so it should be something like this:
Code:
Do While Not rs.EOF
  ~code
Loop


Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
kjv1611,

The form

Code:
Do
   'Do Something
While Condition

Is perfectly acceptable. The loop will *always* execute once no matter what the Condition is. In fact, you can have no condition on the loop at all and it will loop forever.

Code:
Do
   'Do Something
   If Condition Then Exit Do
Loop
 
The 'other' valid option is

Do
<code>
Loop Until <condition>



I've seen a repeat forever loop coded as


Code:
Const TheCowsComeHome As Boolean = False

Do

    <code>

Loop Until TheCowsComeHome

See. Even some coders have a sense of humour.





G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Hmm.. interesting, I did not know that - or else forgot! [WINK]

Anywho, for the problem at hand (question of the thread), could you try the other format to see if it runs better for your particular application? I would think it's worth a try. Also, make sure that PSReturn is actually not equal to 0 at some point in time if the code needs to run.. so, you could code like this:
Code:
Do While PSReturn <> 0
  PSReturn = ehllapicopypstostring(start$,1,13)
Loop

Also, try stepping through the program, so you can see the values of your variables to make sure that PSReturn is not 0 to start with.

Just think it's worth a try - if one way doesn't work, try another.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
WOW!!! Thanks guys! I didn't expect to see this many replies!! I ended up using do/loop/until, and came to find out my PSReturn wasn't returning 0 as it should. THANKS!!!

-Brandon-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top