Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combobox driving me crazy....
Message
From
05/04/2002 23:35:36
Ken Dibble
Southern Tier Independence Center
Binghamton, New York, United States
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00641186
Message ID:
00641733
Views:
13
Thanks, Sergey.

I've read in several places that macro substitution should be avoided when possible. Parentheses are used in so many different ways in VFP, and I've never come across a clear explanation of all of their uses. However, it does surprise me that a function call like EVAL() would be significantly faster than a macro.

Does DO CASE add speed also, or just a sort of logical readability? Doesn't the engine have to evaluate the entire DO CASE structure when it encounters it, whereas it need only look at the first line of each IF statement?

Thanks again.

>A few friendly advises. You're overusing macro substitution in your code which makes it slower, harder to read and maintain.
>
USED("&thetable")
>* is the same as
>USED(thetable)
>
>IF &thefield = .T.
>* is the same as
>IF EVAL(thefield)
>
>REPLACE &thefield WITH .T.
>* is the same as
>REPLACE (thefield) WITH .T.
>
Also multiple related IF's could be replaced witd DO CASE ENDCASE
>               DO CASE
>               CASE ISNULL(EVAL(thefield))
>                    THIS.Value = ""
>               CASE EVAL(thefield)
>                    THIS.Value = "Yes"
>               CASE NOT EVAL(thefield)
>                    THIS.Value = "No"
>               ENDCASE
>
>
>>>This shouldn't be so hard....
>>>
>>>What I'm trying to do is create a self-contained combobox class that will dropdown a Yes/No option, placing a corresponding .t. or .f. into a table.
>>
>>Hi Steve,
>>
>>Would this work? Put this on a form and set the value of YesNoSource to
>>[some table].[some field]:
>>
>>
>>DEFINE CLASS Yncombo AS Combobox
>>     RowSourceType = 1
>>     RowSource = "Yes,No"
>>     Style = 2
>>     FieldName = ""
>>     TableName = ""
>>     YesNoSource = ""
>>
>>     PROCEDURE Init
>>          LOCAL dotspot, thetable, thefield
>>
>>          dotspot = AT(".",THIS.YesNoSource)
>>
>>          STORE LEFT(THIS.YesNoSource,(dotspot - 1)) TO THIS.TableName
>>          STORE SUBSTR(THIS.YesNoSource,(dotspot + 1)) TO THIS.FieldName
>>
>>          STORE THIS.TableName TO thetable
>>          STORE THIS.FieldName TO thefield
>>
>>          IF USED("&thetable")
>>               IF &thefield = .T.
>>                    THIS.Value = "Yes"
>>               ENDIF
>>
>>               IF &thefield = .F.
>>                    THIS.Value = "No"
>>               ENDIF
>>
>>               IF ISNULL(&thefield)
>>                    THIS.Value = ""
>>               ENDIF
>>          ELSE
>>               THIS.Value = ""
>>          ENDIF
>>     ENDPROC
>>
>>     PROCEDURE Valid
>>          LOCAL thetable, thefield
>>
>>          STORE THIS.TableName TO thetable
>>          STORE THIS.FieldName TO thefield
>>
>>          IF NOT EMPTY(THIS.DisplayValue)
>>               IF NOT USED("&thetable")
>>                    MESSAGEBOX("The Yes/No Combobox data source is not open.")
>>                    THIS.DisplayValue = ""
>>                    RETURN
>>               ENDIF
>>          ENDIF
>>
>>          IF THIS.DisplayValue = "Yes"
>>               REPLACE &thefield WITH .T.
>>          ENDIF
>>
>>          IF THIS.DisplayValue = "No"
>>               REPLACE &thefield WITH .F.
>>          ENDIF
>>
>>          IF EMPTY(THIS.DisplayValue)
>>               REPLACE &thefield WITH .F.
>>          ENDIF
>>     ENDPROC
>>ENDDEFINE
>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform