If you don't have NOWAIT in the Browse, the next code line happens after the browse window is closed, so yes, you don't get it colored. You must have NOWAIT if you want to act on the BROWSE window.
But then the form vanishes. Why does the browse vanish, if you use NOWAIT? Well, oBrowse becomes a variable created by the NAME clause, not the Name property of the Browse window. It has to be kept alive - in scope - even after the method or prg ends. because when oBrowse is released the window closes. This is the same effect you have with any object reference, the object vanishes, if the last variable storing a reference to it is released. And if there is just one variable, which is released at the end of code running, that closes the BROWSE window.
So how do you get out of this dilemma? You need the simplest form handler of the world, a bare native collection you keep available public and store any form references in. It has a double effect:
1. It keeps the reference alive and a form does not vanish (including browses)
2. It automatically removes the reference, if the form closes itself. So you don't need any form handler code to remove a reference to release a form.
That is a very clever concept MS did on this collection class, as it allows you to easily keep form references in scope as long as you need them, but also get rid of them from inside of the form. Especially since you can't write code into the Release method or QueryUnload of any Browse Window to ask a form handler to release the form referene it keeps, there is no Brows class you may subclass. It's simply sweet the collection detects any form closing and reacts to it by removing any item of it referencing it. This is only happening for forms, though, not for any other object baseclass.
Code:
PUBLIC goForms
goForms = CREATEOBJECT("collection")
USE ?
BROWSE NAME oBrowse nowait
goForms.add(oBrowse)
oBrowse.BackColor = RGB(255,0,0)
The only thing you can do a bit better is not using a public variable for the forms collection, but rather make that a property of your global Application object goApp. an instance of an application class handling all globally application specific things. The only public variable acceptable to even public variable opponents (like me and any sane developer). Naming it goApp is an unwritten law, a known convention about many application frameworks. You may even avoid that single public variable by attaching this to _screen or _vfp or the OLE object Application via Addproperty(_vfp,"oApp") and _vfp.oApp = CreateObject("yourapplicationclass").
Learn more about scoping of variables and objects/classes in general, and you'd know when any object releases. Even if you don't program OOP, you can't avoid using objects, not only because some are nativle there always. Any DO FORM also created an object, any control on a form is an object, etc. So get used to objects and the term object reference. That avoids many such questions and surprise moments. A last clue on this: When doing things the wrong way within VFP itself as IDE, you're saved by the IDE running. It keeps things in scope, which would end their scope in an exeutable. The most famoous thing nobody gets the first time (including me) is having a main not having READ EVENTS. The end of executing anything, returning from the last level of the callstack, an EXE finishes, forms vanish, but the IDE is a last stack level always there to hold a few things alive. This scoping issue needs to be understood.
If you take it serious, you nevertheless don't use BROWSE at all as any output or edit window. You are in the world of Windows and its forms, everything you present to a user should be a form. BROWSE just becomes a tool for you as developer to get a quick glance at a workarea or DBF. I can understand you may have lots of legacy code you would need to rewrite, but that's the way it is. It's just a kludge to keep Browses going. it should only be that and you should migrate any BROWSE usage to creating a popup form. you may even find better UI solutions in integrating a grid into a pageframe or any other way of making it a part of the main form.
Bye, Olaf.