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!

Adding a Label to a Pageframe 3

Status
Not open for further replies.

David Higgs

Programmer
May 6, 2012
390
0
16
GB
Over the years I’ve been developing an application for my Amateur Radio activities. The project, although it meets my current requirements has become rather cumbersome with code placed here there and everywhere.

As my thoughts keep returning to OOP, should I / shouldn’t I. I thought I'd take another look.

In the following code I've setup a Main Page with a PageFrame.

What I am trying to do is add a label to each PageFrame, lblTest1 to Page1 , lblTest2 to Page2 etc but can’t seem to find where to put the code or find the correct syntax.

Code:
CLEAR 
	
Local oForm

oForm = CREATEOBJECT("clsMainForm")
oForm.SHOW()

Read EVENTS

CLOSE ALL

CLEAR ALL 

RETURN 
		
*                    
*	Define Main Form 
*                    

Define CLASS clsMainForm AS FORM

	WindowState = 0
	WindowType = 0

	Caption = "Amateur Radio Logging Program"
	Height = 978
	Width = 1680
	Themes = .F.

 Add OBJECT cmdExit AS COMMANDBUTTON WITH;
  Caption = "Exit Program", FontSize = 24, FontBold = .T., Backcolor = RGB(192,192,192), ForeColor = RGB(255,0,0), ;
  LEFT = 1390, Top = 800, Width = 300, Height = 60, Alignment = 2

*                
*	Exit Program 
*                

Procedure cmdExit.CLICK
 
thisform.Release
  
ENDPROC 
      
*                         
*	Add Pageframe to Form 
*                         
    
  Add OBJECT pfMain AS clsMainPageFrame WITH;
    PAGECOUNT = 6, ;
    LEFT = 0, ;
    TOP = 0, ;
    WIDTH = THIS.WIDTH - 10, ;
    HEIGHT = THIS.HEIGHT - 300

  ADD OBJECT lblTest1 as Label WITH Left = 0, Top = 40, width = 1668, Height = 46, Alignment = 2, ;
	Backcolor = RGB(255,255,128), Caption = "Page 1", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

  ADD OBJECT lblTest2 as Label WITH Left = 0, Top = 140, width = 1668, Height = 46, Alignment = 2, ;
	Backcolor = RGB(255,255,128), Caption = "Page 2", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

  ADD OBJECT lblTest3 as Label WITH Left = 0, Top = 240, width = 1668, Height = 46, Alignment = 2, ;
	Backcolor = RGB(255,255,128), Caption = "Page 3", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

  ADD OBJECT lblTest4 as Label WITH Left = 0, Top = 340, width = 1668, Height = 46, Alignment = 2, ;
	Backcolor = RGB(255,255,128), Caption = "Page 4", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

  ADD OBJECT lblTest5 as Label WITH Left = 0, Top = 440, width = 1668, Height = 46, Alignment = 2, ;
	Backcolor = RGB(255,255,128), Caption = "Page 5", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

  ADD OBJECT lblTest6 as Label WITH Left = 0, Top = 540, width = 1668, Height = 46, Alignment = 2, ;
	Backcolor = RGB(255,255,128), Caption = "Page 6", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

*  ADD OBJECT pfHeader as Container WITH;
   Left = 0, Top = 100, width = 1668, Height = 46, Backcolor = RGB(255,255,128)
  
Enddefine

*                         
*	Define Main Pageframe 
*                         
		
Define CLASS clsMainPageFrame AS PAGEFRAME

  PageCount = 6

  page1.Caption  = "WAB Awards"
  page1.FontBold = .T.
  page1.FontName = "Arial"
  page1.FontSize = 14
  page1.ForeColor = RGB(0,0,255)

  page2.Caption  = "Logbook"
  page2.FontBold = .T.
  page2.fontname = "Arial"
  page2.fontsize = 14 
  page2.ForeColor = RGB(0,0,0)
     
  page3.Caption  = "WAB Net" 
  page3.FontBold = .T.
  page3.fontname = "Arial"
  page3.fontsize = 14
  page3.ForeColor = RGB(0,0,255)
    
  page4.Caption  = "Small Squares"
  page4.FontBold = .T.
  page4.fontname = "Arial"
  page4.fontsize = 14
  page4.ForeColor = RGB(128,64,64)
   
  page5.Caption  = "Large Squares"
  page5.FontBold = .T.
  page5.fontname = "Arial"
  page5.fontsize = 14
  page5.ForeColor = RGB(0,128,0)
    
  page6.Caption = "WAB Book Numbers" 
  page6.FontBold = .T.  
  page6.fontname = "Arial"
  page6.fontsize = 14
  page6.ForeColor = RGB(255,128,0)

ENDDEFINE





Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
Hi David,

Please have a look at your modified code

Code:
CLEAR 
	
oForm = CREATEOBJECT("clsMainForm")
oForm.Visible = .T.
oForm.SHOW()

Read EVENTS

CLOSE ALL

CLEAR ALL 

RETURN 
		
*                    
*	Define Main Form 
*                    

Define CLASS clsMainForm AS FORM

	WindowState = 0
	WindowType = 0

	Caption = "Amateur Radio Logging Program"
	Height = 978
	Width = 1680
	Themes = .F.

 Add OBJECT cmdExit AS COMMANDBUTTON WITH;
  Caption = "Exit Program", FontSize = 24, FontBold = .T., Backcolor = RGB(192,192,192), ForeColor = RGB(255,0,0), ;
  LEFT = 1390, Top = 800, Width = 300, Height = 60, Alignment = 2

*                
*	Exit Program 
*                

	Procedure cmdExit.CLICK
	 
	CLEAR Events
	  
	ENDPROC 
      
*                         
*	Add Pageframe to Form 
*                         
    
  Add OBJECT pfMain AS clsMainPageFrame WITH;
    PAGECOUNT = 6, ;
    LEFT = 0, ;
    TOP = 0, ;
    WIDTH = THIS.WIDTH - 10, ;
    HEIGHT = THIS.HEIGHT - 300
[highlight #FCE94F]    
	PROCEDURE pfMain.Init()
		LOCAL loPage as Object
			
		FOR i = 1 TO This.pageCount
			loPage = This.Pages(i)
			loPage.Addobject("lblPage", "lblLabel")
			loPage.lblPage.Caption = "This is label on page" + " " + ALLTRIM(STR(i))

		ENDFOR 
	ENDPROC[/highlight] 

*!*	  ADD OBJECT lblTest1 as Label WITH Left = 0, Top = 40, width = 1668, Height = 46, Alignment = 2, ;
*!*		Backcolor = RGB(255,255,128), Caption = "Page 1", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

*!*	  ADD OBJECT lblTest2 as Label WITH Left = 0, Top = 140, width = 1668, Height = 46, Alignment = 2, ;
*!*		Backcolor = RGB(255,255,128), Caption = "Page 2", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

*!*	  ADD OBJECT lblTest3 as Label WITH Left = 0, Top = 240, width = 1668, Height = 46, Alignment = 2, ;
*!*		Backcolor = RGB(255,255,128), Caption = "Page 3", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

*!*	  ADD OBJECT lblTest4 as Label WITH Left = 0, Top = 340, width = 1668, Height = 46, Alignment = 2, ;
*!*		Backcolor = RGB(255,255,128), Caption = "Page 4", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

*!*	  ADD OBJECT lblTest5 as Label WITH Left = 0, Top = 440, width = 1668, Height = 46, Alignment = 2, ;
*!*		Backcolor = RGB(255,255,128), Caption = "Page 5", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

*!*	  ADD OBJECT lblTest6 as Label WITH Left = 0, Top = 540, width = 1668, Height = 46, Alignment = 2, ;
*!*		Backcolor = RGB(255,255,128), Caption = "Page 6", FontSize = 24, FontName = "Verdana", BorderStyle = 1 

*  ADD OBJECT pfHeader as Container WITH;
   Left = 0, Top = 100, width = 1668, Height = 46, Backcolor = RGB(255,255,128)
  
Enddefine

*                         
*	Define Main Pageframe 
*                         
		
Define CLASS clsMainPageFrame AS PAGEFRAME

  PageCount = 6

  page1.Caption  = "WAB Awards"
  page1.FontBold = .T.
  page1.FontName = "Arial"
  page1.FontSize = 14
  page1.ForeColor = RGB(0,0,255)

  page2.Caption  = "Logbook"
  page2.FontBold = .T.
  page2.fontname = "Arial"
  page2.fontsize = 14 
  page2.ForeColor = RGB(0,0,0)
     
  page3.Caption  = "WAB Net" 
  page3.FontBold = .T.
  page3.fontname = "Arial"
  page3.fontsize = 14
  page3.ForeColor = RGB(0,0,255)
    
  page4.Caption  = "Small Squares"
  page4.FontBold = .T.
  page4.fontname = "Arial"
  page4.fontsize = 14
  page4.ForeColor = RGB(128,64,64)
   
  page5.Caption  = "Large Squares"
  page5.FontBold = .T.
  page5.fontname = "Arial"
  page5.fontsize = 14
  page5.ForeColor = RGB(0,128,0)
    
  page6.Caption = "WAB Book Numbers" 
  page6.FontBold = .T.  
  page6.fontname = "Arial"
  page6.fontsize = 14
  page6.ForeColor = RGB(255,128,0)

ENDDEFINE 

**********

[highlight #FCE94F]DEFINE CLASS lblLabel as Label
	Visible = .T.
	Left = 12
	Top = 36
	Height = 36
	Backcolor = RGB(255,255,128)
	Caption = "Label"
	Autosize = .T.
ENDDEFINE 		[/highlight]
*********

hth

MarK
 
Hello Mark,

mjcmkrsr said:
Please have a look at your modified code

Thank you very much for your help with my code, it is much appreciated. It was some of your previous posts with added code that as encouraged me to take another look at OOP. A steep learning curve which I am sure will be worth the effort.





Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
Hi DAvid,

...

after some minor tweaks

Code:
oForm = CREATEOBJECT("clsMainForm")
oForm.Visible = .T.
oForm.SHOW()

Read EVENTS

CLOSE ALL

CLEAR ALL 

RETURN 
		
*!*	*	Define Main Form 

Define CLASS clsMainForm AS FORM

	WindowState = 2
	WindowType = 0

	Caption = "Amateur Radio Logging Program"
	Left = 12
	Top = 12
	Height = _screen.Height - 24 
	Width = _screen.Width - 24 && 1680
	Themes = .F.

	Add OBJECT cmdExit AS COMMANDBUTTON WITH;
		  Caption = "Exit Program", ;
		  FontSize = 24, ;
		  FontBold = .T., ;
		  Backcolor = RGB(192,192,192), ;
		  ForeColor = RGB(255,0,0), ;
		  LEFT = ThisForm.Width - (240 + 12), ;
		  Top = ThisForm.Height - (60 + 24), ;
		  Width = 240, ;
		  Height = 60, ;
		  Alignment = 2
             
*!*	*	Add Pageframe to Form 
	ADD OBJECT pfMain AS PageFrame WITH;
	    PAGECOUNT = 6, ;
	    LEFT = 12, ;
    	TOP = 12, ;
	    WIDTH = THISFORM.WIDTH - 24, ;
    	HEIGHT = THISFORM.HEIGHT - 300
    
		PROCEDURE pfMain.Init()
			LOCAL loPage as Object
				
			FOR i = 1 TO This.pageCount
				loPage = This.Pages(i)
				loPage.Addobject("lblPage", "lblLabel")
				loPage.Caption = ICASE(i = 1, "WAB Awards", i = 2, "Logbook", i = 3, "WAB Net", i = 4, "Small Squares", ;
									i = 5, "Large Squares","WAB Book Numbers" )
				loPage.FontBold = .T.
				loPage.FontName = "Arial"
				loPage.FontSize = 18
				loPage.Forecolor = ICASE(i = 1, RGB(0,0,255), i = 2, RGB(0,0,0), i = 3, RGB(0,0,255), ;
									i = 4, RGB(128,64,64), i = 5, RGB(0,128,0), RGB(255,128,0))

				loPage.lblPage.Caption = "This is label on page" + " " + ALLTRIM(STR(i))

			ENDFOR 
		ENDPROC 

	PROCEDURE cmdExit.CLICK
		CLEAR Events
	ENDPROC 
	
	PROCEDURE Destroy()
		This.cmdExit.Click()
	ENDPROC 
      
ENDDEFINE

**********

DEFINE CLASS lblLabel as Label
	Visible = .T.
	Left = 12
	Top = 36
	Height = 36
	FontSize = 24
	FontName = "Verdana"
	BorderStyle = 1 
	Backcolor = RGB(255,255,128)

	Caption = "Label"
	Autosize = .T.
ENDDEFINE 		

*********

hth

MarK
 
Hello Mark,

Thank you for the updated code which has addressed a couple of issues I was having in closing the application, repetition of code and also given me some more ideas for the next stage. I will study the code in further detail.

Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
I'll strongly encourage you to NOT create forms with code unless you have some very special needs. Use the Form Designer and just drop the controls where you want them.

Tamar
 
Tamar, Thank you for your advice.

Although my Amateur Radio Logging application meets my current requirements, it has become rather cumbersome with code placed here there and everywhere. I'm looking to further expand the application, hence my reason for looking for alternatives.

I'll take another look to see if I can tidy things up on my application before adding other modules.




Regards,

David

Recreational Developer and End User of VFP for my personal use in 'Amateur Radio' and 'British Railways' related Applications.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top