See Also: Understanding File Buffers and DDO Field Buffers, Add, Decrement, Increment, Subtract, SFormat, Append, Expression Syntax
To assign a value to a variable.
Move {expression} to {variable}
Move allows you to copy data from any constant, field, window, or variable into any other field, window, or variable. The arguments may be of different types and/or classes. All necessary conversions will be done automatically, except where a value is "impossible" for the variable type. Examples of "impossible" values are 12/31 for a Date, or A1587 for a Number. No combination of characters is impossible for a String type variable.
Where data is impossible for the type of variable, DataFlex will declare an Error 51 "Bad format of expression (operand)", or other error explicitly naming the incompatibility and continue with execution. "Impossible" values for Numbers and Dates result in a value of zero in variable.
Where data is too long for the declared length of variable, the moved data is simply truncated on the right, and execution continues without error. Where this condition is an undesired possibility, it should be trapped with appropriate commands. On the other hand, this function represents a valid and often convenient way of accomplishing truncation where it is desired.
Number nNum
String sString
Move "California" To sString
In this example, the String constant "California" is moved to string variable sString. If that variable were other than a string type variable, this command would report an error at runtime, because the value California cannot be a number.
String sActive
Move Vendor.Name To sActive
In this example, the value of Field name in Database table vendor is moved to string variable sActive.
Move 07/12/1999 To Sales.Order_date
In this example, the literal date 07/12/86 is moved to Field order_date in database table sales. If Field order_date were not of Type Date, this command would trigger an error.
Move (Sales.Ord_date + 30) To Sales.Due_date
In this example, the value of Field due_date in Database table sales, plus 30, is moved to Field due_date in the same table.
Initializing struct variable members:
In the example below, move is used to initialize members of the myBillingAddress struct variable.
Struct tUSAddress
String sFirstName
String sLastName
String sAddressLine1
String sAddressLine2
String sCity
String sState
Integer iZipCode
End_Struct
Procedure CreateBillingAddress
tUSAddress myBillingAddress
// initialize myBillingAddress
Move "John" to myBillingAddress.sFirstName
Move "Smith" to myBillingAddress.sLastName
Move "Data Access Worldwide" to myBillingAddress.sAddressLine1
Move "14000 SW 119 Ave" to myBillingAddress.sAddressLine2
Move "Miami" to myBillingAddress.sCity
Move "FL" to myBillingAddress.sState
Move "33186" to myBillingAddress.iZipCode
End_Procedure
Copying struct variable members:
Assume that the example below is a continuation of the sample above, using the same struct declaration for tUSAddress. Here, move is used to copy the value of myBillingAddress to myShippingAddress. Using move to copy struct variables uses a deep memberwise copy operation to copy each struct variable member value from the first struct variable to the second struct variable.
Procedure CreateShippingAddress tUSAddress myBillingAddress
tUSAddress myShippingAddress
Move myBillingAddress to myShippingAddress
End_Procedure
Re-initializing struct variable members:
There is a quick way to re-initialize array variables to their original (blank) values. Simply move an un-initialized array variable of the same type:
Struct tTest
Integer iTest
String sTest
End_Struct
Procedure Test
tTest localTest blankTest
// initialize localTest with values
Move 104 to localTest.iTest
Move "Fred" to localTest.sTest
// re-initialize localTest elements to their original (blank) values
Move blankTest to localTest
End_Procedure
The same can be done with struct properties:
Property tTest pMyTest
Procedure ReinitializepMyTest
tTest blankTest
Set pMyTest to blankTest
End_Procedure
Initializing array variable members:
In the example below, move is used to initialize members of the iValues array variable. You can also use FillArray to initialize array values.
Procedure Example
Integer[10] iValues
Integer i
For i From 0 to 9
Move (i+1) to iValues[i]
Loop
End_Procedure
Initializing array variable members:
In the example below, move is used to initialize members of the myFriends array variable, which is a dynamic array of tFriends structs.
Struct tFriends
String sName
String sPhoneNumber
End_Struct
Procedure Example
tFriends[] myFriends
Move "John" to myFriends[0].sName
Move "305-238-0012" to myFriends[0].sPhoneNumber
Move "Susie" to myFriends[1].sName
Move "305-555-1212" to myFriends[1].sPhoneNumber
End_Procedure
You can append values to the end of a dynamic array using Move and passing [-1] as the array indexer as an alternative to AppendArray.
Procedure Example
tFriends[] myFriends
tFriends friend
Move "John" to friend.sName
Move "305-238-0012" to friend.sPhoneNumber
Move friend to myFriends[-1]
Move "Susie" to friend.sName
Move "305-555-1212" to friend.sPhoneNumber
Move friend to myFriends[-1]
End_Procedure
Copying array variable members:
The example below move is used to copy the value of array variable sValues1 to sValues2. Using move to copy array variables uses a deep memberwise copy operation to copy each array variable member value from the first array variable to the second array variable. To copy a range of array elements to another array, rather than the whole array, use CopyArray.
Procedure Example
String[5] sValues1 sValues2
// some code to initialize sValues1
Move sValues1 to sValues2
End_Procedure
You can use the Move command to move an object access name to handle variable. The following example moves the object ID of object oMyObject to a handle variable:
Move oMyObject To hoMyObject
The command actually move the result of an object access expression to the handle variable. At runtime, the following samples are identical.
Move oMyObject To hoMyObject
Move (oMyObject(Self)) to hoMyObject
This value of the object is determined at runtime and uses the standard DataFlex object access evaluation process. This non-expression move syntax is supported to make it easier to read and write programs.
If you will be using an object name many times in the same program it is more efficient to move the object name to a handle variable and use the handle variable.
Procedue ShowAll
Handle hoMyList
String sValue
Integer iCount i
Move oMyList to hoMyList // this access method is only evaluated once!
Get Item_Count of hoMyList to iCount
For i from 0 to (iCount-1)
Get Value of hoMyList i to sValue
Send ProcessValue sValue
Loop
End_Procedure