2019 06 2020191038clase15 VisualBasic PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Visual

 Basic  

Patricio  Inostroza  
Historia  (incompleta)  
•  1978:  Basic  
•  1991:  Visual  Basic  1.0  
•  1992:  Visual  Basic  2.0  
•  1993:  Visual  Basic  3.0  
•  1995:  Visual  Basic  4.0  
•  1997:  Visual  Basic  5.0  
•  1998:  Visual  Basic  6.0  
•  2003:  Visual  Basic  .NET  
•  2005:  MicrosoG  released  Visual  Studio  2005    
–  Visual  Basic  8.0  +  .NET  Framework  2.0  
•  2008,  Visual  Studio  2008    
–  VB  9.0  +    .NET  Framework  3.5.    
Variables  

Python    VBasic  
contador  =  1   Dim  contador  As  Integer  
distancia  =  2.5   Dim  distancia  As  Double  
acTvo  =  True   Dim  acTvo  as  Boolean  
nombre  =  “pedro”   Dim  nombre  as  String  
if  

Python    VBasic  
contador  =  1   Dim  contador  As  Integer    
contador  =  1  
If  contador  >  0:   If  contador  >  0  Then    
 print  “Hola”    MsgBox  ”Hola"    
  End  If  
If  
Python    VBasic  
contador  =  1   Dim  contador  As  Integer    
acTvo  =  False   Dim  acTvo  As  Boolean    
   
if  contador  >  0:   contador  =  1    
 if  acTvo:   acTvo=  False  
   print  “Hola”    
If  contador  >  0  Then    
 If  acTvo  Then    
   MsgBox  "Hola"    
 End  If    
End  If  
Operadores  
Python   Vbasic  
c  =  a  +  b   c  =  a  +  b  
c  =  a  -­‐  b   c  =  a  –  b  
c  =  a  /  b   c  =  a  /  b  
c  =  a  %  b   c  =  a  Mod  b  
c  =  a  **  b   c  =  a  ^  b  
Comparación  
Python   Vbasic  
==   =  
!=   <>  
>,  >=   >,  >=  
<,  <=   <,  <=  
if  a  !=  b:   If  a  <>  b  Then    
 print  “a  no  es  igual  a  b”    MsgBox  "a  no  es  igual  b"    
  End  If    
if  a  >  b:    
 print  “a  es  mayor  que  b”   If  a  >  b  Then    
 MsgBox  "a  es  mayor  que  b"    
End  If    
ciclo  
Python   Vbasic  
contador  =  1     Dim  contador  As  Integer    
  contador  =  1    
while  contador  <=  10:      
 print  contador     Do  While  contador  <=  10    
 contador  =  contador  +  1    MsgBox  contador    
 contador  =  contador  +  1    
Loop  
ciclo  
Python   Vbasic  
nums  =  range(1,  4)     Dim  i  As  Integer    
   
for  i  in  nums:     For  i  =  1  To  3    
 print  i    MsgBox  i    
Next  i  
Range  
Python   Vbasic  
nums  =  range(1,  4)     Dim  col  As  CollecTon    
  Set  col  =  New  CollecTon    
for  numero  in  nums:      
 print  numero   col.Add  1    
  col.Add  2    
#  lo  mismo,  más  corto   col.Add  3    
for  numero  in  range(1,  4):    
 print  numero   For  Each  numero  In  col  
 MsgBox  numero  
Next  numero  
Arreglos  
Python   Vbasic  
animales=  [  ]  #  lista  vacia     Dim  col  As  CollecTon    
  Set  col  =  New  CollecTon  
animales.append(”Gato")    
animales.append(”Perro")   col.Add  ”Gato"    
animales.append(”Raton")     col.Add  ”Perro"    
  col.Add  ”Raton”  
animales.remove(”Gato")      
  col.Remove  1    
print  len(animales)    
MsgBox  col.count  
Arreglos  
Python   Vbasic  
animales  =  [”Gato",   Dim  animales  As  Variant    
”Perro",  ”Raton"]      
  animales  =  Array(”Gato",  
print  animales[0]     ”Perro",  ”Raton")    
print  animales[1]    
MsgBox  animales(0)    
MsgBox  animales(1)  
Función  +  print  
Python   Vbasic  
def  escribir(s):     Sub  escribir  (ByRef  s  As  String)    
 print  s      MsgBox  s    
  End  Sub    
escribir(”primera  linea")    
escribir("segunda  linea")   escribir  "primera  linea"    
escribir  "segunda  linea”  
 
Función  +  return  
Python   Vbasic  
def  suma(a,  b):     FuncTon  Suma(ByRef  a  As  Integer,  
 return  a  +  b     ByRef  b  As  Integer)  As  Integer    
   Suma  =  a  +  b    
print  suma(5,  10)     End  FuncTon    
print  suma(10,  20)    
MsgBox  Suma(5,  10)    
MsgBox  Suma(10,  20)  
Función  
Python   Vbasic  
def  mostrar(nombre,  edad=0):   Sub  Mostrar(ByRef  nombre  As  
    String,  OpTonal  ByRef  edad  As  
 print  nombre   Integer  =  0)    
 if  age  >  0:      
   print  edad    MsgBox  nombre  
   If  edad>  0  Then    
mostrar(”Pedro")      MsgBox  edad  
mostrar(”Pedro",  30)    End  If    
End  Sub    
 
Mostrar  ”Pedro"    
Mostrar  ”Pedro",  30  
Ya  son  expertos  J  

You might also like