Diferencia entre revisiones de «Gambas/Scripting con Gambas»

Contenido eliminado Contenido añadido
Sin resumen de edición
Sin resumen de edición
Línea 44:
De hecho, si teclearas directamente en la consola el comando ''ls -g -B'' obtendrías el mismo resultado que ejecutando tu script. Ejecuta tu script para que lo constates.
 
Como de seguro ya notaste, puedes declarar todo tipo de variabesvariables, incluso arrays; pero no esta limitado a esto, tambientambién puedes hacer uso de procedimientos, funciones y casi todos los recursos disponibles en el lenguaje Gambas.
 
*'''Leer entradas por el usuario'''
Línea 54:
PRINT "Hey " & userInput &"! Recibí tu respuesta. Yupi!"
 
Ejecuta el script y veras que pregunta por tu nombre y despuesdespués que presiones [Enter] aparece un mensaje usando la cadena de caracteres que tecleaste.
user@PC:~$ '''askname.gbs'''
''Please enter your name:''
Línea 62:
 
*'''Pasar argumentos al script'''
Algunas otras veces, desearas recibir la información del usuario desde un inicio como argumentos del script. Esto lo consigues haciendo uso del array ''Args[]'' de la clase ''Application''. Escribe el siguiente codigocódigo en un archivo llamado ''argumentos.gbs''.
#!/usr/bin/env gbs2
PUBLIC SUB Main()
Línea 81:
NEXT
END
Hasta el momento, los scripts que habias escrito empezabas sin ninguna declaración del método ''Main()'', pero ahora, para poder acceder a la clase ''Application'' necesitas declarar un metodo de inicio. De hecho, es una buena practica siempre hacer uso del metodo ''Main()'' incluso en scripts pequenos. Ejecuta el script.
user@PC:~$ gbs2 arguments.gbs TheseEstos areson argumentsargumentos “This“Este ises oneun argumentsolo also”argumento”
So far now, all the scripts in this lesson started without any Main() method declaration, but in order to gain access to the Application class, you need to declare a startup method. Actually it is a good practice to always make use of the Main() method even for small scripts.
/tmp/gambas.10001.../script-cache/5......
Run the script.
Estos
user@PC:~$ gbs2 arguments.gbs These are arguments “This is one argument also”
son
/tmp/gambas.1000/script-cache/5......
argumentos
These
Este es un solo argumento
are
arguments
/tmp/gambas.1000/1...script-cache/5......
This is one argument also
Estos
 
son
/tmp/gambas.1000/script-cache/5......
argumentos
These
Este es un solo argumento
are
arguments
This isloop onestarts argumentfrom also1 not from 0
Estos
son
argumentos
Este es un solo argumento
user@PC:~$
 
La primer linea de los argumentos, es decir el elemento 0 del array, no es un argumento pasado por el usuario, sino una referencia al cache del script. Toma en cuenta esto cuando estés escribiendo tus propios scripts.
This loop starts from 1 not from 0
These
are
arguments
This is one argument also
user@PC:~$
The very first argument (the element 0 of the array) is not an argument passed by the user, but a reference to the script cache. Take this into account when designing your own scripts.
Exercise
1.Write an script that ask for two integer numbers and then perform the following operations with them: add, multiply, divide and subtract.
 
== '''Gsw - En CGI Web''' ==
Línea 122 ⟶ 119:
< th align="left">Value< /th >
< /tr >
< % FOR EACH sEnv IN Application.Env % >
< tr valign="top" >
< td >< %= sEnv % >< /td >
< td >< %= Application.Env[sEnv] % >&nbsp;< /td >
< /tr >
< % NEXT % >
< /table >
< /html >
 
Ejemplo tomado de [[http://gambasdoc.org/help/doc/serverpage|http://gambasdoc.org/help/doc/serverpage]]