robotc controller/encoder

using robotc for cortex would it be possible to press a button on the vex controller have a motor begin turning and stop once an encoder reached a certain value (using the optical shaft encoder)? how would it be done if so?

Yes, here’s an example.

#pragma config(Sensor, dgtl1,  enc1,           sensorQuadEncoder)
#pragma config(Motor,  port1,           motorA,        tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
    while(1) {
      // Button press causes motor to move forward 1000 counts
      if( vexRT Btn8U ] == 1 ) {
        // clear encoder
        SensorValue enc1 ] = 0;
        // start motor
        motor motorA ] = 100;

        // wait for encoder value to be reached
        // assumes encoder counts up as motor runs forward
        while( SensorValue enc1 ] < 1000 ) {
          wait1Msec(20);
        }
        // Stop Motor
        motor motorA ] = 0;

        // make sure button is released
        while( vexRT Btn8U ] == 1 ) {
          wait1Msec(10);
        }
      }

    // no need to run any faster than this
    wait1Msec(20);
    }
}