Hi,
I think that when you work with numbers is better to use numerical variables instead of strings.

Here goes a simple implementation with the use of 'key_any' and 'key_lastpressed'

Code
function num_edit (var *_ptr_num, var _max) {
	var _old_value = *_ptr_num;
	var _last_pressed = key_lastpressed;
	while(1) {
		if(key_any) {
			if(key_lastpressed != _last_pressed) {
				_last_pressed = key_lastpressed;
				switch(_last_pressed) {
					case 1: // esc
						*_ptr_num = _old_value;
						return;
					
					case 14: // back space
						*_ptr_num = floor(*_ptr_num / 10);
						break;
					
					case 28: // enter
						return;
					
					default: // any other key
						if(_last_pressed > 11) // from 1 to 0 keys -> from 2 to 11 scancodes
							break;
						var _res = *_ptr_num * 10 + (_last_pressed - 1) % 10; // 11 = scancode of 0 character
						if(_res > _max)
							break;
						*_ptr_num = _res;
				}
			}
		} else {
			_last_pressed = 0;
		}
		wait(1);
	}
}

// --------------------------------------------------

function main () {
	static var my_num = 20;
	num_edit(my_num, 150);
	
	while(1) {
		DEBUG_VAR(my_num, 100);
		wait(1);
	}
}


Salud!