Q(uick)BASIC Statement: RSET
Quick View
RSET
A string processing statement that moves data from memory to a random-access file buffer (in preparation for a PUT statement) or right-justifies the value of a string in a string variable
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- LSET stringvariable$=stringexpression$
- RSET stringvariable$=stringexpression$
- LSET recordvariable1=recordvariable2
Description/Parameter(s)
stringvariable$ | Any string variable or a random-access file field defined in a FIELD statement. |
stringexpression$ | For LSET, the left-justified version of stringvariable$. For RSET, the right-justified version of stringvariable$. |
recordvariable1 | Record variables of any user-defined data type. |
recordvariable2 | Use LSET to assign a record variable of one data type to a different user-defined data type. |
Example
OPEN "FILEDAT.DAT" FOR RANDOM AS #1 LEN = 10
FIELD #1, 5 AS Ls1$, 5 AS Rs1$
LSET Ls1$ = "LSET"
RSET Rs1$ = "RSET"
PUT #1, 1
CLOSE #1
OPEN "FILEDAT.DAT" FOR RANDOM AS #1 LEN = 10
FIELD #1, 5 AS Ls2$, 5 AS Rs2$
GET #1, 1
PRINT "*" + Ls2$ + "*", "*" + Rs2$ + "*"
CLOSE #1
See also:
Syntax
- RSET stringvariable=stringexpression
Description/Parameter(s)
The stringvariable is usually a random-access file field defined in a FIELD statement, although it can be any string variable. The stringexpression is the value assigned to the variable.
- If stringexpression requires fewer bytes than were defined for stringvariable in the FIELD statement, the RSET statement right-justifies the string in the field (LSET left-justifies the string). Spaces are used to pad the extra positions.
- If the string is too long for the field, both LSET and RSET truncate characters from the right. Numeric values must be converted to strings before they are justified with the RSET or LSET statements.
The RSET statement can be used with string variables unrelated to FIELD statements. When used with a fixed-length string variable, the value is right-justified and left-padded with blanks.
When RSET is used with a variable-length string, the string is treated as a fixed field. The length of the field is the length of the value the variable had before the RSET statement.
Example
This example shows the effects of using RSET to assign values to fixed- and variable-length strings.
DIM TmpStr2 AS STRING * 10
CLS ' Clear screen
PRINT " 1 2 3"
PRINT "123456789012345678901234567890"
' Use RSET on null variable-length string of length.
' Nothing prints because TmpStr$ is a zero-length field.
TmpStr$ = ""
RSET TmpStr$ = "Another"
PRINT TmpStr$
' Use RSET on variable-length string with a value.
TmpStr$ = SPACE$(20)
RSET TmpStr$ = "Another"
PRINT TmpStr$
' Use RSET on fixed-length string of length 10.
RSET TmpStr2 = "Another"
PRINT TmpStr2
Sample Output:
1 2 3 123456789012345678901234567890 Another AnotherSyntax
- RSET stringvariable = stringexpression
Description/Parameter(s)
stringvariable | A random-access file field defined in a FIELD statement, or any string variable. |
stringexpression | The value that is assigned to stringvariable and is right-justified. |
- The argument stringvariable usually is a random-access file field defined in a FIELD statement. The argument stringexpression is the value assigned to the variable.
- If stringexpression requires fewer bytes than were defined for stringvariable in the FIELD statement, the RSET statement right- justifies the string in the field (LSET left-justifies the string). Spaces are used to pad the extra positions.
- If the string is too long for the field, both LSET and RSET truncate characters from the right. Numeric values must be converted to strings before they are justified with the RSET or LSET statements.
- The RSET statement can be used with string variables unrelated to FIELD statements. When used with a fixed-length string variable, the value is right-justified and left-padded with blanks.
- When RSET is used with a variable-length string, the string is treated as a fixed field. The length of the field is the length of the value the variable had before the RSET statement.
Example
This example uses the LSET and RSET statements to assign values to fixed- and variable-length strings.
DIM TmpStr2 AS STRING * 25
CLS 'Clear screen.
'Use RSET on variable-length string with a value.
TmpStr$ = SPACE$(40)
PRINT "Here are two strings that have been right and left "
PRINT "justified in a 40-character variable-length string."
PRINT
RSET TmpStr$ = "Right-|"
PRINT TmpStr$
LSET TmpStr$ = "|-Left"
PRINT TmpStr$
PRINT "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
PRINT "12345678901234567890123456789012345678901234567890"
PRINT " 1 2 3 4 5"
'Use RSET on fixed-length string of length 25.
PRINT
PRINT
PRINT "Here are two strings that have been right and left"
PRINT "justified in a 25-character fixed-length string."
PRINT
RSET TmpStr2 = "Right-|"
PRINT TmpStr2
LSET TmpStr2$ = "|-Left"
PRINT TmpStr2$
PRINT "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
PRINT "12345678901234567890123456789012345678901234567890"
PRINT " 1 2 3 4 5"