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

Simple substitute for @ say ?

Status
Not open for further replies.

SYN

Programmer
Nov 2, 2000
45
NL
Hi,

I'm wondering what in vfp the substitute is for the @ say command. I've changed from fox2.5 to vfp. I've tried to use the label option but this isn't very dynamic at all (or I'm doing something wrong.) Any suggestions or example prg?

 
I'm creating a form. I want to place a label dynamically. Just like the @ say command in a window. I'm not familiar with forms. I'm used to develop in fox2.5.
 
Why wouldn't use the Visual part of Visual FoxPro. Just use the file->new Form. And use the Control Toolbar, and drag a lable on the your form...
Or you could code the whole thing but it's not very visual.
Code:
DEFINE CLASS myform AS form
	Caption = "Form1"
	Name = "Form1"
ADD OBJECT label1 AS label WITH ;
		Caption = "myLabel", ;
		Height = 17, ;
		Left = 84, ;
		Top = 60, ;
		Width = 84, ;
		Name = "Label1"
ENDDEFINE
 
Ok, but I think this is very static. I want to do something like this:

DEFINE CLASS myform AS form
Caption = "Form1"
Name = "Form1"
DO ADD_OJECTS WITH 17,10, "example 1"
ENDDEFINE

IF USER_IS_DOING_THIS
DO ADD_OBJECTS WITH 17,40, "example 2"
ELSE
DO ADD_OBJECTS WITH 17,40, "example 3"
ENDIF

PROCEDURE ADD_OBJECTS
*********************
PARAMETER P_LEFT, T_TOP, P_TXT

ADD OBJECT label1 AS label WITH ;
Caption = P_TXT, ;
Height = 17, ;
Left = P_LEFT, ;
Top = P_TOP, ;
Width = 84, ;
Name = P_TXT

Do you know is something like this is possible?
 
SYN

You could do it Visually, by putting a condition on the visible property of the label.
 
mgagnon,

the visible property is possible but I want to make standard procedures and so I can't define labels when creating a form. For example:

=MAKE_NEW_FORM("NAMEFORM")
=ADD_LABEL(NAMEFORM,ROW,COLUM,NAME)
=ADD_CHECKBOX(NAMEFORM, ROW,COLUM,NAME)

procedure make_new_form
***********************
parameter p_name

p_name = createobject("myform")

etc etc

Do you know how to make the procedure add_label so that it will add labels?
 
Sure, you can do things this way. It does get into more maintenance in the long run, though our company did a similar thing to accomplish the initial conversion from FP Dos to VFP where all our forms had been dynamically built.

=ADD_LABEL(NAMEFORM,ROW,COLUM,NAME)

(Let me emphasize that we don't create new code with these methods; they were just for getting (lot's of!) old code running in VFP forms right away)

Could be:
Code:
********************************************************
********    Windows Routines
PROCEDURE AtSay
LPARAMETER pnRow, pnCol, pcText, pcFormat, pcFont, pnSize, pcName
LOCAL lcOFont,lnOSize, lcAlign, lnEndX, lnWidth, lcFormat
LOCAL llOBold, llOItalic, llOUnderline, llOStrike, loForm, llOForeColor, llODrawMode
* pcFormat can contain the normal format characters:
*           B=Bold, I=Italic, U=Underline, S=Strikeout
*          and additional Alignment characters:
*           L=Left, R=Right, C=Center, O=Opaque  (transparent is default)
*           D=Disabled
  lcFormat = upper( iif( VarType(pcFormat)='C', pcFormat, '' ) )
  do case
    case 'L' $ lcFormat
      lcAlign = 'L'
    case 'R' $ lcFormat
      lcAlign = 'R'
    case 'C' $ lcFormat
      lcAlign = 'C'
    other
      lcAlign = 'L'
  endcase
  if Type(wOutput())='O'
    loForm = Eval( wOutput() )
  else
    loForm = _SCREEN.ActiveForm
  endif
*v10.00   if Type('loForm.PageFrame1.Page1')='O' 
*v10.00     if loForm.PageFrame1.ActivePage = 0
*v10.00       loForm.PageFrame1.ActivePage = 1
*v10.00     endif
*v10.00     loCont = loForm.PageFrame1.Page1
*v10.00   else
    loCont = loForm
*v10.00   endif
  WITH loCont
    if VarType(pcName)='C'
      lcName = pcName
      if Type('.'+lcName)='O'
        .RemoveObject(lcName)
      endif
    else
      lcName = 'lbl'+sys(2015)
    endif
    .AddObject(lcName,'Label')
    loLbl = Eval('.'+lcName)

    lnX       = loForm.TextWidth( Space(pnCol)  )
    loLbl.Top            = -100
    loLbl.Visible        = .T.
    loLbl.Width          = 0
    loLbl.Caption        = pcText
    loLbl.AutoSize       = .T.
    loLbl.BackColor      = RGB(0,0,192) && 192,192,192)

    
    loLbl.FontName       = iif(VarType(pcFont)='C',pcFont,'Arial'  )
    loLbl.FontSize       = iif(VarType(pnSize)='N',pnSize,loForm.FontSize)
    
    lnWidth   = loForm.TextWidth( pcText        )
    lnNewWidth   = FontMetric( 6, loLbl.FontName, loLbl.FontSize, ChrTran(lcFormat,'OLRC','') ) * ;
                    TxtWidth( pcText, loLbl.FontName, loLbl.FontSize, ChrTran(lcFormat,'OLRC','') ) 
                    
    loLbl.BackStyle      = iif( 'O'$lcFormat,1,0) && Opaque
    do case
      case lcAlign='L'
        loLbl.Left = lnX
      case lcAlign='R'
        loLbl.Left = lnX + lnWidth - lnNewWidth
      case lcAlign='C'
        loLbl.Left = lnX - ( lnNewWidth / 2 )
    endcase
    loLbl.Enabled        = NOT ('D' $ lcFormat)
    loLbl.FontBold       = 'B' $ lcFormat
    loLbl.FontItalic     = 'I' $ lcFormat
    loLbl.FontUnderline  = 'U' $ lcFormat
    loLbl.FontStrikethru = 'S' $ lcFormat
    loLbl.BorderStyle    = 0 && 1
    
    loLbl.AutoSize       = .F.
    loLbl.Height         = loLbl.Height - 2
    
    loLbl.Top            = loForm.TextHeight( ' ' )*pnRow 
  ENDWITH
ENDPROC

procedure PermText
parameter cLabelName, nTop, nLeft, cText, cFont, nSize, nColor
private lcLabel
  
  if type( &quot;_Screen.&quot;+cLabelName ) <> &quot;O&quot;
    _screen.AddObject( cLabelName,   'Label' ) && 'AutoResizeLabel' )
  endif
  lcLabel = &quot;_Screen.&quot;+cLabelName
  with &lcLabel
    .BackStyle  = 0 && Transparent = 0
    .AutoSize   = .T.
*    .height     = hig
*    .width      = _screen.width
    .FontName   = cFont
    .FontSize   = nSize
    .FontItalic = .t.
    .ForeColor  = nColor
    .Top        = int( nTop )
    .Left       = int( nLeft )
*v7.13w     .atOffset = _screen.Height - .Top   && v7.13w  wgcs
*v7.13w     .alOffset = _screen.Width  - .Left  && v7.13w  wgcs
    .Caption    = cText
    .Visible    = .t.
  endwith
return

** @ -srows()/6,0 say &quot;c:\computer\images\BB_BB.bmp&quot; BITMAP size sRows()*2, sCols() ISOMETRIC
procedure PermImage
parameter cLabelName, cFileName
private lcLabel
  
  if type( &quot;_Screen.&quot;+cLabelName ) <> &quot;O&quot;
    _screen.AddObject( cLabelName,   'image' )
  endif
  lcLabel = &quot;_Screen.&quot;+cLabelName
  with &lcLabel
    .BackStyle  = 1 && 1=Opaque;  Transparent = 0
    .height     = _screen.height*2
    .width      = _screen.width
    .Top        = 0 - int( _screen.height / 3 )
    .Left       = 0
    .Stretch    = 1  && Isometric
    .Picture    = cFileName
    .Visible    = .t.
  endwith
return
 
That's what I was looking for. Thanks. Can you expain what you mean by

loForm = _SCREEN.ActiveForm

The property is missing isn't it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top