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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to display default image? 2

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
585
PH
Good day everyone... i have this line in my program that displays the picture depending on input number,
i would like to ask if there's a way to display a default image in case the input number is not found? Thanks and God bless!

this.Parent.image1.picture = "C:\Program Files\SCMS Info Wave\Pictures\"+ TRIM(this.Parent.text1.value) + ".jpg
 
Hi Mandy,

I assume that, when you say the "input number is not found", you mean that the textbox containing the number is empty? If so, you could do something like this:

Code:
lcImage = EVL(TRIM(this.Parent.text1.value), "MyDefaultImage")
this.Parent.image1.picture =  "C:\Program Files\SCMS Info Wave\Pictures\"+ lcImage + ".jpg"

If I've misunderstood the question, please clarify.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mandy_crw

if no picture/foto is available, we usually show a transparent label that is positioned in a higher ZOrder than the image object.
This label has the caption "no picture available" (in big fat letters) or something like that.

So adapting this to your code it would be like this:
Code:
lcFile = "C:\Program Files\SCMS Info Wave\Pictures\"+ ALLTRIM(this.Parent.text1.value) + ".jpg" 
this.Parent.label1.Visible = .F.
IF FILE( lcFile , 1 )
    this.Parent.image1.picture = lcFile
ELSE
    this.Parent.label1.Visible = .T.
ENDIF

HTH

-Tom
 
I could'nt say more Tom and Mike!!! Thanks for your very helpful tips and answers!!!!God bless!!!! i am still finishing my project.... please continue to be a blessing to everyone.....
 
Hi Tom and Mike.... Here's what i did.... and worked!!!! thanks so much to both of you.... Great help!!! God bless!

excerpt
iF FOUND()

this.Parent.text1.value = TRIM(tsulat.idnum)
this.parent.text2.value = TRIM(tsulat.sname) + ", " + TRIM(tsulat.fname)
this.Parent.text3.value = TRIM(tsulat.mobile)

lcFile = "D:\Program Files\SCMS Info Wave\Pictures\"+ ALLTRIM(this.Parent.text1.value) + ".jpg"

this.Parent.image2.Visible = .F.

IF FILE( lcFile , 1 )
this.Parent.image1.picture = lcFile
this.parent.image1.visible = .t.
ELSE
this.Parent.image1.visible = .f.
this.Parent.image2.Visible = .T.
ENDIF
 
Hi Mandy,

Good to see that you have got it working. And thanks for posting your code. It's always good to see the final result.

Now, could I make a suggestion. When posting program code on Tek-Tips, it is a good idea to wrap it in "code" tags, so that it appears nicely formatted with all the original indentations in place. This makes it a lot easier to read.

To do that, either type [ignore]
Code:
[/ignore] immediately before the code, and [ignore]
[/ignore] immediately after it; or highlight the code and click the "Code" button on the toolbar, just above the editing area - the button is about three buttons to the right of the yellow smiley.

This is how the code from your previous post would look with the formatting in place:

Code:
THIS.PARENT.text1.VALUE = TRIM(tsulat.idnum)
THIS.PARENT.text2.VALUE = TRIM(tsulat.sname) + ", " + TRIM(tsulat.fname)
THIS.PARENT.text3.VALUE = TRIM(tsulat.mobile)

lcfile = "D:\Program Files\SCMS Info Wave\Pictures\"+ ;
    ALLTRIM(THIS.PARENT.text1.VALUE) + ".jpg"

THIS.PARENT.image2.VISIBLE = .F.

IF FILE( lcfile , 1 )
    THIS.PARENT.image1.PICTURE = lcfile
    THIS.PARENT.image1.VISIBLE = .T.
ELSE
    THIS.PARENT.image1.VISIBLE = .F.
    THIS.PARENT.image2.VISIBLE = .T.
ENDIF

You'll notice that I have also changed the key words (such as THIS and VISIBLE) to all caps. This is a VFP convention, but is by no means essential.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ok Mike... thank you for the very cool tip.... God bless!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top