Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
data_pos = 5
Header = 5
        For loopc = 0 To 650
            target_time = Cells(loopc + Header, 8).Value
               Do
                raw_data1 = Cells(data_pos, 4).Value
                raw_data2 = Cells(data_pos + 1, 4).Value
                If target_time >= raw_data1 And target_time < raw_data2 Then
                    Cells(loopc + Header, 9).Value = Cells(data_pos, 5).Value
                    Exit Do
                End If
                data_pos = data_pos + 1
            Loop
        Next loopc


How to convert the following code to php

What I have tried:

I don't know about Do statement without condition
Posted
Updated 18-Apr-19 20:15pm
v2

There's a condition which finish executing do...loop statement! See:

VB
If target_time >= raw_data1 And target_time < raw_data2 Then
     Cells(loopc + Header, 9).Value = Cells(data_pos, 5).Value
     Exit Do
End If


All you have to do is to put this part into do...loop statement :)

PHP
<?php
do {
    //some instructions 
} while (...); //here!
?>


But i think that - in this case - it would be better to use while statement.

Good luck!
 
Share this answer
 
v2
Quote:
I don't know about Do statement without condition

A Do-Loop without condition is basically an infinite loop. In your case, there is a condition, it is the If-Then which contain the Exit Do.
Use the debugger to watch the code execute, it is a great learning tool.
-----
Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

Debugging in Excel VBA - EASY Excel Macros[^]
MS Excel 2013: VBA Debugging Introduction[^]
How to debug Excel VBA - YouTube[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900