0% found this document useful (0 votes)
26 views55 pages

Compu

The document contains 38 code snippets written in Visual Basic that demonstrate various programming concepts like input/output, arithmetic operations, conditional statements, loops, and arrays. The snippets cover basics like displaying messages and calculating sums and products, as well as more complex topics like sorting arrays, calculating averages, Fibonacci sequences, and analyzing ranges of numbers.

Uploaded by

GASTON CHOQUE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views55 pages

Compu

The document contains 38 code snippets written in Visual Basic that demonstrate various programming concepts like input/output, arithmetic operations, conditional statements, loops, and arrays. The snippets cover basics like displaying messages and calculating sums and products, as well as more complex topics like sorting arrays, calculating averages, Fibonacci sequences, and analyzing ranges of numbers.

Uploaded by

GASTON CHOQUE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 55

1.

Private Sub Command1_Click()

MsgBox ("Hola Mundo")

End Sub

2. Private Sub cmdInicio_Click()

Dim nombre As String 'variable nombre de tipo cadena

nombre = InputBox("Ingrese Nombre") ' se pide al usuario su nombre

MsgBox ("Hola Como Estas " & nombre) ' se muestra un saludo

End Sub

3. Private Sub Command1_Click()

Dim a, b, suma As Integer

a = InputBox("ingrse 1er Numero")

b = InputBox("ingrse 2do Numero")

suma = Val(a) + Val(b)

MsgBox ("la suma de los numeros es: " & suma)

End Sub
4. Private Sub Command1_Click()

Dim a, b, producto As Integer

a = InputBox("ingrse 1er Numero")

b = InputBox("ingrse 2do Numero")

producto = Val(a) * Val(b)

MsgBox ("el producto de los numeros es: " & producto)

End Sub

5. Private Sub Command1_Click()

Dim l, area As Integer

l = InputBox("ingrse uno de los lados")

area = l * l

MsgBox ("el area del cuadrado es: " & area)

End Sub
6. Private Sub Command1_Click()

Dim b, a, area As Integer

b = InputBox("ingrse la base del triangulo")

a = InputBox("ingrse la altura del triangulo")

area = (b * a) / 2

MsgBox ("el area del triangulo rectangulo es: " & area)

End Sub

7. Private Sub Command1_Click()

Dim b, a, area As Integer

b = InputBox("ingrse la base del triangulo")

a = InputBox("ingrse la altura del triangulo")

area = (b * a) / 2

MsgBox ("el area del triangulo rectangulo es: " & area)

End Sub

8. Private Sub Command1_Click()

Dim nom As String

nom = InputBox("ingrse su nombre")

MsgBox ("Hola se Bien Venido " & nom)


End Sub

9. Private Sub Command1_Click()

Dim a, b As Integer

a = Val(Text1.Text)

b = Val(Text2.Text)

MsgBox ("El Producto es " & a * b)

End Sub

10. Private Sub Command1_Click()

Dim c, f As Integer

c = Val(Text1.Text)

f = (9 / 5) * c + 32

Text2.Text = f

End Sub

11. Private Sub Command2_Click()


Dim a, b, c As Integer

a = Val(Text1.Text)

b = Val(Text2.Text)

c = Val(Text3.Text)

Label4.Caption = (a + b + c) / 3

End Sub

12. Private Sub Command1_Click()

Dim nht, pxh As Integer

nht = Val(Text1.Text)

pxh = Val(Text2.Text)

MsgBox ("El salario a pagar es: " & nht * pxh)

End Sub

13. Private Sub Command1_Click()

n1 = Val(txtNum1.Text)

n2 = Val(txtNum2.Text)

lblOp.Caption = "+"

txtRes.Text = n1 + n2
End Sub

Private Sub Command2_Click()

n1 = Val(txtNum1.Text)

n2 = Val(txtNum2.Text)

lblOp.Caption = "-"

txtRes.Text = n1 - n2

End Sub

Private Sub Command3_Click()

n1 = Val(txtNum1.Text)

n2 = Val(txtNum2.Text)

lblOp.Caption = "*"

txtRes.Text = n1 * n2

End Sub

Private Sub Command4_Click()

n1 = Val(txtNum1.Text)

n2 = Val(txtNum2.Text)

lblOp.Caption = "/"

txtRes.Text = n1 / n2

End Sub

14. Private Sub Command1_Click()

Dim cf, cv, q, ct As Integer

cf = Val(Text1.Text)

cv = Val(Text2.Text)
q = Val(Text3.Text)

ct = cf + cv * q

Text4.Text = ct

End Sub

15. Private Sub Command1_Click()

Dim c, cv, iva, pf As Integer

c = Val(Text1.Text)

cv = Val(Text2.Text)

iva = Val(Text3.Text) / 100

pf = c + cv + (c * iva)

Text4.Text = pf

End Sub

SELECTIVAS

16. Private Sub Command1_Click()

Dim num As Integer

num = InputBox("ingrese numero")

If (num = 0) Then
MsgBox (num & " es cero")

Else

MsgBox (num & " no es cero")

End If

End Sub

17. Private Sub Command1_Click()

Dim num As Integer

num = InputBox("ingrese numero")

If (num Mod 2 = 0) Then

MsgBox (num & " es par")

Else

MsgBox (num & " no es par")

End If

End Sub

18. Private Sub Command1_Click()

Dim num1 As Integer

num1 = InputBox("ingrese numero")


If (num1 Mod 5 = 0) Then

MsgBox (num1 & " es multiplo de 5")

Else

MsgBox (num1 & " no es multiplo de 5")

End If

End Sub

19. Private Sub Command1_Click()

Dim num1, num2 As Integer

num1 = InputBox("ingrese numero")

num2 = InputBox("ingrese numero")

If (num1 Mod num2 = 0) Then

MsgBox (num1 & " es multiplo de " & num2)

Else

MsgBox (num1 & " no es multiplo de " & num2)

End If

End Sub

20. Private Sub Command1_Click()


Dim a, b As Integer

a = InputBox("Ingrese primer numero")

b = InputBox("Ingrese segundo numero")

If (a > b) Then

MsgBox (a & " es mayor que " & b)

Else

MsgBox (b & " es mayor que " & a)

End If

End Sub

21. Private Sub Command1_Click()

Dim a, b As Integer

a = InputBox("Ingrese primer numero")

b = InputBox("Ingrese segundo numero")

If (a < b) Then

MsgBox (a & " es menor que " & b)

Else

MsgBox (b & " es menor que " & a)

End If

End Sub
22. Private Sub Command1_Click()

Dim a, b As Integer

a = Val(Text1.Text)

b = Val(Text2.Text)

If (a = b) Then

MsgBox (a & " es igual a " & b)

Else

If (a > b) Then

MsgBox (a & " es mayor que " & b)

Else

MsgBox (b & " es mayor que " & a)

End If

End If

End Sub

23. Private Sub Command1_Click()

Dim n1, n2, n3 As Integer

n1 = Val(Text1.Text)

n2 = Val(Text2.Text)
n3 = Val(Text3.Text)

If (n1 < n2 And n1 < n3) Then

If (n2 < n3) Then

MsgBox (n1 & " " & n2 & " " & n3)

Else

MsgBox (n1 & " " & n3 & " " & n2)

End If

End If

If (n2 < n1 And n2 < n3) Then

If (n1 < n3) Then

MsgBox (n2 & " " & n1 & " " & n3)

Else

MsgBox (n2 & " " & n3 & " " & n1)

End If

End If

If (n3 < n1 And n3 < n2) Then

If (n1 < n2) Then

MsgBox (n3 & " " & n1 & " " & n2)

Else

MsgBox (n3 & " " & n2 & " " & n1)

End If

End If

End Sub
24. Private Sub cmdInicio_Click()

Dim nota As Integer

nota = InputBox("Ingrese Nota")

If (nota >= 0 And nota <= 100) Then

If (nota >= 51) Then

MsgBox ("Aprobado")

Else

MsgBox ("Reprobado")

End If

Else

MsgBox ("ERROR . . !!")

End If

End Sub

25. Private Sub Command1_Click()

Dim n1, n2, n3 As Integer

n1 = Val(Text1.Text)
If (n1 >= 10 And n1 <= 50) Then

MsgBox (n1 & " esta en el rango 10 a 50")

Else

If (n1 >= 60 And n1 <= 100) Then

MsgBox (n1 & " esta en el rango 60 a 100")

Else

If (n1 > 100) Then

MsgBox (n1 & " esta en el rango mayor a 100")

Else

MsgBox (n1 & " no se encuentra en ninguno de los rangos")

End If

End If

End If

End Sub

26. Private Sub Command1_Click()

Dim n1, n2, n3 As Integer

n1 = Val(Text1.Text)

If (n1 >= 1 And n1 <= 50) Then

MsgBox (n1 & " nota de reprobacion")

Else
If (n1 >= 51 And n1 <= 79) Then

MsgBox (n1 & " nota Buena")

Else

If (n1 >= 80 And n1 <= 100) Then

MsgBox (n1 & " es una nota Excelente")

Else

MsgBox (n1 & " no esta en el rango")

End If

End If

End If

End Sub

REPETITIVAS

27. Private Sub Command1_Click()


Dim suma, n As Integer
n=2
For i = 1 To 20 Step 1
suma = suma + n
n=n+2
Next i
MsgBox ("la suma de los 20 primeros pares es: " & suma)
End Sub
28. Private Sub Command1_Click()
Dim suma, n As Integer
n=3

For i = 1 To 10 Step 1
suma = suma * n
n=n+3
Next i
MsgBox ("la suma de los 10 primeros multiplos de 3: " & f)
End Sub

29. Private Sub Command1_Click()

For i = 100 To 200 Step 1


If (i Mod 7 = 0) Then
List1.AddItem (i)
End If
Next i

End Sub

30. Private Sub Command1_Click()


Dim n, inp As Integer
inp = 1
n = InputBox("Ingrese un numeros")
For i = 1 To n Step 1
cuad = cuad + inp
inp = inp + 2
Next i
MsgBox ("el cuadradode " & n & " es: " & cuad)
End Sub

31. Private Sub Command1_Click()


Dim pi, t, d As Double
d=1
For i = 1 To 100 Step 1
t=1/d
d=d+2
If (i Mod 2 = 0) Then
pi = pi - t
Else
pi = pi + t
End If

Next i
MsgBox ("el valor de PI es: " & pi * 4)
End Sub

32. Private Sub Command1_Click()


Dim suma, t As Double
For i = 1 To 10 Step 1
t=1/i
suma = suma + t
Next i
MsgBox ("la suma de la serie es: " & suma)
End Sub
33. Private Sub Command1_Click()
Dim suma, t, b As Double
b=2
For i = 1 To 19 Step 2
t=i/b
suma = suma + t
b=b+b
Next i
MsgBox ("la suma de la serie es: " & suma)
End Sub

34. Private Sub Command1_Click()


Dim t As Long
t=1
For i = 1 To 10 Step 1
List1.AddItem (t)
t=t*3
Next i
End Sub

35. Private Sub cmdFibonacci_Click()


Dim a, b, n, c As Integer
n = txtNum1.Text
c=2
a=0
b=1
lstSalida1.Clear
lstSalida1.AddItem (a)
lstSalida1.AddItem (b)

For i = 3 To n Step 1
n=a+b
lstSalida1.AddItem (n)
c=c+1
a=b
b=n
Next i

End Sub

36. Private Sub Command1_Click()


Dim suma, n As Double
For i = 1 To 10 Step 1
n = InputBox("Ingresa Numero " & i)
suma = suma + n
Next i
MsgBox ("el promedio de los 10 numeros leidos es: " & (suma / 10))
End Sub

37. Private Sub Command1_Click()


Dim may, n As Double
n = InputBox("Ingresa Numero 1")
may = n
For i = 2 To 10 Step 1
n = InputBox("Ingresa Numero " & i)
If (n > may) Then
may = n
End If
Next i
MsgBox ("el mayor de los 10 nuemros leidos es: " & may)
End Sub

38. Private Sub Command1_Click()


Dim cont As Double
cont = 0
For i = 1 To 10 Step 1
n = InputBox("Ingresa Numero " & i)
If (n >= 0) Then
cont = cont + 1
End If
Next i
MsgBox ("la cantidad de positivos es: " & cont)
End Sub

39. Private Sub Command1_Click()


Dim contP As Double
contP = 0
contN = 0
contC = 0
For i = 1 To 10 Step 1
n = InputBox("Ingresa Numero " & i)
List1.AddItem (n)
If (n > 0) Then
contP = contP + 1
End If
If (n < 0) Then
contN = contN + 1
End If
If (n = 0) Then
contC = contC + 1
End If
Next i
MsgBox ("la cantidad de positivos es: " & contP)
MsgBox ("la cantidad de negativos es: " & contN)
MsgBox ("la cantidad de ceros es: " & contC)
End Sub

40. Private Sub Command1_Click()

Dim contP As Double


contP = 0
contI = 0
For i = 1 To 10 Step 1
n = InputBox("Ingresa Numero " & i)
List1.AddItem (n)
If (n Mod 2 = 0) Then
contP = contP + 1
End If
If (n Mod 2 <> 0) Then
contI = contI + 1
End If
Next i
MsgBox ("la cantidad de pares es: " & contP)
MsgBox ("la cantidad de inpares es: " & contI)

End Sub

41. Private Sub Command1_Click()


Dim cont1, cont2 As Integer
cont1 = 0
cont2 = 0
For i = 1 To 10 Step 1
n = InputBox("Ingresa Numero " & i)
List1.AddItem (n)
If (n Mod 3 = 0) Then
cont1 = cont1 + 1
End If
If (n Mod 5 = 0) Then
cont2 = cont2 + 1
End If
Next i
MsgBox ("la cantidad de multiplos de 3 es: " & cont1)
MsgBox ("la cantidad de multiplos de 5 es: " & cont2)
End Sub

42. Private Sub Command1_Click()


Dim cont1, cont2 As Integer
contE = 0
contMB = 0
contB = 0
contR = 0
contM = 0
For i = 1 To 10 Step 1
n = InputBox("Ingresa Numero " & i)
List1.AddItem (n)
If (n > 80 And n < 100) Then
contE = contE + 1
End If
If (n > 70 And n < 80) Then
contMB = contMB + 1
End If
If (n > 60 And n < 70) Then
contB = contB + 1
End If
If (n > 40 And n < 60) Then
contR = contR + 1
End If
If (n > 0 And n < 40) Then
contM = contM + 1
End If
Next i
MsgBox ("la cantidad de Exelentes es de: " & contE)
MsgBox ("la cantidad de Muy buenos es de: " & contMB)
MsgBox ("la cantidad de buenos es de: " & contB)
MsgBox ("la cantidad de regulares es de: " & contR)
MsgBox ("la cantidad de notas malas es de: " & contM)
End Sub

43. Private Sub Command1_Click()

n = InputBox("Ingresa Numero " & i)

If (n >= 51) Then


MsgBox ("Aprobado")
End If
If (n <> 0 And n < 50) Then
MsgBox ("Reprobado")
End If
If (n = 0) Then
MsgBox ("Abandono")
End If
End Sub

44. Private Sub Command1_Click()

n = InputBox("Ingresa Numero 1")


aux = n
i=2
List1.AddItem (aux)
While (aux <> 1)
If (primo(i) = True) Then
While (aux Mod i = 0)
aux = aux / i
List1.AddItem (aux)
Wend
End If
i=i+1
Wend
End Sub

Function primo(n) As Boolean


Dim cd As Integer

For i = 1 To n Step 1
If (n Mod i = 0) Then
cd = cd + 1
End If
Next i
If (cd = 2) Then
primo = True
Else
primo = False
End If
End Function

45. Private Sub cmdVerificar_Click()


Dim a As Integer
Dim b As Integer
Dim sma As Integer
Dim smb As Integer

a = InputBox("Ingrese A")
b = InputBox("Ingrese B")
sma = 0
For i = 1 To a - 1 Step 1
If (a Mod i = 0) Then
sma = sma + i
End If
Next i

smb = 0
For i = 1 To b - 1 Step 1
If (b Mod i = 0) Then
smb = smb + i
End If
Next i

If (sma = b And smb = a) Then


MsgBox ("Son Amigos")
Else
MsgBox ("no son Amigos")
End If

End Sub

46. Private Sub cmdInicio_Click()


Dim n As Integer
Dim sm As Integer
n=1
While (n <= 1000)
sm = 0
'sumar solo los divisores de n
For i = 1 To n - 1 Step 1
If (n Mod i = 0) Then
sm = sm + i
End If
Next i
'verificamos si es perfecto
If (sm = n) Then
lstSalida.AddItem (n)
End If
n = n + 1 ' incrementamos n
Wend

End Sub

47. Private Sub Command1_Click()


Dim n As Integer
Dim res As Boolean

n = txtNum1.Text
res = perfecto(n)
If (res = True) Then
MsgBox ("Es Numero Perfecto")
Else
MsgBox ("No es Numero Perfecto")
End If

End Sub
Function perfecto(n As Integer) As Boolean
Dim suma As Integer
suma = 0
For i = 1 To n - 1 Step 1
If (n Mod i = 0) Then
suma = suma + i
End If
Next i
If (suma = n) Then
perfecto = True
Else
perfecto = False
End If
End Function

48. Private Sub cmdPrimo_Click()


Dim n As Integer
Dim res As Boolean
n = txtNum1.Text
res = primo(n)
If (res = True) Then
MsgBox ("Es Primo")
Else
MsgBox ("No es Primo")
End If

End Sub
Function primo(n As Integer) As Boolean
Dim cd As Integer

For i = 1 To n Step 1
If (n Mod i = 0) Then
cd = cd + 1
End If
Next i
If (cd = 2) Then
primo = True
Else
primo = False
End If

End Function

49.
Private Sub cmdInicio_Click()
Dim n1 As Integer
Dim n2 As Integer
Dim pm As Double
Dim cont As Integer
Dim v1 As Boolean
Dim sm As Integer
Dim pmdt As Double

n1 = InputBox("ingrese NOTA 1")


n2 = InputBox("ingrese NOTA 2")
v1 = verificarceros(n1, n2)
sm = 0
cont = 0
While (v1 = True)
pm = promedio(n1, n2)
MsgBox ("Promedio Total es: " & pm)
cont = cont + 1
sm = sm + pm
n1 = InputBox("Ingrese NOTA 1")
n2 = InputBox("Ingrese NOTA 2")
v1 = verificarceros(n1, n2)
Wend
pmdt = sm / cont
MsgBox ("Promedio Total es: " & pmdt)
End Sub

Function verificarceros(a As Integer, b As Integer) As Boolean


' retorna falso si a y b son ceros
' retorna verdad si a y b son distintos de cero
Dim res As Boolean
res = True
If (a = 0 And b = 0) Then
res = False
End If
verificarceros = res
End Function

Function promedio(a As Integer, b As Integer) As Double


' retorna el promdio de a y b
Dim res1 As Double
res1 = (a + b) / 2
promedio = res1
End Function

VECTORES
50. Dim vec(1 To 10) As Integer
Private Sub cmdBuscar_Click()
numB = txtElemBuscar.Text
pos = -1
For i = 1 To 10 Step 1
If (vec(i) = numB) Then
pos = i
End If
Next

If (pos >= 0) Then


MsgBox ("Se encontro el elemto en la posicion " & pos)
Else
MsgBox ("No se encontro el elemto")
End If
End Sub

Private Sub cmdCargarVec_Click()


For i = 1 To 10 Step 1
vec(i) = Rnd() * 100
Next
lstSalida1.Clear
For i = 1 To 10 Step 1
lstSalida1.AddItem ("pos: " & i & " --> " & vec(i))
Next
End Sub

Private Sub cmdOrdenar_Click()


Dim aux As Integer

For i = 1 To 10 Step 1
For j = i To 10 - 1 Step 1
If (vec(i) > vec(j + 1)) Then
aux = vec(i)
vec(i) = vec(j + 1)
vec(j + 1) = aux
End If
Next j
Next i

lstSalida2.Clear
For i = 1 To 10 Step 1
lstSalida2.AddItem (vec(i))
Next i
End Sub
51. Dim vec(1 To 10) As Integer
Private Sub cmdCargarVector_Click()
For i = 1 To 10 Step 1
vec(i) = InputBox("Ingrese un numero")
Next
End Sub
Private Sub cmdMostrar_Click()
For i = 1 To 10 Step 1
lstSalida1.AddItem (vec(i))
Next
End Sub

Private Sub Command1_Click()


End
End Sub

52. Dim vec(1 To 15) As Integer


Private Sub Command1_Click()
Dim n As Integer
n=5
For i = 1 To 15 Step 1
vec(i) = n
List1.AddItem (n)
n=n+5
Next i
End Sub
53. Dim A(1 To 7) As Integer ' Variables Globales
Dim B(1 To 5) As Integer
Dim C(1 To 12) As Integer
Dim i As Integer
Dim j As Integer

Private Sub cmdInterseccion_Click()


lstSalida3.Clear
For i = 1 To 7 Step 1
For j = 1 To 5 Step 1
If (A(i) = B(j)) Then
lstSalida3.AddItem (A(i))
End If
Next j
Next i
End Sub

Private Sub cmdUnion_Click()


Dim k As Integer
k=0
' Vaciar A en C
For i = 1 To 7 Step 1
k=k+1
C(k) = A(i)
Next i
' Vaciar B en C
For j = 1 To 5 Step 1
k=k+1
C(k) = B(j)
Next j
' Eliminar Elementos repetidos con un cero
For i = 1 To 11 Step 1
For j = i + 1 To 12 Step 1
If (C(i) = C(j)) Then
C(j) = 0
End If
Next j
Next i
' Ordenamos aplicando el metodo de la burbuja
For i = 1 To 11 Step 1
For j = i + 1 To 12 Step 1
If (C(i) > C(j)) Then
aux = C(i)
C(i) = C(j)
C(j) = aux
End If
Next j
Next i
' mostramos a los que son diferentes de cero
For i = 1 To 12 Step 1
If (C(i) <> 0) Then
lstSalida4.AddItem (C(i))
End If
Next i

End Sub

Private Sub cmdVectorA_Click()


lstSalida1.Clear
For i = 1 To 7 Step 1
A(i) = InputBox("Ingrese elementos de A")
lstSalida1.AddItem (A(i))
Next i
End Sub

Private Sub cmdVectorB_Click()


lstSalida2.Clear
For j = 1 To 5 Step 1
B(j) = InputBox("Ingrese elementos de B")
lstSalida2.AddItem (B(j))
Next j
End Sub
CADENAS
54. Private Sub cmdVerificar_Click()
Dim correo As String
Dim cant As Integer
Dim us As String ' nombre de usuario
Dim emp As String ' nombre de la empresa de correo
Dim pa As Integer ' posicion del @
Dim pp As Integer ' pocicion del punto
lstSalida.Clear

correo = txtEntrada.Text ' leer


pa = InStr(correo, "@")
pp = InStr(correo, ".")

If (pa > 0 And pp > pa) Then


lstSalida.AddItem (" si es un Correo valido")
cant = Len(correo) ' tamaño de la cadena
lstSalida.AddItem (cant & " Caracteres")
us = Left(correo, pa - 1) 'lee usuario
lstSalida.AddItem (us & " Usuario")
emp = Mid(correo, pa + 1, pp - pa - 1) 'LEE nombre de la EMPRESA
lstSalida.AddItem (emp & " Empresa")
Else
lstSalida.AddItem ("no es correo valido")
End If
End Sub

ARCHIVOS

55. Private Sub cmdMostrar_Click()


lstSalida.Clear
Dim linea As String

Open "c:\agenda.txt" For Input As #1


'Not EOF (1) controla que todas las lineas sean leidas
While (Not EOF(1))
Line Input #1, linea
lstSalida.AddItem (linea)
Wend
Close #1
End Sub

Private Sub cmdRegistrar_Click()


Dim linea As String
' abrimos el archivo para escribir
Open "c:\agenda.txt" For Append As #1
linea = InputBox("Ingrse Nombre-Telefono")
'se termina de escribir cuando lines = "ok"
While (linea <> "ok")
Print #1, linea
linea = InputBox("Ingres Nombre-Telefono")
Wend
Close #1
End Sub

56. Dim vt(1 To 100) As String


Dim linea As String
Dim i As Integer
Dim j As Integer

Private Sub cmdImporte_Click()


'mostrar reporte de un articulo
Dim nom As String
Dim sm As Integer
nom = InputBox("Ingrese Articulo")
sm = 0
Open "C:\importe.txt" For Append As #2
For i = 1 To j Step 1
nom1 = nombre(vt(i))

If (nom = nom1) Then


pc = precio(vt(i))
sm = sm + cantidad(vt(i))
End If
Next i
total = sm * pc
lstSalida2.AddItem (nom & ": " & total)
Print #2, nom & ": " & total
Close #2
End Sub
Function nombre(cadena As String) As String
Dim res As String
p = InStr(cadena, " ")
res = Left(cadena, p - 1)
nombre = res
End Function
Function cantidad(cadena As String) As Integer
Dim res As Integer
p1 = InStr(cadena, " ")
p2 = InStr(p1 + 1, cadena, " ")
res = Val(Mid(cadena, p1 + 1, p2 - p1 - 1))
cantidad = res
End Function
Function precio(cadena As String) As Integer
Dim res As Integer
p1 = InStr(cadena, " ")
p2 = InStr(p1 + 1, cadena, " ")
tm = Len(cadena)
res = Right(cadena, tm - p2)
precio = res
End Function

Private Sub cmdLeer_Click()


'Abrimos ventas.txt
Open "C:\ventas.txt" For Input As #1
j=0
While (Not EOF(1))
Line Input #1, linea
j=j+1
vt(j) = linea
lstSalida1.AddItem (vt(j))
Wend
Close #1

End Sub
57. Dim art(1 To 100) As String
Dim vt(1 To 1000) As String
Dim j As Integer
Dim k As Integer
Dim i As Integer
Dim linea As String

Private Sub cmdArticulos_Click()


lstSalida1.Clear
Open "C:\proy10\articulos.txt" For Input As #1
j = 0 'contador de articulos
While (Not EOF(1))
Line Input #1, linea
j=j+1
art(j) = linea
lstSalida1.AddItem (art(j))
Wend
Close #1
End Sub
Private Sub cmdVentas_Click()
lstSalida2.Clear
Open "C:\proy10\ventas.txt" For Input As #2
k=0
While (Not EOF(2))
Line Input #2, linea
k=k+1
vt(k) = linea
lstSalida2.AddItem (vt(k))
Wend
Close #2
End Sub
Private Sub cmdReporte_Click()
Dim pc As Integer
Dim sm As Integer
Dim total As Integer
Dim totalImportes As Integer

Open "C:\proy10\reporte.txt" For Output As #3


total = 0
For i = 1 To j Step 1 'recorre vector de articulos
cod1 = codigo(art(i))
pc = precio(art(i))
sm = 0
For m = 1 To k Step 1 ' recorre vector de ventas
cod2 = codigo(vt(m))
If (cod1 = cod2) Then
sm = sm + cantidad(vt(m))
End If
Next m
total = sm * pc
totalImportes = totalImportes + total 'suma todo los importes
lstSalida3.AddItem (cod1 & " : " & total & " Bs.")
Print #3, cod1 & ":" & total ' escribe en el archivo reporte.txt
Next i
Close #3
lblSalida.Caption = "Total es: " & totalImportes & " Bs."
End Sub

Function codigo(cadena As String) As String


Dim res As String
p = InStr(cadena, " ")
res = Left(cadena, p - 1)
codigo = res
End Function
Function cantidad(cadena As String) As Integer
Dim res As Integer
p1 = InStr(cadena, " ")
tm = Len(cadena)
res = Val(Right(cadena, tm - p1))
cantidad = res
End Function
Function precio(cadena As String) As Integer
Dim res As Integer
p1 = InStr(cadena, " ")
p2 = InStr(p1 + 1, cadena, " ")
tm = Len(cadena)
res = Val(Right(cadena, tm - p2))
precio = res
End Function

OTROS
58. Private Sub cmdPrimosG_Click()
Dim n1, n2 As Integer
Dim res As Boolean

n1 = txtNum1.Text
n2 = txtNum2.Text
MsgBox (n1 & " " & n2)
res = PrimosGemelos(n1, n2)
MsgBox (res)
If (res = True) Then
MsgBox ("Son Primos gemelos")
Else
MsgBox ("No son Primos gemelos")
End If
End Sub

Function PrimosGemelos(a, b) As Boolean


Dim res As Boolean
res = False
If ((primo(a) = True) And primo(b) = True) Then
If (a - b = 2 Or b - a = 2) Then
res = True
End If
End If
PrimosGemelos = res
End Function

Function primo(n) As Boolean


Dim cd As Integer

For i = 1 To n Step 1
If (n Mod i = 0) Then
cd = cd + 1
End If
Next i
If (cd = 2) Then
primo = True
Else
primo = False
End If

End Function

59. Dim cad As String

Private Sub cmdBuscar_Click()


Dim cb As String
Dim pos As Integer

cad = txtCadena.Text
cb = InputBox("ingrese la cadena a Buscar")
pos = InStr(cad, cb)
MsgBox ("la sub cadena inicia en: " & pos)
End Sub

Private Sub cmdDer_Click()


MsgBox ("3 de la der: " & Right(txtCadena.Text, 3))
End Sub

Private Sub cmdIzq_Click()


Dim aux As String
cad = txtCadena.Text
aux = Left(cad, 3)
MsgBox ("los 3 de la izquierda son: " & aux)
End Sub

Private Sub cmdMay_Click()


Dim mays As String
cad = txtCadena.Text
mays = UCase(cad) 'convierte a mayusculas
MsgBox ("la nueva cadena es: " & mays)
End Sub

Private Sub cmdMed_Click()


Dim aux As String
cad = txtCadena.Text
aux = Mid(cad, 7, 3)
MsgBox ("los 3:" & aux)
End Sub

Private Sub cmdProm_Click()


Dim ape As String
Dim p1, p2 As Integer
cad = txtCadena.Text
p1 = InStr(cad, " ")
p2 = InStr(p1 + 1, cad, " ")
ape = Mid(cad, p1 + 1, (p2 - 1) - p1)
MsgBox ("Ape" & ape & "99")
End Sub

Private Sub cmdTam_Click()


Dim tam As Integer
cad = txtCadena.Text
tam = Len(cad) 'obtiene el tamaño
MsgBox ("El tamaño es: " & tam)
End Sub

60. Private Sub cmdLeer_Click()

Open "D:/Archivo1.txt" For Input As #1


j=0
lstSalida1.Clear

While (Not EOF(1))


Line Input #1, linea
j=j+1
noms(j) = linea
lstSalida1.AddItem (noms(j))
Wend
cont = j 'obtiene cuantos elementos se cargaron al vector
Close #1

End Sub

Private Sub cmdMostrar_Click()


lstSalida2.Clear
For i = 1 To cont Step 1
lstSalida2.AddItem (noms(i))
Next i
End Sub

61. Dim alumnos(1 To 100) As String

Private Sub cmdAumentar_Click()

Dim cad As String

cad = txtCadena.Text

Open "D:/archivos/alumnos2.txt" For Append As #3

Print #3, cad


Close #3

End Sub

Private Sub cmdLeer_Click()

Dim i As Integer

i=1

lstSalida1.Clear

Open "D:/archivos/alumnos2.txt" For Input As #2

While (Not EOF(1))

Line Input #2, alumnos(i)

lstSalida1.AddItem (alumnos(i))

i=i+1

Wend

Close #2

End Sub

Private Sub cmdOutput_Click()

Open "D:\Archivos\alumnos.txt" For Output As #1

For i = 1 To 5 Step 1

Print #1, alumnos(i)

Next i

Close #1

End Sub
62. Dim pals(1 To 150) As String

Dim cont As Integer

Private Sub cmdGerigoncio_Click()

Dim geri As String

For i = 1 To cont Step 1

geri = geri & convGeri(pals(i)) & " "

Next i

txtGerigoncio.Text = geri

End Sub

Function convGeri(pal As String) As String

Dim np As String

Dim c As String

While (Len(pal) >= 1)

c = Left(pal, 1)

pal = Right(pal, Len(pal) - 1)

If (c = "a" Or c = "e" Or c = "i" Or c = "o" Or c = "u") Then

np = np + c & "p" & c

Else

np = np & c

End If

Wend
convGeri = np

End Function

Private Sub cmdLong3_Click()

lstsalida2.Clear

For i = 1 To cont Step 1

If (Len(pals(i)) >= 3) Then

lstsalida2.AddItem (pals(i))

End If

Next i

End Sub

Private Sub cmdNumericos_Click()

Dim cantidad As Integer

For i = 1 To cont Step 1

If (pals(i) = "0") Then 'si la palabra es cero lo contara

cantidad = cantidad + 1

End If

If (Val(pals(i)) <> 0) Then 'si la cadena tiene un valor numerico lo contara

cantidad = cantidad + 1 'val(cadena) si la canena no es numero retorna cero

End If

Next i
MsgBox ("la cantidad de caracteres numericos es :" & cantidad)

End Sub

Private Sub cmdPalMasCorta_Click()

Dim men As String

men = pals(1)

For i = 1 To cont Step 1

If (Len(pals(i)) < Len(men)) Then

men = pals(i)

End If

Next i

MsgBox ("la palabra de mayor longitus es :" & men & " tam: " & Len(men))

End Sub

Private Sub cmdPalMasLarga_Click()

Dim may As String

may = pals(1)

For i = 1 To cont Step 1

If (Len(pals(i)) > Len(may)) Then

may = pals(i)

End If

Next i

MsgBox ("la palabra de mayor longitus es :" & may & " tam: " & Len(may))

End Sub

Private Sub cmdSeparar_Click()

lstSalida1.Clear

If (Len(txtCadena.Text) <= 300) Then


Call separar(txtCadena.Text)

For i = 1 To cont Step 1

lstSalida1.AddItem (pals(i))

Next i

Else

MsgBox ("La cadena tiene mas de 300 Caracteres")

End If

End Sub

Sub separar(cad As String)

Dim pal As String

Dim p1 As Integer

cont = 0

While (InStr(cad, " ") <> 0) 'mientra exista un siguiente espacio en la cadena

p1 = InStr(cad, " ") ' posicion del siguiente espacio

pal = Left(cad, p1 - 1) ' obtiene la palabra

cont = cont + 1 ' se incrementa el contador de palabras

pals(cont) = pal ' se añade al vector de palabras

cad = Right(cad, Len(cad) - p1) ' modifica y obtiene la nueva cadena

Wend

cont = cont + 1 ' incrementa el contador de palbras

pals(cont) = cad ' añade la ultima palabra al vector de palabras


Dim cadena As String

Dim tam As Integer

Dim pals(1 To 300) As String

Dim i As Integer

Private Sub cmsSeparar_Click()

Dim cadAux As String

Dim pal As String

i=1

cadena = txtCadena.Text

cadAux = cadena

lstSalida1.Clear

While (cadAux <> " ")

i=i+1

If (InStr(cadAux, " ") <> 0) Then

pal = NextPal(cadAux)

cadAux = DelPal(cadAux)
Else

pal = cadAux

cadAux = " "

End If

pals(i) = pal

lstSalida1.AddItem (pal)

Wend

End Sub

Function NextPal(cadena As String) As String

Dim res As String

Dim p As Integer

p = InStr(cadena, " ")

res = Left(cadena, p - 1)

NextPal = res

End Function

Function DelPal(cadena As String) As String

Dim res As String

Dim p As Integer

tam = Len(cadena)

p = InStr(cadena, " ")

res = Right(cadena, tam - p)

DelPal = res

End Function
63. Dim c(1 To 100) As String

Dim a(1 To 100) As String

Dim linea As String

Dim i As Integer

Dim j As Integer

Dim k As Integer

Private Sub cmdAlgebra_Click()

Open "c:\algebra.txt" For Input As #2

k=0

lstSalida2.Clear

While (Not EOF(2))

Line Input #2, linea

k=k+1

a(k) = linea

lstSalida2.AddItem (a(k))

Wend

Close #2
End Sub

Private Sub cmdAprobados_Click()

Open "c:\aprobados.txt" For Output As #3

Dim nom, nom1 As String

Dim m As Integer

lstSalida3.Clear

For i = 1 To j Step 1

nom = nombre(c(i))

nota1 = nota(c(i))

MsgBox (nom & " " & nota1)

For m = 1 To k Step 1

nom1 = nombre(a(m))

nota2 = nota(a(m))

If (nom = nom1) Then

If (nota1 > 50 And nota2 > 50) Then

Print #3, nom

lstSalida3.AddItem (nom)

End If

End If

Next m

Next i

Close #3

End Sub

Function nombre(cadena As String) As String

Dim res As String

p1 = InStr(cadena, " ")


p2 = InStr(p1 + 1, cadena, " ")

tam = Len(cadena)

res = Left(cadena, p2 - 1)

nombre = res

End Function

Function nota(cadena As String) As Integer

Dim res As Integer

p1 = InStr(cadena, " ")

p2 = InStr(p1 + 1, cadena, " ")

tam = Len(cadena)

res = Val(Right(cadena, tam - p2))

nota = res

End Function

Private Sub cmdCalculo_Click()

Open "c:\calculo.txt" For Input As #1

j=0

lstSalida1.Clear

While (Not EOF(1))

Line Input #1, linea

j=j+1

c(j) = linea

lstSalida1.AddItem (c(j))

Wend

Close #1

End Sub
64. Private Sub cmdMostrar_Click()

Open "C:\archivos\Docentes.dat" For Input As #1 ' abre el archivo para lectura

i=0

lstSalida1.Clear

While (Not EOF(1)) 'mientra no se termine de leeer el archivo

i=i+1

Line Input #1, docentes(i) 'recupera el registro en el vector docentes

lstSalida1.AddItem (docentes(i))

Wend

nr = i 'nr el el numero de registros recuperados

Close #1

End Sub

Private Sub cmdMostrarDA_Click()

Dim contTD, contTA As Integer

contTD = 0

For i = 1 To nr Step 1

p1 = InStr(docentes(i), " ")

p2 = InStr(p1 + 1, docentes(i), " ")

p3 = InStr(p2 + 1, docentes(i), " ")

titulo = Right(docentes(i), Len(docentes(i)) - p3)


If (titulo = "Lic. Derecho") Then

contTD = contTD + 1

End If

Next i

contTA = 0

For i = 1 To nr Step 1

p1 = InStr(docentes(i), " ")

p2 = InStr(p1 + 1, docentes(i), " ")

p3 = InStr(p2 + 1, docentes(i), " ")

titulo = Right(docentes(i), Len(docentes(i)) - p3)

If (titulo = "Lic. Auditoria") Then

contTA = contTA + 1

End If

Next i

MsgBox ("son " & contTD & " con titulo en Lic. Derecho")

MsgBox ("son " & contTA & " con titulo en Lic. Auditoria")

End Sub

65. Private Sub cmdMostrar_Click()

Open "C:/archivos/entrada.dat" For Input As #1

j=0
lstSalida1.Clear

While (Not EOF(1))

Line Input #1, linea

j=j+1

ent(j) = linea

lstSalida1.AddItem (ent(j))

Wend

cont = j 'obtiene cuantos elementos se cargaron al vector

Close #1

End Sub

Private Sub cmdOrdenar_Click()

Dim cad As String

For i = 1 To cont Step 1

For j = i To cont - 1 Step 1

If (titulo(ent(i)) > titulo(ent(j + 1))) Then

aux = ent(i)

ent(i) = ent(j + 1)

ent(j + 1) = aux

End If

Next j

Next i

lstSalida4.Clear

For i = 1 To 5 Step 1

cad = ent(i)

lstSalida4.AddItem (cad)
Next i

End Sub

Private Sub cmdTitulos_Click()

Dim tit As String

Dim cad As String

lstSalida2.Clear

For i = 1 To cont Step 1

cad = ent(i)

tit = titulo(cad)

lstSalida2.AddItem (tit)

Next i

End Sub

Function titulo(cad As String)

Dim p1, p2 As Integer

Dim pal As String

p1 = InStr(cad, " ") 'obtiene la posicion del 1er espacio

p2 = InStr(p1 + 1, cad, " ") 'obtiene la posicion del 2do espacio

pal = Mid(cad, p1 + 1, (p2 - 1) - p1) 'obt la segunda palabra

titulo = pal

End Function

You might also like