Normal Topic Copy Form to Buffer  question (Read 1414 times)
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Copy Form to Buffer  question
Jul 22nd, 2006 at 6:08am
Print Post Print Post  
As part of a command button logic I am using these lines to create a copy of the current record:

Vcopy=@selectTreeitem("Search Update Menu!Edit Commands!Copy Form to Buffer (F11)") // runs ditto command from tree

VDupe=@selectTreeitem("Search Update Menu!Edit Commands!Paste Buffer to Form (Shift-F11)") // runs ditto command from tree

I set a number of variables before and then modify field elements after as needed. All was working great. I changed a number of elements to read only and all sorts of problems began. I realized my problem was caused by blank elements that I was calculating from. I have learned that Copy Form to Buffer feature does not copy elements that are read only.

I have 2 methods that work to overcome my problem. First method was to set additional variables prior to my Copy Form to Buffer command and then after Paste Buffer to Form command runs I calculate and fill my elements using the variables.

The second method I used was to temporarily set the element to readable using  readonly(elements,1) command prior to using the copy to buffer.

I would like to know if one method is better to use over the other? Is one easier on the computer or network? What would the pros use?

Thanks for any and all thoughts.
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Copy Form to Buffer  question
Reply #1 - Jul 22nd, 2006 at 1:42pm
Print Post Print Post  
Copy Form to Buffer does copy read-only LEs, because that is a read operation. But Paste Buffer to Form does not write to read-only LEs, because it is a user accessible command and that would allow the end user to violate the read-only status of the LE.

Neither using variables or changing the read-only status of the LE in programming will involve the network at all, both are completely done on the client side. I suspect that using variables will be faster, but that changing the the read-only status will produce "cleaner" and more obvious code.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Copy Form to Buffer  question
Reply #2 - Jul 22nd, 2006 at 3:24pm
Print Post Print Post  
Thanks Mark for the input!

The more I think about it I come to the conclusion that in the long run using variables can be troublesome for me. I originally decided to use the variable method because it seemed simpler for me to do. I understood what elements I needed to capture and were I needed to send the data after my copy from buffer. The big problem comes in when I decide to make another element read only at a later date, I will need to change the code every time a decision is made to set an element to read only.

I am thinking it would be best for me to make a method were I read all the elements on a form and then set them all temporarily to NOT read only. This way if I add elements later I will not need to go and add logic to deal with them separately.

I will try to make a Function that I can place in global code that reads all the elements and temporarily sets them so I can use this function  with other buttons on my form also.

Thanks again,

Robert
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Copy Form to Buffer  question
Reply #3 - Jul 22nd, 2006 at 4:36pm
Print Post Print Post  
Actually something as simple as this works.

Subroutine NotReadonly()


Var vElements as String
Var vCnt as Int
Var vLoop as Int
Var vName as String

    vElements = @StringArrayElementList() // Reads all my elements


   
     vCnt = @CountStringArray(vElements) // counts the anount of elements so my loop knows how many times to run
          vLoop = 0
 
         While vLoop < vCnt
       {
           vLoop = vLoop + 1
           vName = @AccessStringArray(vElements, vLoop)
           SetThisElement(vName)
           ReadOnly(ThisElement, 0) // sets element to Not read only
       }
     


End subroutine
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Copy Form to Buffer  question
Reply #4 - Jul 22nd, 2006 at 4:38pm
Print Post Print Post  
That sounds like a good approach. Remember to take note of which are read-only before you begin setting them all writable, so you can restore the correct LEs.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Copy Form to Buffer  question
Reply #5 - Jul 22nd, 2006 at 6:13pm
Print Post Print Post  
Bob,

Don't forget to use UnSetThisElement() somewhere. Wink

I was tooling around with your code a bit in a mass update, and it caused lots of my other code to fail to fuction as expected, because I'm using ThisElement in much of my code.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Copy Form to Buffer  question
Reply #6 - Jul 22nd, 2006 at 7:09pm
Print Post Print Post  
To help do exactly what you are doing, I just added two new subroutines to SBasic for Sesame 2.0

PushAttribute(var LE as string, attribute_id as int)

and

PopAttribute(var LE as string, attribute_id as int)

These let you save and restore any of the forty-some attributes on individual LEs.

Code
Select All
#include "sbasic_include.sbas"

// Save the background color whatever it is
PushAttribute(Company, ATTR_ID_BACK_RGB_COLOR)

// Set the background color to Red
RGBColor(Company, -1, -1, -1, 128, 0, 0)

// Let's see it!
ForceRedraw()

// Go do whatever Red LEs do - in this case: Twiddle Thumbs
Loiter(10000)

// Restore whatever the background color was before we messed with it
PopAttribute(Company, ATTR_ID_BACK_RGB_COLOR)
 



Of course you can push any attribute mulitply (up to 128 for each attribute in each LE) and you can then "pop" them off the stack in reverse order, making the push/pop sequence work much like a multi-level "undo".
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Copy Form to Buffer  question
Reply #7 - Jul 22nd, 2006 at 7:58pm
Print Post Print Post  
Remember there are two visible ReadOnly states now, "1" and "2", not just "1"

In the loop that Sets ReadOnly, you should get ReadOnly status and if it is not "0", then write the elementname and its "1" or "2" status to a string array.  Then after you Ditto the Record, loop through the elements in that string array to set ReadOnly status back again.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Copy Form to Buffer  question
Reply #8 - Jul 22nd, 2006 at 9:29pm
Print Post Print Post  
Thanks for all the great input!

I understand about resetting the elements back to the original readonly state, but it seems that as soon as the new record is created it automatically is going back to the original settings.

Is this not the norm?

This is the code on my button and it works and the elements automatically are returning to the original state. (I will however work on my subroutine to only change the elements that need it and then change them back)

// create fulfillment from active record Button

Var Vcopy as INT
Var VDupe as INT
var vTrakerCount as string
var vNewTrakerid as string
var vtrakercut as string
var vtrakercut1 as string
var vtrakercut2 as string
Var Vsave as INT
var vtrakercutHold as string
var vleftid as string
var nc as int
var vneeded as string
var vnextneeded as string
var vnextproc as string



     


If Not @IsBlank(Itm_PatientId) then

{
     
     If @Askuser("You are about to add a new Record for the product "+Itm_productName,"It will be for "+Itm_PatientFirst + " "+ Itm_PatientLast,"Do you want to continue")
   {

     NotReadonly() // temporarily sets all elements read only so they can be written to duped record
     vnextneeded = Itm_nextNEEDED
     vnextproc = Itm_nextprocess

     Vcopy=@selectTreeitem("Search Update Menu!Edit Commands!Copy Form to Buffer (F11)") // runs ditto command from tree
     
     Vneeded = Itm_NextNeeded                  // this takes next needed date for use as needed date on fullfilled order creation
     Itm_ProcStat = "F"                        // an  F is placed in the proc status box that signifies A followup fullfilment record was generated
     nc = @FormNewRecord("MedsTrak")

     VDupe=@selectTreeitem("Search Update Menu!Edit Commands!Paste Buffer to Form (Shift-F11)") // runs ditto command from tree
     

     Vleftid = @left(trakerID,1)
     Vtrakercount = @len(trakerID)                                          // counts characters of traking field
                       

           If VleftId <> "f" then      
     

                 {      
                 
                 vNewTrakerid = "F102"+trakerid                  // if trakerid does not start with F then new id is trakerId +"F002"
                 Trakerid = VnewtrakerId                        // sets trakerId to new number
                 Itm_typ = "Patient Fulfillment"                  // Sets Itm_type to patient fulfillment

                 Itm_nextprocess =  @todate(vnextproc)+ 30            // increases next process by 30 days
                 Itm_nextNEEDED = @todate(vnextneeded)+ 30            // increases next needed by 30 days
                 Itm_DateEntered = @date                        // changes date entered to todays date
                 Clear(Itm_billedDate,Itm_billedAmt,Itm_paidDate,Itm_paidAmt,Itm_PaidCCtransChkNu
mber)
                 Itm_ProcStat = "X"                        // an x is placed in the proc status box that signifies given/shipped to patient
                 Itm_billon = (Itm_billon + @tonumber(Itm_physgrpterms)) // this takes the
                 Itm_needed = @todate(Vneeded)                             // slugs itm_nextneeded into Itm_needed

                 FormCommit("")                              // Save the current record

                 }
           
                 else if VleftId = "f" then


                 {

                 vtrakercuthold = @mid(trakerid,5,25)             //cut and stores the trakerid after the 4th character(Fxxx)
                 vtrakercut1 = @left(trakerid,4)                       //cut and stores the first 4 characters(Fxxx) of trakerid
                 vtrakercut = @mid(trakerid,2,3)                  //cut and store the number portion after F for 3digits
                 vtrakercut2 = @tonumber(vtrakercut) + 1          //increases f section of trakerid by 1
                 vNewTrakerid = "F"+ vtrakercut2 + vtrakercuthold //
                 Trakerid = VnewtrakerId                         // writes new trakerid to trakerif field
                 Itm_typ = "Patient Fulfillment"                   // Sets Itm_type to patient fulfillment
                 Itm_nextprocess =  @todate(vnextproc)+ 30            // increases next process by 30 days
                 Itm_nextNEEDED = @todate(vnextneeded)+ 30            // increases next needed by 30 days
           
                 Itm_DateEntered = @date                        // changes date entered to todays date
                 Clear(Itm_billedDate,Itm_billedAmt,Itm_paidDate,Itm_paidAmt,Itm_PaidCCtransChkNu
mber)
                 Itm_ProcStat = "X"                          // an x is placed in the proc status box that signifies given/shipped to patient
                 Itm_billon = (Itm_billon + @tonumber(Itm_physgrpterms)) // this takes the
                 Itm_needed = @todate(Vneeded)                             // slugs itm_nextneeded into Itm_needed
                 
                 FormCommit("")                                                      // Save the current record

                 }

}            
}      
else

{
@msgbox("","Patient Data must be available to Perform this function","")
}



  

Team – Together Everyone Achieves More
Back to top
 
IP Logged