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!

What is wrong with 'ADD OBJECT footer.cntpanel1.image1 AS image WITH;' ? Can't I use it As it is?

Status
Not open for further replies.

A Beginner

Programmer
Apr 15, 2017
81
IN
I was going through an article of Mr. ChrisRChamberlain- 'How can I create my own status bar.' on the link-
I actually wanted to create a PROGRESSBAR, but attracted by content of the article I tried the codes in the article on my vfp9.0
Problem is that The code is giving syntax error during compilation.
For the referance I am pasting the code as it is -
PUBLIC ofooter

ofooter=NEWOBJECT("footer")
ofooter.Show
RETURN


*************************************************
*-- Form: footer (c:\test\newfooter.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 02/11/03 09:06:00 AM
*
DEFINE CLASS footer AS form


Top = 0
Left = 0
Height = 27
Width = 812
DoCreate = .T.
ShowTips = .T.
BorderStyle = 0
Caption = ""
ControlBox = .F.
Closable = .F.
FontName = "MS Sans Serif"
TitleBar = 0
WindowState = 0
AlwaysOnBottom = .T.
Name = "FOOTER"
lfullsize = .F.


ADD OBJECT cntpanel1 AS container WITH ;
Top = 4, ;
Left = 1, ;
Width = 53, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel1"


ADD OBJECT footer.cntpanel1.image1 AS image WITH ; && The syntax error strikes compilation here.
Picture = "bitmaps\autoname.bmp", ;
BackStyle = 0, ;
Height = 16, ;
Left = 2, ;
Top = 2, ;
Width = 16, ;
Name = "Image1"


ADD OBJECT footer.cntpanel1.label1 AS label WITH ;
AutoSize = .T., ;
FontName = "MS Sans Serif", ;
Caption = "Label1", ;
Height = 15, ;
Left = 19, ;
Top = 4, ;
Width = 34, ;
Name = "Label1"


ADD OBJECT cntpanel2 AS container WITH ;
Top = 4, ;
Left = 277, ;
Width = 224, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel2"


ADD OBJECT footer.cntpanel2.txtprogressbar AS textbox WITH ;
FontBold = .F., ;
FontName = "MS Sans Serif", ;
Alignment = 2, ;
BorderStyle = 1, ;
Enabled = .F., ;
Height = 20, ;
Left = 0, ;
ReadOnly = .T., ;
TabStop = .F., ;
Top = 0, ;
Visible = .F., ;
Width = 432, ;
DisabledBackColor = RGB(255,255,255), ;
DisabledForeColor = RGB(0,0,0), ;
Name = "txtProgressBar"


ADD OBJECT cntpanel3 AS container WITH ;
Top = 4, ;
Left = 523, ;
Width = 21, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel3"


ADD OBJECT footer.cntpanel3.oleaviplayer AS olecontrol WITH ;
Top = 2, ;
Left = 2, ;
Height = 16, ;
Width = 16, ;
Name = "oleAviPlayer"


ADD OBJECT cntpanel4 AS container WITH ;
Top = 4, ;
Left = 547, ;
Width = 51, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel4"


ADD OBJECT footer.cntpanel4.label1 AS label WITH ;
AutoSize = .T., ;
FontName = "MS Sans Serif", ;
Caption = "Label1", ;
Height = 15, ;
Left = 4, ;
Top = 4, ;
Width = 34, ;
Name = "Label1"


ADD OBJECT cntpanel5 AS container WITH ;
Top = 4, ;
Left = 600, ;
Width = 55, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel5"


ADD OBJECT footer.cntpanel5.label1 AS label WITH ;
AutoSize = .T., ;
FontName = "MS Sans Serif", ;
Caption = "Label1", ;
Height = 15, ;
Left = 3, ;
Top = 4, ;
Width = 34, ;
Name = "Label1"


ADD OBJECT tmrtime AS timer WITH ;
Top = 0, ;
Left = 684, ;
Height = 23, ;
Width = 23, ;
Interval = 1000, ;
Name = "tmrTime"


PROCEDURE mcntlabel1
LPARAMETERS cFile, cLine1

WITH THIS
.cntPanel1.Image1.Picture = cFile
.cntPanel1.Label1.Caption = cLine1
ENDWITH
ENDPROC


PROCEDURE mcntlabel3
LPARAMETERS cFile, cAction

THIS.cntPanel3.oleAviPlayer.Open(cFile)
lcExpr = [THIS.cntPanel3.oleAviPlayer.] + cAction
&lcExpr
ENDPROC


PROCEDURE Resize
WITH THIS
.Height = 27
.Top = _SCREEN.Height - 27
.Width = _SCREEN.Width

WITH .cntPanel2
.Left = _SCREEN.Width - 338
.Width = 200
ENDW

WITH .cntPanel3
.Left = _SCREEN.Width - 136
ENDWITH

WITH .cntPanel4
.Left = _SCREEN.Width - 113
ENDWITH

WITH .cntPanel5
.Left = _SCREEN.Width - 60
ENDWITH

WITH .cntPanel1 && The one panel that resizes
.Left = 3
.Width = _SCREEN.Width - 343
ENDW
ENDW
ENDPROC


PROCEDURE Init
THIS.Resize()
THIS.mCntLabel1([],[This is a test, and an even bigger test])
THIS.mCntLabel2()
THIS.mCntLabel3([bitmaps\n3.avi],[Play])
ENDPROC


PROCEDURE Destroy
RELE oFooter
ENDPROC


PROCEDURE mcntlabel2
ENDPROC


PROCEDURE mcntlabel4
ENDPROC


PROCEDURE mcntlabel5
ENDPROC


PROCEDURE label1.MouseEnter
LPARAMETERS nButton, nShift, nXCoord, nYCoord
THIS.ToolTipText = THIS.Caption
ENDPROC


PROCEDURE label1.MouseEnter
LPARAMETERS nButton, nShift, nXCoord, nYCoord
THIS.ToolTipText = [The time is ] + THIS.Caption
ENDPROC


PROCEDURE label1.MouseEnter
LPARAMETERS nButton, nShift, nXCoord, nYCoord
THIS.ToolTipText = [The date is ] + THIS.Caption
ENDPROC


PROCEDURE tmrtime.Timer
THISFORM.cntPanel4.Label1.Caption = TIME()
ENDPROC


ENDDEFINE
*
*-- EndDefine: footer
**************************************************


The error comes at the first add object only-
ADD OBJECT footer.cntpanel1.image1 AS image WITH.

My QUESTION here is:
HOW TO TROUBLESHOOT THE ERROR. I WANT TO BE ABLE TO USE THE CODE LIKE THIS- (as it reduces codes)
'ADD OBJECT footer.cntpanel1.image1 AS image WITH'
Thank you
 
Code:
*************************************************
*-- Form: footer (c:\test\newfooter[b].scx[/b])
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 02/11/03 09:06:00 AM
*

This header suggests this is prg code generated from an SCX. The VFP class browser has an option to do this. But this is not meant to be executed that way. To get this running, you will need to redo a SCX form composed in the same way from the base components used here, too.

I assume Chris just used the generated PRG code to share the idea as code, as it's not possible to have a binary attachment in a FAQ, or was not possible way back at that time. In fact I don't see the possibility to upload an attachment today, too. Only normal threads and thread posts can have an attachment.

So this surely doesn't work for a beginner. This isn't fixable by slight modifications. Everytime something like adding a subobject of a subobject is done, such code fails to execute. Its intention is not to work, but to be stored as PRG represnetation of a visual class or in this case form (SCX).

Bye, Olaf.
 
'So this surely doesn't work for a beginner. This isn't fixable by slight modifications' Liked this statement most. What I wanted to convey along with my question, you perceived very nicely.
Thanks
 
Maybe the question you should have asked is "How do I create my own status bar?". That really isn't difficult.

To start with, are you aware that VFP has a built-in status bar? In fact, it has two such bars: a character-based bar and a graphical bar. The character-based bar is a hang-over from earlier versions and not much used. The graphical bar is more useful.

By default, this status bar displays the alias of the current table, its lock status, its record number and record count, and the state of the toggle keys (Num Lock etc). But you can change that behaviour, and display your own text as well.

If that doesn't meet your needs, there are other options. But I suggest that you experiment with the built-in graphical bar first as it is very easy to use. Check the Help for commands such as SET STATUS BAR, SET NOTIFY, the StatusBar and StatusBarText properties, and SET MESSAGE.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
There also was a recent thread about status bars:

thread184-1775275

and Chris wrote another FAQ:

faq184-6469

Beginner said:
I actually wanted to create a PROGRESSBAR
Well, there are other FAQs about that, too:

faq184-5535
faq184-216

And both things just require one single object. A label can display any text via setting its Caption, a Textbox could even automatically adjust itself to whatever you write to some property by using that as its ControSource, though you typically want to control what a status bar displays and then the label.Caption is as good as any other property and the whole ControlSource mechanism already is over the top of the normal status bar requirements. And you just put that labek object at the bottom of your form and have a status bar. There is no big magic about this.

The same applies to a progess bar. In the usual case it's some fixed width object (could be a container or shape) in which another object grows from 0 to 100%. You may also use a Windows progress bar, see (just by the way: the 3d transparent/translucient liquid look MS introduces in Vista was very much reduced to flat style in Win8/10, I don't know in which version of Windows you are, but however impressive the reinvention of the Vista Aero look was, the world rather connected it to a plastic look of tele tubbies. While flat style also is just todays trend and what's modern will surely look different within the next few years, the flat style gives everybody even with less grphical skills the possibility to create such a look and that helps to find a unified and clear look for a more wholesome UX.

But aside of the layout design it's really a good topic for a beginner using simple objects/controls and not going to a FAQ section or blog post to get something readymade. This is really a good lesson to take and do from scratch. If you can't imagine how to create such simple things, you should also think about whether programming really is for you.

Needing to do OCR or speech recognition or handwriting recognition or scan to images or many other more complex tasks, that would be a reaon I also would look out for a finished component. But you want something that resizes from width 0 to full width and you can't imagine how to do something like that on your own? I know the beginning always is hard, but how you size things is really easily discoverable with form designers, isn't it? And when you know the positioning and sizing of something influences its top,left,width, and height properties it's quite easy to imagine how to do that in code, isn't it?

Bye, Olaf.
 
@ Mike
I read and tested all the commands- SET STATUS BAR, SET NOTIFY, the StatusBar and StatusBarText properties, and SET MESSAGE.
Found them useful.

@ Olaf
I created the progress bar following the thread 'A Progress Bar or Thermometer Class by ramani'
Now I want to do two things-
1. Display percentage at the center of the progress bar.
Working on that...

 
Notice Ramanis code demos how to do a progress bar in many ways. As I already said it's not hard to do your own, you should try that, then you know what things are and how to extend is much easier than using someone else's code und using such nonvisual prg class definition code generated from visual classes is putting you into a dead end. It's much easier to modify and extend a visual class.

Bye, Olaf.
 
What I did can be summarized as under-
1. Written the class definitions in a program general_functions.prg.
2. There was slight change in the class definition ie. Instead of defining gsThermometer, gsTehermometerOLE and gsThermometer class as form I defined them as container.
3. Written a procedure Progressbar_genfun in general_functions.prg with parameters-
i. pnNo, ii. pnTop, iii. pnLeft, iv. pnWidth, v. pnHeight
So that If I called this procedure with pnNo. 1 or 2 or 3 along with top,left,width and height, I may refer to three different classes.
Using pnNo in docase endcase I conditionally stored in a variable cThermometer, the names of the class.
4. Using CreateObject command and variable cThermometer, I created an object oTherm in procedure Progressbar_genfun in general_functions.prg passing top,left,width and height parameters to the the class definitions.
5. Using Do While-
do while i<=100
oTherm.Progress1.value= i
i= i+1
inkey(0.001)
enddo
in the procedure Progressbar_genfun, I changed the value of progress1 object of oTherm
NOW THE PROBLEM IS THAT The object is not visible on the form from where i called the procedure-
Do Progressbar_genfun with 1,170,270,500,75
The Messagebox 'Done' comes when process completes but the progressbar is seen nowhere on the form I created using codes.

 
Got the solution:
Passed one more parameter Thsfrom
Do Progressbar_genfun with Thsform,1,170,270,500,75
and there in the progressbar_genfun procedure, instead of createobject used following command-
Thsform.addobject('oTherm','cThermometer',pnTop,pnLeft,pnWidth,pnHeight)

Thanks Olaf, Mike for the motivation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top