Converting VB6 code

I am a bit lost on trying to convert a do…loop…while from VB6.

Code is:

Do Target = Chr(Int(Rnd * 26) + 65) Loop While Target = UCase(pTarget)

I am more concerned with just trying to duplicate the do loop while in xojo and have tried a few things that do not work.

I tried putting the while…wend around the do…loop but that doesnt produce the same results.

Any suggestions?



A “do” loop uses “until” conditions in Xojo. So you would end it with Loop Until Target <> UCase(pTarget)

Look at

Both expressions can be used for a loop while a condition is verified or until it is.

While Keyboard.AsyncCommandKey = false wend // or Do Loop Until Keyboard.AsyncCommandKey = true

The while/wend form maybe closer to the VB do/while

Actually, a While loop wouldn’t work here, because the condition is to be evaluated after the loop runs–While loops have to be tested before the loop. (This can be adjusted for by putting the commands both before and inside the loop, but that’s probably more trouble than it’s worth.)

Like this since no one actually showed you the code:

   Target = Chr(Cytpe(Rnd*26,Integer)+65)
Loop Until Target <> Uppercase(pTarget)

You may want to consider using the Random class instead of Rnd as it’s more powerful.

A feature of the Do/Loop loop is that you can evaluate a condition at the start, end, both, or neither. This is distinguished from the While/Wend loop where the condition must be evaluated at the start.

All of these are valid:

loop // endless so use 'exit' or 'return' somewhere in the loop

do until someCondition // A reverse While/Wend

loop until someCondition

do until someCondition
loop until someOtherCondition

Also, the test

Target <> Uppercase(pTarget)

may function differently in Xojo, because the default string comparison is not case sensitive. If you need case sensitive string comparison use StrComp.

Thanks for all the help. The loop until seems to work as expected for me in this case. For the UCase part I just used pTarget.Text.Uppercase and that seems to work.

It will work, but may not do what you want. In Xojo, “s” = “S”.