ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Skip LOC in D While Loop (https://www.excelbanter.com/excel-programming/382226-skip-loc-d-while-loop.html)

Khurram

Skip LOC in D While Loop
 
Hi all,
Can anyone tell me if the below scenario is possible. I'm trying to
do this using Excel VBA. Basically if results equals to zero, I do
not want any of the next lines of code to be executed and the code to
loop again. I know I can simply use a GoTO statement using a label
but trying to avoid spaghetti code. Any suggestions please


Function abc As String

Do while (condition is not met)

code line 1
code line 2
results = code line 3

if (results = 0) = True Then goto end of Loop

code line 4
code line 5
code line 6

Loop

End Function


Thank you
Khurram


WLMPilot

Skip LOC in D While Loop
 
I believe your code will work, but I have one suggestion. Change the IF
statement to execute the code if the results does not equal zero. Normally a
good habit is to execute the Lines if TRUE instead of bypassing them.

Generic Format:

IF true, THEN
execute code
END IF



if results < 0 Then
Line 4
Line 5
Line 6
End if

LOOP

Good Luck,
Les


"Khurram" wrote:

Hi all,
Can anyone tell me if the below scenario is possible. I'm trying to
do this using Excel VBA. Basically if results equals to zero, I do
not want any of the next lines of code to be executed and the code to
loop again. I know I can simply use a GoTO statement using a label
but trying to avoid spaghetti code. Any suggestions please


Function abc As String

Do while (condition is not met)

code line 1
code line 2
results = code line 3

if (results = 0) = True Then goto end of Loop

code line 4
code line 5
code line 6

Loop

End Function


Thank you
Khurram



Khurram

Skip LOC in D While Loop
 
Interesting, Thank you Les, I will adhere to your advice.

Cheers
Khurram

On Jan 30, 3:58 pm, WLMPilot
wrote:
I believe your code will work, but I have one suggestion. Change the IF
statement to execute the code if the results does not equal zero. Normally a
good habit is to execute the Lines if TRUE instead of bypassing them.

Generic Format:

IF true, THEN
execute code
END IF

if results < 0 Then
Line 4
Line 5
Line 6
End if

LOOP

Good Luck,
Les



"Khurram" wrote:
Hi all,
Can anyone tell me if the below scenario is possible. I'm trying to
do this using Excel VBA. Basically if results equals to zero, I do
not want any of the next lines of code to be executed and the code to
loop again. I know I can simply use a GoTO statement using a label
but trying to avoid spaghetti code. Any suggestions please


Function abc As String


Do while (condition is not met)


code line 1
code line 2
results = code line 3


if (results = 0) = True Then goto end of Loop


code line 4
code line 5
code line 6


Loop


End Function


Thank you
Khurram- Hide quoted text -- Show quoted text -




All times are GMT +1. The time now is 08:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com