Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional "ControlSource" for Grid 2

Status
Not open for further replies.

David Higgs

Programmer
May 6, 2012
390
GB

I have the following Code in a GRID REFRESH

Code:
	this.Column8.ControlSource = 'PADL(ALLTRIM(STR(cLogbook.STX)),3,"0")'

The Code Converts an Integer Value from a Table and displays it as a 3 Character String, padded out with Leading Zero's (001,002 etc). What I would like to do is only PAD out a Value that is greater than Zero. If the value is Zero, I would prefer the Display to be Blank.

Any help would be most appreciated.

Regards,

David.

Recreational user of VFP.
 
I'd even forget about that, you can set the text1.InputMask to 999 and text1.Format to LZ, controlsource can be your stx field.

Bye, Olaf

Olaf Doschke Software Engineering
 
Mike,

Thank you for your reply and your Code which worked exactly as per my explanation of my requirements. However, typical of me, it wasn't until I checked the operation of the code that I realised that on occasions the Value could be in excess of 999. So the results I am getting are 1, 28, 123, 1023 appearing as 001,028,123,***. What I was looking for was to PAD numbers 1 to 99 to 3 Chrs and still be able to see 3 & 4chrs (001,028,123,1023). I can live with the (***) if there is no other option.

Changing the code to:

Code:
this.Column8.ControlSource = 'TRANSFORM(cLogbook.STX, "@LZ 9999")'

produces 0001,0028,0012,1023

I'm thinking along the lines of using your original code and the above code in an IIF Statement but I'm having problems with the Syntax.

Olaf,

Your code also worked as per my explanation of my requirements with similar results as above.


Regards,

David.

Recreational user of VFP.
 
It's unusual that you want padding up to 3 for numbers lower than 1000 and then 4 for everything up to 9999, then you need two textboxes and seitch between them with DanymicCurrentControl, which needs a condition of the number range of STX, I wouldn't do that with a single textbox and more complex IIF() transform, because I would prefer this to stay a number and not an expression.

Otherwise you can have IIF(stx<1000,expression1,expression2) or more different expressions with ICASE. But your single textbox can't have multiple maxlengths or inputmasks with differing sizes, so that can only apply to display.

Another perhaps better idea is to use DanymicForeColor to color numbers larger 999 different from those lower 1000.

Bye, Olaf.

Olaf Doschke Software Engineering
 
...or use DynamicFointBold to highlight large values. Anyway, different padding would just confuse me, then I'd rather stay without any padding, just right alignment (as is normal with numeric fields) and courier font (or any monospaced font).

Bye, Olaf.

Olaf Doschke Software Engineering
 
David, I can't see any obvious way of using TRANSFORM() to get what you want. You might have to resort to a more complex IIF(). Or Olaf's idea of two separate controls, using DynamicCurrentControl to switch between them. (Actually, I'm not sure if that would work. Doesn't the ControlSource belong to the column rather than the individual textboxes?)

If you come up with an expression that meets the requirement, you might find it easiest to put it in its own function, and call that function from your ControlSource expression.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
It is a bit unusual; my application is an Amateur Radio Logbook where details of Radio Contacts are recorded. One Amateur Radio activity is called a “Contest” where each Operator taking part in the “Contest” Exchange a “Report” consisting of a “Signal Strength” and a “Serial Number”. Suppose you and I were on our Radios and we exchanged “Reports” where your Signal Strength is 59 and your Serial Number is 59. So, your Report recorded in the Logbook would be “59 059”. If there was any interference / Fading of our signals you will know if you have received the “Report” Correctly because you will be looking for a 2 Digit Signal Report and a 3 Digit Serial Number. If your serial Number is only one or two digits you will know that you have missed some information.

I am currently looking at getting the following code working:-

Code:
IIF (cLogbook.STX >999,this.Column8.ControlSource = 'TRANSFORM(cLogbook.STX,"@LZ 9999")','this.Column8.ControlSource = TRANSFORM(cLogbook.STX,"@LZ 999")'')

but so far have been unsuccessful.

Regards,

David.

Recreational user of VFP.
 
You can't execute code inside IIF, your value for the controlsource needs to be an IIF expression.

Just modify this
Code:
this.Column8.ControlSource = 'IIF(cLogbook.STX >999,TRANSFORM(cLogbook.STX,"@LZ 9999"),TRANSFORM(cLogbook.STX,"@LZ 999"))'

So you can't switch controlsources, you can have an expression that swiches string formatting based on conditions. The expression iotself can't change, so it has to switch and be an IIF.

The other solution would - as said - be two textboxes one for each settings and switching between them with DyanamicCurrentControl. As tthat switches between two controls the whoile set of properties can vary and you can even switch between different controls (not necessary here) and change all properties, not just DynamicpXYZ properties, so that is the most versatile solution.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Actually, what you could do is something like this:

Code:
TRANSFORM(cLogbook.STX, IIF(cLogbook.STX <=999, "@LZ 999", "@LZ 9999"))

but I'm nor sure if that would produce the desired result.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
And actually when all values <=999 are done with "@LZ 999" there is no need for leading zeros and blank value for STX>=1000, all numbers like that are already 4 digits long (or longer) and need no leading zero, so you could let them stay as is and this would then even work for all larger values, and there will be no blank cells, they're already covered in the <=999 case. I already said I think this is a bad decision to have different padding for different ranges, but when that's wanted, then that's wanted.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Mike / Olaf,

Thank you very much for your help, much appreciated. I am pleased to report that both examples produced the desired result.



Regards,

David.

Recreational user of VFP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top