Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Do while loop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vanna - 22 Mar 2006 03:01 GMT
I need to create a loop to test if the value "56A" exist.  It should loop
until C<25.  If "56A" exists, then call a function.  If c reaches 25 and
"56A" does not exist, then call a different function.

I had this code created.  It seems like both the happy and sad functions are
performed when "56A" is found.

What's a better method to put this code?

   c = 10
   Do While sValue <> "56A" or c<25
     
             If sValue = "56A" Then
                         call happy
               Else
           c = c + 1
       End If
       
   Loop
   call sad
Myles - 22 Mar 2006 04:27 GMT
Hi Vanna,

Not surprising. After "56A" is found and "Happy" called, the loop i
exited only to call "Sad" again.  To avoid calling "Sad" after "Happy"
adjust your code thus:

c = 10
Do While sValue <> "56A" or c<25

If sValue = "56A" Then
call happy
EXIT SUB  =====> INSERTE
Else
c = c + 1
End If

Loop
call sad

Myle
Vanna - 22 Mar 2006 16:47 GMT
Hi Myles,
thank you very much for answering to my post.
I tried your solution and it worked for me partially.  Now I'm getting
information populated in my "Happy" worksheet, but I'm also getting
information populated for my "Sad" worksheet.

Perhaps I didn't explain my situation in enough detailed.

I have a do loop inside a do loop.  Say, List of A to Z records
Inside each record, I need to extract field inforamation and populate them
into the "happy" or "Sad" spreadsheet.  I don't know where I should put my
"SAD" function so that it only runs either "Happy" or "SAD".  Now, I'm
getting results on both spreadsheets

bError = False
   x = 15
   intNumberOfTrades = 7
   i = 8
 
       Do Until bError = True
           
               If sValue = " " Then
               Exit Do
           End If
           
                     
           
'---------------------------------------------------------------------
           '   Check if Further Benneficiary exists (row 56A on Audsum
Mnemonic)
           '   if true, call HAPPY
           
'---------------------------------------------------------------------
           
           
           c = 9
       Do While (sValue <> "56A" Or c < 25)
       
           sValue = Trim$(sValue)
       
           If sValue = "56A" Then
               Call HAPPY
               Exit Do
           Else
               c = c + 1
           End If
           
           
       Loop
           
           Call SAD
                                                 

           i = i + 1
           intNumberOfTrades = intNumberOfTrades + 1
           
                       
           If x < 37 Then
               x = x + 2

           ElseIf x >= 37 Then
'go to next screen                
    x = 15
           End If

           rc = MB_CopyPSToString(gPSid, 40, 2, 5, sMessage) '

           If sMessage = "I9001" Or sMessage = "E8001" Then
               bError = True
           End If
           
       Loop
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.