home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / COREL6 / SCRIPTS / BASIC.CSC < prev    next >
Encoding:
Text File  |  1995-08-12  |  3.0 KB  |  129 lines

  1. REM This script demonstrates some basic functionality
  2. REM Basic.csc 19 MAY, 1995
  3.  
  4.  
  5. DECLARE SUB setvars(strin$)                       'subroutine declaration. Sub routine sets the value of a global variable
  6. DECLARE FUNCTION settovalue(z1 AS INTEGER) AS INTEGER             'FUNCTION declaration the FUNCTION sets the variable
  7.  
  8.  
  9. '=====================================================
  10. ' Variable declaration using the DIM statement,
  11. ' the %, $, & ... suffix or with implicit declarations
  12.  
  13.     DIM arr(5) AS STRING    'array of STRINGs (5 elements)
  14.     DIM a(10) AS STRING
  15.     DIM b$
  16.     c%=1
  17.     d="Hello"        'STRING set to Hello
  18.  
  19.  
  20. ' We also have constants
  21.  
  22.     CONST e=" 'e' is a constant STRING"        'STRING constant
  23.  
  24.  
  25.  
  26.  
  27. '=====================================================
  28. ' Control Statements
  29. '=====================================================
  30.  
  31.  
  32. '=====================================================
  33. ' Gotos and labels
  34.  
  35.     GOTO mylabel
  36.  
  37. elsewhere:            'label FOR goto statement
  38.     GOTO last        'note: Never used
  39.  
  40. mylabel:
  41.  
  42. '=====================================================
  43. ' While loop example
  44.  
  45.     WHILE a1%<3        'count up TO 2
  46.         MESSAGE "This is Fun!"
  47.         a1%=a1%+1
  48.     WEND            'end while
  49.  
  50.     MESSAGE "This is no fun anymore."
  51.         
  52.     
  53. '=====================================================
  54. ' Do loop example
  55.  
  56.     a(1) = "COREL "
  57.     a(2) = "SCRIPT "    
  58.     a(3) = "Macro Language"
  59.     a(4) = "END"
  60.  
  61.     c=1
  62.     b=""
  63.     DO             'Assembles a string (b= "COREL SCRIPT Macro Language")
  64.         b = b + a(c)
  65.         c = c + 1
  66.     LOOP UNTIL c=4      'end do loop
  67.  
  68. '=====================================================
  69. ' if and for examples
  70.  
  71.     IF c<>1 THEN
  72.         ' we had enough !
  73.         MESSAGE    "This is inside an if statement"
  74.     ELSE
  75.         ' We need another loop example
  76.         FOR c=1 TO 3
  77.             MESSAGE str(c)
  78.         NEXT c
  79.     END IF
  80.  
  81.  
  82. '=====================================================
  83. ' Dialog and Select example
  84.  
  85.     arr$(1) = "black"            'setting each element of the existing array TO a color
  86.     arr$(2) = "red"
  87.     arr$(3) = "white"
  88.     arr$(4) = "blue"
  89.     arr$(5) = "green"
  90.  
  91.  
  92. index% = settovalue(1)        'using a FUNCTIONto ASsign a value TO index
  93. setvars "This is inside a subroutine"                '
  94.  
  95. BEGIN DIALOG combodlg 144, 68, "List Example"        'definition of dialog box
  96.     TEXT           4, 4, 90, 8, "&List:"
  97.     LISTBOX        4, 14, 90, 50, arr$, index%
  98.     OKBUTTON       100, 4, 40, 14
  99.     CANCELBUTTON   100, 20, 40, 14
  100. END DIALOG
  101.  
  102. dlg:
  103. ret% = DIALOG(combodlg)        'returns the button pressed (1 for OK, 2 for Cancel)
  104.  
  105. ' If Cancel is selected, stop the macro
  106.     SELECT CASE ret%     'selects action based on which button is pressed
  107.         CASE 1
  108.             MESSAGE "You chose " + arr$(index%)    
  109.         CASE 2 
  110.             MESSAGE "You selected cancel!"
  111.             goto last
  112.         CASE ELSE            'impossible
  113.             MESSAGE "Try again"
  114.             GOTO dlg
  115.     END SELECT    
  116.  
  117. last:
  118. '=====================================================
  119. ' subs and functions
  120. SUB setvars (strin$)
  121.     MESSAGE strin
  122. END SUB
  123.  
  124. FUNCTION settovalue(v%)
  125.     MESSAGE "This is function #" + STR(v)
  126.     settovalue=v%
  127. END FUNCTION 
  128.  
  129.