visual basic 2008-i
TRANSCRIPT
![Page 1: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/1.jpg)
![Page 2: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/2.jpg)
Inicio Visual Basic 2008
![Page 3: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/3.jpg)
Create New Project
![Page 4: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/4.jpg)
New project Window
Botones de minimizar maximizar y cerrar
Windows form object
Title bar
Desing tab page
![Page 5: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/5.jpg)
MsgBox("Hola " & TextBox1.Text)
![Page 6: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/6.jpg)
MsgBox ( ) FunctionyourMsg=MsgBox(Prompt, Style Value,
Title)Styles
Ejemplo : yourMsg=MsgBox( "Click OK to Proceed", 1, "Startup Menu")
![Page 7: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/7.jpg)
Escribiendo CódigoPrivate Sub Form1_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadMe.Text="My First VB2008 Program"
Me.ForeColor = Color.YellowMe.BackColor = Color.Blue
End Sub
![Page 8: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/8.jpg)
Tipos de DatosA nivel de algoritmo, lo básico es definir el
tipo de dato, los siguientes tiposde datos son los siguientes:
Numéricos; Dígitos, cifras (Números reales)
Carácter; un símbolo que el computador puede reconoces (Letras, dígitos, signos de puntuación, símbolos), representan un texto (no se utilizan en operaciones matemáticas)
Booleana; un valor lógico que puede ser verdadero (V) o falso (F).
![Page 9: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/9.jpg)
EjemploPrivate Sub
Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim name1, name2, name3 As Stringname1 = "John“name2 = "Chan“name3 = "Ali"MsgBox(" The names are " & name1 & " , " & name2 & " and " & name3)
End Sub
![Page 10: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/10.jpg)
Operadores matemáticos+ Suma- Resta* Multiplicación/ División^ Potencia
![Page 11: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/11.jpg)
Operadores relacionales o comparativos> Mayor< Menor>= Mayor Igual<= Menor Igual<> Diferente= Igual
![Page 12: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/12.jpg)
Operadores LógicosOperador Significado
And El operador And solo utilizamos cuando queremos que se cumpla una serie de expresiones
or El operador Or solo utilizamos cuando queremos que se cumpla una expresión de toda una serie de expresiones
Xor El operador Xor lo utilizaremos para casos especiales ya que realiza una operación de exclusión lógica entre dos expresiones de tipo Boolean o bien una exclusión bit a bit entre dos expresiones numéricas
No Este operador se utiliza para hacer negaciones.
![Page 13: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/13.jpg)
Tablas de verdad de las principales operaciones Lógicas - ANDResumiendo, el
resultado siempre dará F a menos que ambas variables sean Cierta
AND
F and F = F
F and C = F
C and F = F
C and C =C
![Page 14: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/14.jpg)
Tablas de verdad de las principales operaciones Lógicas - ORResumiendo el
resultado arrojado será siempre C si al menos una de las variables tiene por valor C.
OR
F or F = F
F or C = C
C or F = C
C and C =C
![Page 15: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/15.jpg)
Tablas de verdad de las principales operaciones Lógicas - NOT
El not es una inversión del valor.
NOT
Not C = F
Not F = C
![Page 16: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/16.jpg)
Variables y ConstantesSintaxis para declarar variables
Dim nombreVariable As Type Podemos utilizar variables para
Almacenar valores de expresionesAlmacenar entrada del usuarioAlmacenar objetosAlmacenar valores de propiedadesDevolver valoresMostrar la salida
Sintaxis para declarar una constante: Const constantName As Type
![Page 17: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/17.jpg)
Instrucción CondicionalIf <expresión condicional (lógica booleana)> Then
Instrucción Verdadera (V)Else
Instrucción Falsa (F)Endif
![Page 18: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/18.jpg)
Select Case Control StructureSelect Case test expression Case expression list 1
Block of one or more VB statements Case expression list 2 Block of one or more VB Statements Case expression list 3 Block of one or more VB statements Case expression list 4 . . . Case Else Block of one or more VB Statements
End Select
![Page 19: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/19.jpg)
For....Next LoopThe format is: For counter=startNumber to endNumber (Step
increment) One or more VB statements
Next
![Page 20: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/20.jpg)
Ejemplos For1. The program will enter number 1 to 10 into the list box.Dim counter as IntegerFor counter=1 to 10
ListBox1.Items.Add (counter) Next 2. The program will calculate the sum of the numbers as
follows: sum=0+10+20+30+40+......Dim counter , sum As IntegerFor counter=1 to 100 step 10
sum+=counterListBox1.Items.Add (sum)
Next
![Page 21: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/21.jpg)
Ejemplos For3. Notice that increment can be negative. The program will compute the subtraction as
follow: 1000-100-95-90-..........
Dim counter, sum As Integersum = 1000For counter = 100 To 5 Step -5sum - = counterListBox1.Items.Add(sum)Next
Dim n as IntegerFor n=1 to 10
![Page 22: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/22.jpg)
Ejemplos For4. The process will stop when n is greater than
6.Dim n as IntegerFor n=1 to 10
If n>6 then Exit For End If
Else ListBox1.Items.Add ( n) Next
End IfNext
![Page 23: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/23.jpg)
ESTRUCTURAS REPETITIVASCuando no se conoce el número de ciclo a
realizar. Se debe prever que las expresiones lógicas llegue a ser falsa en algún momento, sino este llegaría a formar un LOOP (Proceso repetitivo infinito que nunca termina, se da cuando la expresión lógica de control nunca llega a ser falsa)
Las instrucciones se realizan, siempre y cuando la lógica sea verdadera, en caso contrario, por no decir si llega a ser falsa, esta dará por terminado el algoritmo o el programa.
![Page 24: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/24.jpg)
Do Loopa) Do While condition Block of one or more VB statements Loop b) Do
Block of one or more VB statements Loop While condition
c) Do Until condition Block of one or more VB statements Loop
d) Do Block of one or more VB statements
Loop Until condition
![Page 25: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/25.jpg)
Ejemplo Do Loop* The example will keep on adding until
counter >1000. Do while counter <=1000 TextBox1.Text=counter counter +=1 Loop
![Page 26: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/26.jpg)
Ejemplo Do Loop In the example, we find the summation of 1+2+3+4+……+100.
In the design stage, you need to insert a ListBox into the form for displaying the output, named List1. The program uses the AddItem method to populate the ListBox. The statement ListBox1.Items.Add(n & vbTab & sum) will display the headings in the ListBox, where it uses the vbTab function to create a space between the headings n and sum.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim sum, n As IntegerDo
n += 1sum += nListBox1.Items.Add(n & vbTab & sum)If n = 100 Then
Exit DoEnd If
Loop Sub
![Page 27: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/27.jpg)
While ...End While LoopThe structure of a While….End While is very
similar to the Do Loop. it takes the following format:
While condition Statements
End WhileThe above loop means that while the
condition is not met, the loop will go on. The loop will end when the condition is met.
![Page 28: Visual Basic 2008-I](https://reader033.vdocuments.net/reader033/viewer/2022061119/546af856b4af9f330a8b45c9/html5/thumbnails/28.jpg)
Ejemplo While ...End While Dim sum, n As IntegerPrivate Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim sum, n As IntegerWhile n <> 100
n += 1sum = sum + nListBox1.Items.Add(n & vbTab & sum)
End While
End Sub