如何将VBA do循环转换为PHP循环 [英] How to convert VBA do loop to PHP loop

查看:96
本文介绍了如何将VBA do循环转换为PHP循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 data_pos =  5  
标头= 5
对于 loopc = 0 650
target_time = Cells(loopc + Header, 8 )。值
< span class =code-keyword>
raw_data1 = Cells(data_pos, 4 )。值
raw_data2 = Cells( data_pos + 1 4 )。值
如果 target_time> = raw_data1 target_time< raw_data2 然后
Cells(loopc + Header, 9 )。Value = Cells(data_pos,< span class =code-digit> 5 )。值
退出 执行
结束 如果
data_pos = data_pos + 1
循环
下一步 loopc





如何将以下代码转换为php



我有什么试过:



我不知道没有条件的Do语句

解决方案

这里有完成执行的条件...循环语句!请参阅:



 如果 target_time> = raw_data1  target_time< raw_data2 然后 
Cells(loopc + Header, 9 )。Value = Cells(data_pos,< span class =code-digit> 5 )。值
退出 执行
结束 如果





你所要做的就是将这部分放入 do ... loop 声明:)



 <?php  
do {
// 一些说明
} while (...); // 此处!
?>





但我认为 - 在这种情况下 - 最好在时使用声明。



祝你好运!


Quote:

我不知道没有条件的Do语句



没有条件的Do-Loop基本上是一个无限循环。在你的情况下,有一个条件,它是包含Exit Do的If-Then。

使用调试器观察代码执行,它是一个很好的学习工具。

-----

你的代码没有你想象的那样,或者你不明白为什么!



有一个几乎通用的解决方案:逐步在调试器上运行代码,检查变量。

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它不知道你的代码应该做什么,它没有找到错误,它只是通过向你显示正在发生的事情来帮助你。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。



调试器 - 维基百科,免费的百科全书 [ ^ ]


掌握调试Visual Studio 2010 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]



在Excel VBA中调试 - 轻松的Excel宏 [ ^ ]

MS Excel 2013:VBA调试简介 [ ^ ]

如何调试Excel VBA - YouTube [ ^ ]



调试器仅显示您的代码正在执行的操作,您的任务是与应该执行的操作进行比较。


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

解决方案

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

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
do {
    //some instructions 
} while (...); //here!
?>



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

Good luck!


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.


这篇关于如何将VBA do循环转换为PHP循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆