×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Conditional "ControlSource" for Grid
2

Conditional "ControlSource" for Grid

Conditional "ControlSource" for Grid

(OP)

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.

RE: Conditional "ControlSource" for Grid

David, forget about ALLTRIM() and STR(). Do this instead:

CODE -->

this.Column8.ControlSource = 'TRANSFORM(cLogbook.STX, "@LZ 999")' 

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Conditional "ControlSource" for Grid

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
https://www.doschke.name

RE: Conditional "ControlSource" for Grid

Also, set grid.columnX.sparse = .f.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Conditional "ControlSource" for Grid

(OP)
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.

RE: Conditional "ControlSource" for Grid

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
https://www.doschke.name

RE: Conditional "ControlSource" for Grid

...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
https://www.doschke.name

RE: Conditional "ControlSource" for Grid

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

RE: Conditional "ControlSource" for Grid

(OP)
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.

RE: Conditional "ControlSource" for Grid

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
https://www.doschke.name

RE: Conditional "ControlSource" for Grid

No, all that you are doing there is to show a three-digit number with 2 or 3 leading zeroes, and a four-digit number with four leading zeroes, which is not what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Conditional "ControlSource" for Grid

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

RE: Conditional "ControlSource" for Grid

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
https://www.doschke.name

RE: Conditional "ControlSource" for Grid

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close