UNIDAD 3: VISUAL BASIC CGI ARREGLOS
TEMA 3: ARREGLO TIPO LISTA VISUAL BASIC CGI
Un arreglo tipo lista se define como una variable que permite almacenar un conjunto de datos del mismo tipo organizados en una sola columna y uno o mas renglones.
Tambien reciben el nombre de vectores en algebra o arreglos unidimensionales en programacion.
Los procesos normales con una lista o con sus elementos, incluyen declarar toda la lista, capturar sus elementos, desplegarlos, realizar operaciones con ellos, desplegarlos, etc.
Para declarar una lista se usa el siguiente formato;
SHARED DIM NOMLISTA(CANT ELEMENTOS -1) AS TIPODATO
Shared(compartido), se usa cuando la lista se tenga que compartir entre varias subutinas, si un programa tiene varias subrutinas que compartan la misma lista, dicha lista debera ser SHARED.
La cantidad de elementos-1, significa que si se quiere una lista de 5 ciudades por ejemplo su declaracion sera shared dim ciudad(4) as string, la razon de esto es que visual basic empieza una lista por el elemento o renglon cero(0), por tanto cuando se pide crear una lista de 4 ciudades, visual basic net le agrega el renglon o elemento 0, que en total darian 5 ciudade.
Es tambien importante recordar que un arreglo en visual basic net es realmente un objeto derivado de la clase SYSTEM.ARRAY.
Recordar tambien que como objeto arreglo, tambien puede usar una serie de metodos pertenecientes a dicha clase system.array, los metodos principales de dicha clase y por tanto de los arreglos derivados de la misma son:
| BinarySearch | Overloaded. Searches a one-dimensional sorted Array for a value, using a binary search algorithm. |
| Clear | Sets a range of elements in the Array to zero, to false, or to a null reference (Nothing in Visual Basic), depending on the element type. |
| Clone | Creates a shallow copy of the Array. |
| Copy | Overloaded. Copies a section of one Array to another Array and performs type casting and boxing as required. |
| CopyTo | Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index. |
| CreateInstance | Overloaded. Initializes a new instance of the Array class. |
| Equals (inherited from Object) | Overloaded. Determines whether two Object instances are equal. |
| GetEnumerator | Returns an IEnumerator for the Array. |
| GetHashCode (inherited from Object) | Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. |
| GetLength | Gets the number of elements in the specified dimension of the Array. |
| GetLowerBound | Gets the lower bound of the specified dimension in the Array. |
| GetType (inherited from Object) | Gets the Type of the current instance. |
| GetUpperBound | Gets the upper bound of the specified dimension in the Array. |
| GetValue | Overloaded. Gets the value of the specified element in the current Array. |
| IndexOf | Overloaded. Returns the index of the first occurrence of a value in a one-dimensional Array or in a portion of the Array. |
| Initialize | Initializes every element of the value-type Array by calling the default constructor of the value type. |
| LastIndexOf | Overloaded. Returns the index of the last occurrence of a value in a one-dimensional Array or in a portion of the Array. |
| Reverse | Overloaded. Reverses the order of the elements in a one-dimensional Array or in a portion of the Array. |
| SetValue | Overloaded. Sets the specified element in the current Array to the specified value. |
| Sort | Overloaded. Sorts the elements in one-dimensional Array objects. |
| ToString (inherited from Object) | Returns a String that represents the current Object. |
notas:
Recordar que la primera posicion o renglon en una lista es la posicion o renglon 0 (cero).
Prog10.html
<HTML> <B> DAME 5 EDADES </B><br> <form action=/cgi-bin/tusitio/prog10.exe method=get> 1= <INPUT TYPE=text NAME="UNO"><BR> 2= <INPUT TYPE=text NAME="DOS"><BR> 3= <INPUT TYPE=text NAME="TRES"><BR> 4= <INPUT TYPE=text NAME="CUATRO"><BR> 5= <INPUT TYPE=text NAME="CINCO"><BR> <input type=submit value="lista"> <input type=reset> </form> </HTML>
corrida prog10.html
prog10.vb
imports System
imports Microsoft.VisualBasic
PUBLIC CLASS prog10
' declarando arreglo como global
SHARED DIM edad(4) AS INTEGER
PUBLIC SHARED SUB MAIN()
DIM ren AS INTEGER
' creando un objeto de captura
DIM capturar AS lnet = new lnet()
'capturando,cargando y convirtiendo
'los datos de la forma a las variables
edad(0) = CINT(capturar.getparametro("UNO") )
edad(1) = CINT(capturar.getparametro("DOS") )
edad(2) = CINT(capturar.getparametro("TRES") )
edad(3) = CINT(capturar.getparametro("CUATRO") )
edad(4) = CINT(capturar.getparametro("CINCO") )
'operaciones a meses
FOR ren = 0 TO 4
edad(ren) = edad(ren) * 12
NEXT ren
'construyendo y desplegando la pagina de salida
System.Console.WriteLine("Content-Type:text/html" & vbCrLf)
' DESPLEGANDO EN OBJETO LISTA DE HMTL CON BULLETS FOR NORMAL
System.Console.WriteLine("<UL>")
FOR ren = 0 TO 4
System.Console.WriteLine("<LI>"&edad(ren).ToString())
NEXT ren
System.Console.WriteLine("</UL>")
' DESPLEGANDO EN OBJETO LISTA DE HMTL
System.Console.WriteLine("<OL>")
FOR ren = 0 TO 4
System.Console.WriteLine("<LI>"&edad(ren).ToString())
NEXT ren
System.Console.WriteLine("</UL>")
' DESPLEGANDO USANDO OBJETO TABLE DE HMTL FOR NORMAL
System.Console.WriteLine("<table border=2><tr><th>EDADES EN MESES</th></tr>")
FOR ren = 0 TO 4
System.Console.WriteLine("<tr><td>"&edad(ren).ToString()&"</td></tr>")
NEXT ren
END SUB
END CLASS
corrida prog10.vb
Se esta usando un input text por cada elemento del arreglo pero reng empieza en cero y termina en 4, recordar que el arreglo es de 5 elementos, pero su captura y despliegue van del renglon 0 hasta el renglon cuatro.
Para el caso de operaciones y comparaciones con todos los elementos de la lista a la vez, se debera usar un ciclo for con una variable entera llamada renglon, misma que tambien se usa como indice de la lista.
Recordar que todos los datos internos de la lista estaran almacenados en la memoria ram del computador, para despliegues se DEBERA USAR ALGUNOS DE LOS OBJETOS HTML'S que permitan manipular un conjunto de datos a la vez como lo muestra el programa ejemplo.
Para inicializar una lista se debe usar el siguiente formato:
shared dim nomlista() as tipodato={lista de valores separados por comas}
ej;
shared dim edad() as integer = {15,16,17,18}
shared dim sueldo() as double = {40.85, 65.30, 33.33}
shared dim ciudad() as string = {“tecate”, “tijuana”, “mexicali”, “rosarito”, “ensnada”}
TAREAS PROGRAMACION VISUAL BASIC CGI
1.- Capturar y desplegar 5 precios de productos cualesquiera usando dos panel, uno para capturar y uno para desplegar.
2.- Capturar 4 sueldos en un panel desplegarlos aumentados en un 25% en otro panel( un vb capturado y otro vb inicializado).
3.- Capturar los datos de 5 productos comprados en una tienda, incluyendo nombre, precio y cantidad en sus 3 listas respectivas, despues calcular una cuarta lista con el gasto total por cada producto desplegarlo todo e incluir tambien el gran total.