Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Better way of coding this
Message
From
16/12/2008 10:26:35
 
 
To
16/12/2008 09:31:37
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01367822
Message ID:
01367887
Views:
9
OK, you didn't say in which way you wanted to "improve" the example code. So now you're saying there may be 1 - x textboxes, depending on "what was defined in the INIT of the instance"? Well do the loop THAT many times then.

I imagine macro subs and one loop, with one defo would be better than 10, with only x used depending on "what was defined in the INIT of the instance".

Also, I HATE repetition of the scope of an object within all its containers. It makes the code ugly and harder to read, as well as you have really long statements, sometimes going off the A4 page.

>I thought of that at first, but then wasn't sure if using macro substitution was the best way to handle it. Also, I didn't say this, but I would like to make it so the number of loops/textboxes would depend on what was defined in the INIT of the instance.
>
>>You saying you'd have to repeat the if block 10 times?
>>
>>If so, can't you put one block in a for loop, 10 times, and macro-subs the .DispLabel and DisplayValue endings (assuming they're all set to the same properties).
>>Oh, and "With" these huge blocks, just to keep the aesthete in me happy and to save processor time re-navigating the scope of each element for every statement.
>>
>>
>>
>>>This is part of a code block I wrote to handle 10 different possible textboxes on a form. I know there is a better/simpler way to handle the different IF/ENDIF blocks. Any quick thoughts?
>>>
>>>
>>>* This code is in the INIT of the instance of the class:
>>>
>>>WITH THIS
>>>	.DispPicture = .F.
>>>	.DispLabel01 = 'Name: '
>>>	.DispValue01 = 'Account.FullName'
>>>	.DispLabel02 = 'Gender: '
>>>	.DispValue02 = 'IIF(Account.Sex="M","Male",IIF(Account.Sex="F","Female",""))'
>>>	.DispLabel03 = 'DOB: '
>>>	.DispValue03 = 'Account.DOB'
>>>	.DispLabel04 = 'Age: '
>>>	.DispValue04 = 'THIS.DeriveAge(Account.DOB)'
>>>	.DispLabel05 = 'Phone: '
>>>	.DispValue05 = 'Account.Phone'
>>>	.DispLabel06 = 'Cell Phone: '
>>>	.DispValue06 = 'Account.CellPhone' 
>>>ENDWITH
>>>
>>>DODEFAULT()
>>>
>>>* This code is in the INIT of the class:
>>>
>>>WITH THISFORM
>>>
>>>	.oPopUpInfoForm = CREATEOBJECT("fm_PopupInfo")
>>>	.oPopUpInfoForm.ALWAYSONTOP = .T.
>>>	.oPopUpInfoForm.AUTOCENTER = .T.
>>>	.oPopUpInfoForm.Visible = .F.
>>>
>>>	m.DisplayTop = 6
>>>	m.Top = m.DisplayTop
>>>	m.DisplayTopIncrement = 18
>>>	m.DisplayLabelOffset = 2
>>>	m.DisplayLeftLabel = 140
>>>	m.DisplayLeftValue = 210
>>>
>>>	IF !EMPTY(THIS.DispValue01)
>>>		.oPopUpInfoForm.ADDOBJECT("DispLabel01", "fm_label")
>>>		.oPopUpInfoForm.DispLabel01.TOP = m.DisplayTop + m.Top + m.DisplayLabelOffset
>>>		.oPopUpInfoForm.DispLabel01.LEFT = m.DisplayLeftLabel
>>>		.oPopUpInfoForm.DispLabel01.WIDTH = 50
>>>		.oPopUpInfoForm.DispLabel01.CAPTION = THIS.DispLabel01
>>>		.oPopUpInfoForm.DispLabel01.VISIBLE = .T.
>>>		BINDEVENT(.oPopUpInfoForm.DispLabel01,"Click",.oPopUpInfoForm,"Click")
>>>		BINDEVENT(.oPopUpInfoForm.DispLabel01,"RightClick",.oPopUpInfoForm,"RightClick")
>>>		.oPopUpInfoForm.ADDOBJECT("DispValue01", "fm_textbox")
>>>		.oPopUpInfoForm.DispValue01.ENABLED = .F.
>>>		.oPopUpInfoForm.DispValue01.Display_Only = .T.
>>>		.oPopUpInfoForm.DispValue01.BORDERSTYLE = 0
>>>		.oPopUpInfoForm.DispValue01.TOP = m.DisplayTop + m.Top
>>>		.oPopUpInfoForm.DispValue01.LEFT = m.DisplayLeftValue
>>>		.oPopUpInfoForm.DispValue01.WIDTH = 250
>>>		.oPopUpInfoForm.DispValue01.BACKSTYLE = 0
>>>		.oPopUpInfoForm.DispValue01.VALUE = TRANSFORM(EVALUATE(THIS.DispValue01))
>>>		.oPopUpInfoForm.DispValue01.VISIBLE = .T.
>>>		BINDEVENT(.oPopUpInfoForm.DispValue01,"Click",.oPopUpInfoForm,"Click")
>>>		BINDEVENT(.oPopUpInfoForm.DispValue01,"RightClick",.oPopUpInfoForm,"RightClick")
>>>	ENDIF
>>>
>>>	IF !EMPTY(THIS.DispValue02)
>>>		m.Top = m.Top + m.DisplayTopIncrement
>>>		.oPopUpInfoForm.ADDOBJECT("DispLabel02", "fm_label")
>>>		.oPopUpInfoForm.DispLabel02.TOP = m.DisplayTop + m.Top + m.DisplayLabelOffset
>>>		.oPopUpInfoForm.DispLabel02.LEFT = m.DisplayLeftLabel
>>>		.oPopUpInfoForm.DispLabel02.WIDTH = 50
>>>		.oPopUpInfoForm.DispLabel02.CAPTION = THIS.DispLabel02
>>>		.oPopUpInfoForm.DispLabel02.VISIBLE = .T.
>>>		BINDEVENT(.oPopUpInfoForm.DispLabel02,"Click",.oPopUpInfoForm,"Click")
>>>		BINDEVENT(.oPopUpInfoForm.DispLabel02,"RightClick",.oPopUpInfoForm,"RightClick")
>>>		.oPopUpInfoForm.ADDOBJECT("DispValue02", "fm_textbox")
>>>		.oPopUpInfoForm.DispValue02.ENABLED = .F.
>>>		.oPopUpInfoForm.DispValue02.Display_Only = .T.
>>>		.oPopUpInfoForm.DispValue02.BORDERSTYLE = 0
>>>		.oPopUpInfoForm.DispValue02.TOP = m.DisplayTop + m.Top
>>>		.oPopUpInfoForm.DispValue02.LEFT = m.DisplayLeftValue
>>>		.oPopUpInfoForm.DispValue02.WIDTH = 250
>>>		.oPopUpInfoForm.DispValue02.BACKSTYLE = 0
>>>		.oPopUpInfoForm.DispValue02.VALUE = THIS.DispLabel02 + TRANSFORM(EVALUATE(THIS.DispValue02))
>>>		.oPopUpInfoForm.DispValue02.VISIBLE = .T.
>>>		BINDEVENT(.oPopUpInfoForm.DispValue02,"Click",.oPopUpInfoForm,"Click")
>>>		BINDEVENT(.oPopUpInfoForm.DispValue02,"RightClick",.oPopUpInfoForm,"RightClick")
>>>	ENDIF
>>>
>>>.
>>>.
>
>>>.
>>>
>>>ENDWITH
>>>
- Whoever said that women are the weaker sex never tried to wrest the bedclothes off one in the middle of the night
- Worry is the interest you pay, in advance, for a loan that you may never need to take out.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform