30ejercicios de Archivos

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

1.

APORTE DE VENTAS

Dim art(100) As String List2.Clear


Dim ven(100) As String Open "c:/aprobados.txt" For Output As #2
Private Sub Command1_Click() For i = 1 To nr Step 1
List1.Clear ap = a(i)
Open "c:/articulos.txt" For Input As #1 If (ap <= 100) And (ap >= 0) Then
j=0 If (ap >= 51) Then
While (Not EOF(1)) List2.AddItem a(i)
Line Input #1, linea End If
j=j+1 End If
art(j) = linea Next
List1.AddItem art(j) Close #2
Wend End Sub
Close #1
End Sub 3.INGRESAR NOMBRE A BUSCAR

Private Sub Command2_Click() Dim a(100) As String


List2.Clear Dim nr As Integer
Open "c:/ventas.txt" For Input As #2
j=0 Private Sub Command1_Click()
While (Not EOF(2)) Open "c:/nombres.txt" For Input As #1
Line Input #2, linea i=1
j=j+1 While Not (EOF(1))
ven(j) = linea Input #1, a(i)
List2.AddItem ven(j) List1.AddItem a(i)
Wend i=i+1
Close #2 Wend
End Sub nr = i - 1
Close #1
2.CALCULO DE APROBADOS End Sub

Dim a(100) As String Private Sub Command2_Click()


Dim nr As Integer Dim n As String
Private Sub Command1_Click() n = Text1.Text
List1.Clear For i = 1 To nr Step 1
Open "c:/algebra.txt" For Input As #1 aux = a(i)
i=0 pb = InStr(aux, " ")
While (Not EOF(1)) nom = Left(aux, pb - 1)
Line Input #1, linea If (UCase(nom) = UCase(n)) Then
i=i+1 List2.AddItem a(i)
nr = i End If
a(i) = linea Next
List1.AddItem (a(i)) End Sub
Wend
Close #1
End Sub

Private Sub Command2_Click()


4.TELEFONOS NOMBRES CON A List2.AddItem a(i)
Dim a(100) As String Else
Dim nr As Integer List3.AddItem a(i)
Private Sub Command1_Click() End If
Open "c:/TEL.txt" For Input As #1 End Sub
i=1
While Not (EOF(1)) 6.CODIGO SIS 2013
Input #1, a(i)
List1.AddItem a(i) Dim a(100) As String
i=i+1 Dim nr As Integer
Wend Private Sub Command1_Click()
nr = i - 1 Open "c:/COD.SIS.txt" For Input As #1
Close #1 i=1
End Sub While Not (EOF(1))
Input #1, a(i)
Private Sub Command2_Click() List1.AddItem a(i)
Open "c:/NOM.A" For Output As #2 i=i+1
For i = 1 To nr Step 1 Wend
pb = InStr(a(i), " ") nr = i - 1
cod = Left(a(i), pb - 1) Close #1
aux = Mid(a(i), pb + 1, Len(a(i)) - pb) End Sub
nom = Left(aux, 1)
If LCase(nom) = "A" Then Private Sub Command2_Click()
List2.AddItem nom For i = 1 To nr Step 1
Print #2, a(i) cod = Left(a(i), 4)
End Sub If (Val(cod) = Val(2013)) Then
List2.AddItem a(i)
5.APROBADOS Y REPROBADOS End If
Dim a(100) As String Next
Dim nr As Integer End Sub
Private Sub Command1_Click()
Open "c:/algebra.txt" For Input As #1 7.CODSIS,NOM,APP,APM
i=1 Dim a(10) As String
While Not (EOF(1)) Dim nr As Integer
Input #1, a(i) Private Sub Command1_Click()
List1.AddItem a(i) Open "c:/datos.txt" For Input As #1
i=i+1 i=1
Wend While Not (EOF(1))
nr = i - 1 Input #1, a(i)
Close #1 List1.AddItem a(i)
End Sub i=i+1
Wend
Private Sub Command2_Click() nr = i - 1
Open "c:/aprobados" For Output As #2 Close #1
For i = 1 To nr Step 1 End Sub
pb = InStr(a(i), " ")
nom = Left(a(i), pb - 1) Private Sub Command2_Click()
nota = Mid(a(i), pb + 1, Len(a(i)) - pb) Open "c:/ape.conM" For Output As #2
If (Val(nota) >= 51) Then codsis = InputBox("codigo a buscar")
For i = 1 To nr Step 1
pb = InStr(a(i), " ") 9.REPORTE DE VENTAS
cod = Left(a(i), pb - 1) Dim vt(100) As String
aux = Mid(a(i), pb + 1, Len(a(i)) - pb) Dim linea As String
pb = InStr(aux, " ")
nom = Left(aux, pb - 1) Private Sub Command1_Click()
aux = Mid(aux, pb + 1, Len(aux) - pb) Open "c:/ventas.txt" For Input As #1
cc = Left(aux, 1) j=0
If LCase(cc) = "m" Then While (Not EOF(1))
List2.AddItem nom Line Input #1, linea
Print #2, a(i) j=j+1
End If vt(j) = linea
Next i List1.AddItem vt(j)
Close #2 Wend
End Sub Close #1
End Sub
8.ESCRIBIR Y LEER UN ARCHIVO
Dim a(10) As String Private Sub Command2_Click()
Dim nr As Integer Dim nom As String
Private Sub Command1_Click() Dim sm As Integer
Open "c:/datos.txt" For Input As #1 nom = InputBox("ingrese articulo")
i=1 sm = 0
While Not (EOF(1)) Open "c:/importe.txt" For Append As #2
Input #1, a(i) For i = 1 To j Step 1
List1.AddItem a(i) nom1 = nombre(vt(i))
i=i+1 If (nom = nom1) Then
Wend pc = precio(vt(i))
nr = i - 1 sm = sm + cantidad(vt(i))
Close #1 End If
End Sub Next i
total = sm * pc
Private Sub Command2_Click() List2.AddItem nom & " : " & total
Open "c:/ape.conM" For Output As #2 Print #2, nom & " : " & total
codsis = InputBox("codigo a buscar") Close #2
For i = 1 To nr Step 1 End Sub
pb = InStr(a(i), " ") Function nombre(cadena As String) As String
cod = Left(a(i), pb - 1) Dim res As String
aux = Mid(a(i), pb + 1, Len(a(i)) - pb) p = InStr(cadena, " ")
pb = InStr(aux, " ") res = Left(cadena, p - 1)
nom = Left(aux, pb - 1) nombre = res
aux = Mid(aux, pb + 1, Len(aux) - pb) End Function
cc = Left(aux, 1) Function cantidad(cadena As String) As Integer
If LCase(cc) = "m" Then Dim res As Integer
List2.AddItem nom p1 = InStr(cadena, " ")
Print #2, a(i) p2 = InStr(p1 + 1, cadena, " ")
End If res = Val(Mid(cadena), p1 + 1, p2 - p1 - 1)
Next i cantidad = res
Close #2 End Function
End Sub Function precio(cadena As String) As Integer
Dim res As Integer nr = i - 1
p1 = InStr(cadena, " ") Close #1
p2 = InStr(p1 + 1, cadena, " ") End Sub
tm = Len(cadena)
res = Right(cadena, tm - p2) Private Sub Command2_Click()
precio = res For i = 1 To nr Step 1
End Function If (a(i) Mod 2 = 0) Then
List2.AddItem a(i)
10.LA MEDIA End If
Dim a(10) As String Next
Dim nr As Integer End Sub
Private Sub Command1_Click()
Open "c:/numeros.txt" For Input As #1 Private Sub Command3_Click()
i=1 End
While Not (EOF(1)) End Sub
Input #1, a(i)
List1.AddItem a(i) 12.LOS PRIMOS QUE SE ENCUENTRAN
i=i+1 SON
Wend Dim a(10) As String
nr = i - 1 Dim nr As Integer
Close #1 Private Sub Command1_Click()
End Sub Open "c:/numeros.txt" For Input As #1
i=1
Private Sub Command2_Click() While Not (EOF(1))
Dim media As Integer Input #1, a(i)
s=s+1 List1.AddItem a(i)
For i = 1 To nr Step 1 i=i+1
s = s + a(i) Wend
Next i nr = i - 1
media = s / nr Close #1
Label1.Caption = "Hay " & nr & " numeros y la End Sub
Media es : " & media
End Sub Private Sub Command2_Click()
Dim c As Integer
Private Sub Command3_Click() Dim num As Integer
End c=0
End Sub For i = 1 To nr Step 1
num = a(i)
11.LOS PARES QUE SE ENCUENTRAN SON If (primo(num) = True) Then
Dim a(10) As String List2.AddItem a(i)
Dim nr As Integer c=c+1
Private Sub Command1_Click() End If
Open "c:/numeros.txt" For Input As #1 Next
i=1 List2.AddItem "Hay " & c & " primos"
While Not (EOF(1)) End Sub
Input #1, a(i)
List1.AddItem a(i) Private Sub Command3_Click()
i=i+1 End
Wend End Sub
Function primo(n As Integer) As Boolean Private Sub Command1_Click()
Dim res As Boolean List1.Clear
res = False Open "c:/numeros.txt" For Input As #1
cd = 0 i=1
For i = 1 To n Step 1 While Not (EOF(1))
If (n Mod i = 0) Then Input #1, a(i)
cd = cd + 1 List1.AddItem a(i)
End If i=i+1
Next Wend
If (cd = 2) Then nr = i - 1
res = True Close #1
End If End Sub
primo = res
End Function Private Sub Command2_Click()
Dim c As Integer
13.NUMERO MAYOR Dim num As Integer
Dim a(10) As String c=0
Dim nr As Integer For i = 1 To nr Step 1
Private Sub Command1_Click() num = a(i)
Open "c:/numeros.txt" For Input As #1 If (num > 0) Then
i=1 List2.AddItem a(i)
While Not (EOF(1)) c=c+1
Input #1, a(i) End If
List1.AddItem a(i) Next
i=i+1 List2.AddItem "Hay " & c & " numeros
Wend positivos"
nr = i - 1 End Sub
Close #1
End Sub Private Sub Command3_Click()
men = a(1)
Private Sub Command2_Click() For i = 1 To nr Step 1
may = a(1) If (a(i) < men) Then
For i = 2 To nr Step 1 men = a(i)
pal = a(i) End If
If pal > may Then Next
may = a(i) Label2.Caption = "El numero menor es : " &
End If men
Next i End Sub
Label1.Caption = "Hay " & nr & " numeros y el
mayor es : " & may Private Sub Command4_Click()
End Sub End
End Sub
Private Sub Command3_Click()
End 15.NEGATIVOS PARES MAYOR
End Sub Dim a(100) As String
Dim nr As Integer
14.POS. NUMERO MENOR Private Sub Command1_Click()
Dim a(100) As String List1.Clear
Dim nr As Integer Open "c:/numeros.txt" For Input As #1
i=1 End
While Not (EOF(1)) End Sub
Input #1, a(i)
List1.AddItem a(i) 16.POS. PARES IMPARES
i=i+1 Dim a(100) As String
Wend Dim nr As Integer
nr = i - 1 Private Sub Command1_Click()
Close #1 List1.Clear
End Sub Open "c:/numeros.txt" For Input As #1
i=1
Private Sub Command2_Click() While Not (EOF(1))
Dim c As Integer Input #1, a(i)
Dim num As Integer List1.AddItem a(i)
c=0 i=i+1
For i = 1 To nr Step 1 Wend
num = a(i) nr = i - 1
If (num < 0) Then Close #1
c=c+1 End Sub
End If
Next Private Sub Command2_Click()
Label1.Caption = "Hay " & c & " numeros For i = 2 To nr Step 2
negativos" List2.AddItem a(i)
End Sub Next
End Sub
Private Sub Command3_Click()
Dim men As Integer Private Sub Command3_Click()
Dim cp As Integer For i = 1 To nr Step 2
cp = 0 List3.AddItem a(i)
For i = 1 To nr Step 1 Next
If (a(i) Mod 2 = 0) Then End Sub
cp = cp + 1
End If Private Sub Command4_Click()
Next End
Label2.Caption = "Hay " & cp & " numeros End Sub
pares"
End Sub 17.POS Y NEG, MAY Y MEN

Private Sub Command4_Click() Dim a(100) As String


men = a(1) Dim nr As Integer
For i = 1 To nr Step 1 Private Sub Command1_Click()
If (a(i) < men) Then List1.Clear
men = a(i) Open "c:/numeros.txt" For Input As #1
End If i=1
Next While Not (EOF(1))
Label3.Caption = "El numero menor es : " & Input #1, a(i)
men List1.AddItem a(i)
End Sub i=i+1
Wend
Private Sub Command5_Click() nr = i - 1
Close #1 i=1
End Sub While Not (EOF(1))
Input #1, a(i)
Private Sub Command2_Click() List1.AddItem a(i)
men = a(1) i=i+1
may = a(1) Wend
For i = 1 To nr Step 1 nr = i - 1
If (a(i) < men) Then Close #1
men = a(i) End Sub
End If
If (a(i) > may) Then Private Sub Command2_Click()
may = a(i) may = a(1)
End If For i = 1 To nr Step 1
Next If (Len(a(i)) > Len(may)) Then
Label1.Caption = "El numero mayor es : " & may = a(i)
may End If
Label2.Caption = "El numero menor es : " & Next
men Label1.Caption = "La palabra mas larga es : " &
End Sub may
Label2.Caption = "Tiene " & Len(may) & "
Private Sub Command3_Click() caracteristica"
Dim c, ci As Integer End Sub
Dim num As Integer
c=0 Private Sub Command3_Click()
ci = 0 End
For i = 1 To nr Step 1 End Sub
num = a(i)
If (num > 0) Then 19.LA PALABRA MAS LARGA INVERTIDA
c=c+1 ES
Else Dim a(100) As String
ci = ci + 1 Dim nr As Integer
End If Private Sub Command1_Click()
Next List1.Clear
Label3.Caption = "Hay " & c & " numeros Open "c:/nombres.txt" For Input As #1
positivos" i=1
Label4.Caption = "Hay " & ci & " numeros While Not (EOF(1))
negativos" Input #1, a(i)
End Sub List1.AddItem a(i)
i=i+1
Private Sub Command4_Click() Wend
End nr = i - 1
End Sub Close #1
End Sub
18.PAL MAYOR
Dim a(100) As String Private Sub Command2_Click()
Dim nr As Integer Dim invmay As String
Private Sub Command1_Click() Dim may As String
List1.Clear may = a(1)
Open "c:/nombres.txt" For Input As #1 For i = 1 To nr Step 1
If (Len(a(i)) > Len(may)) Then End Sub
may = a(i)
invmay = may Private Sub Command3_Click()
End If End
Next End Sub
invmay = may Function invertirCadena(c As String) As String
inv = invertirCadena(invmay) Dim res As String
Label1.Caption = "La palabra mas larga es : " & res = ""
may While (Len(c) > 0)
Label3.Caption = inv res = res & Right(c, 1)
End Sub c = Left(c, Len(c) - 1)
Wend
Private Sub Command4_Click() invertirCadena = res
End End Function
End Sub
Function invertirCadena(c As String) As String 21.LA PALABRA MAS CORTA INVERTIDA
Dim res As String ES
res = "" Dim a(100) As String
While (Len(c) > 0) Dim nr As Integer
res = res & Right(c, 1) Private Sub Command1_Click()
c = Left(c, Len(c) - 1) List1.Clear
Wend Open "c:/nombres.txt" For Input As #1
invertirCadena = res i=1
End Function While Not (EOF(1))
Input #1, a(i)
20.NOMBRES LEIDO AL REVES List1.AddItem a(i)
Dim a(100) As String i=i+1
Dim nr As Integer Wend
Private Sub Command1_Click() nr = i - 1
List1.Clear Close #1
Open "c:/nombres.txt" For Input As #1 End Sub
i=1
While Not (EOF(1)) Private Sub Command2_Click()
Input #1, a(i) Dim invmen As String
List1.AddItem a(i) Dim men As String
i=i+1 men = a(1)
Wend For i = 1 To nr Step 1
nr = i - 1 If (Len(a(i)) < Len(men)) Then
Close #1 men = a(i)
End Sub End If
Next
Private Sub Command2_Click() invmen = men
Dim n As String inv = invertirCadena(invmen)
Dim p As String Label1.Caption = "La palabra mas corta es : " &
For i = 1 To nr Step 1 men
n = a(i) Label3.Caption = inv
p = invertirCadena(n) End Sub
List2.AddItem p
Next Private Sub Command3_Click()
End End Sub
End Sub Function invertirCadena(c As String) As String
Function invertirCadena(c As String) As String Dim res As String
Dim res As String res = ""
res = "" While (Len(c) > 0)
While (Len(c) > 0) res = res & Right(c, 1)
res = res & Right(c, 1) c = Left(c, Len(c) - 1)
c = Left(c, Len(c) - 1) Wend
Wend invertirCadena = res
invertirCadena = res End Function
End Function
23.APRLLIDO CON M INVERTIDO
22.REGISTRAR MOSTRAR INVERTIR Dim a(100) As String
Dim a(100) As String Dim nr As Integer
Dim nr As String
Private Sub Command1_Click() Private Sub Command1_Click()
Open "c:/prueba.txt" For Append As #1 Open "c:/nombres.txt" For Input As #1
Dim linea As String i=1
linea = " " While Not (EOF(1))
While (Not linea Like "salir") Input #1, a(i)
Print #1, linea List1.AddItem a(i)
linea = InputBox("escriba y presione aceptar,para i=i+1
terminar escriba salir") Wend
Wend nr = i - 1
Close #1 Close #1
End Sub End Sub

Private Sub Command2_Click() Private Sub Command2_Click()


Open "c:/prueba.txt" For Input As #1 Dim invm As String
List1.Clear For i = 1 To nr Step 1
i=0 pb = InStr(a(i), " ")
While (Not EOF(1)) nom = Left(a(i), pb - 1)
Line Input #1, linea ape = Mid(a(i), pb + 1, Len(a(i)) - pb)
i=i+1 cc = Left(ape, 1)
a(i) = linea If LCase(cc) = "m" Then
List1.AddItem a(i) List2.AddItem ape
Wend invm = ape
nr = i inv = invertirCadena(invm)
Close #1 List3.AddItem inv
End Sub End If
Next i
Private Sub Command3_Click() End Sub
Dim invc As String Function invertirCadena(c As String) As String
List2.Clear Dim res As String
For i = 1 To nr Step 1 res = ""
invc = a(i) While (Len(c) > 0)
inv = invertirCadena(invc) res = res & Right(c, 1)
List2.AddItem inv c = Left(c, Len(c) - 1)
Next Wend
invertirCadena = res i=i+1
End Function a(i) = linea
List1.AddItem a(i)
24.NUMEROS DE TELEFONOS Wend
INVERTIDOS nr = i
Dim a(100) As String Close #1
Dim nr As String End Sub
Private Sub Command1_Click()
Open "c:/telefonos.txt" For Input As #1 Private Sub Command2_Click()
List1.Clear Dim c As Integer
i=0 Dim invm As String
While (Not EOF(1)) c=0
Line Input #1, linea For i = 1 To nr Step 1
i=i+1 c = c + a(i)
a(i) = linea Next
List1.AddItem a(i) invm = c
Wend inv = invertirCadena(invm)
nr = i Label1.Caption = "La suma total es de : " & c
Close #1 Label2.Caption = "El invertido de la suma total
End Sub es : " & inv
End Sub
Private Sub Command2_Click() Function invertirCadena(c As String) As String
Dim invc As String Dim res As String
List2.Clear res = ""
For i = 1 To nr Step 1 While (Len(c) > 0)
invc = a(i) res = res & Right(c, 1)
inv = invertirCadena(invc) c = Left(c, Len(c) - 1)
List2.AddItem inv Wend
Next invertirCadena = res
End Sub End Function
Function invertirCadena(c As String) As String
Dim res As String 26.MULTIPLICACION Y SUMA
res = "" Dim a(100) As String
While (Len(c) > 0) Dim nr As String
res = res & Right(c, 1) Private Sub Command1_Click()
c = Left(c, Len(c) - 1) Open "c:/numeros.txt" For Input As #1
Wend List1.Clear
invertirCadena = res i=0
End Function While (Not EOF(1))
Line Input #1, linea
25.SUMA i=i+1
Dim a(100) As String a(i) = linea
Dim nr As String List1.AddItem a(i)
Private Sub Command1_Click() Wend
Open "c:/numeros.txt" For Input As #1 nr = i
List1.Clear Close #1
i=0 End Sub
While (Not EOF(1))
Line Input #1, linea Private Sub Command2_Click()
Dim invm As String nr = i
c=1 Close #1
For i = 1 To nr Step 1 End Sub
c = c * a(i) Private Sub Command2_Click()
Next Dim invc As String
invm = c List2.Clear
inv = invertirCadena(invm) For i = 1 To nr Step 1
Label1.Caption = "La multiplicacion total es invc = a(i)
de : " & c inv = invertirCadena(invc)
Label2.Caption = "El invertido de la List2.AddItem inv
multiplicacion total es : " & inv Next
End Sub End Sub
Function invertirCadena(c As String) As String Function invertirCadena(c As String) As String
Dim res As String Dim res As String
res = "" res = ""
While (Len(c) > 0) While (Len(c) > 0)
res = res & Right(c, 1) res = res & Right(c, 1)
c = Left(c, Len(c) - 1) c = Left(c, Len(c) - 1)
Wend Wend
invertirCadena = res invertirCadena = res
End Function End Function

Private Sub Command3_Click() 28.MULTIPLICACION


Dim c As Integer Dim a(100) As String
Dim invm As String Dim nr As String
c=0 Private Sub Command1_Click()
For i = 1 To nr Step 1 Open "c:/numeros.txt" For Input As #1
c = c + a(i) List1.Clear
Next i=0
invm = c While (Not EOF(1))
inv = invertirCadena(invm) Line Input #1, linea
Label3.Caption = "La suma total es de : " & c i=i+1
Label4.Caption = "El invertido de la suma total a(i) = linea
es : " & inv List1.AddItem a(i)
End Sub Wend
nr = i
27.MAS DE UN DIGITO INVERTIR Close #1
Dim a(100) As String End Sub
Dim nr As String
Private Sub Command1_Click() Private Sub Command2_Click()
Open "c:/numeros.txt" For Input As #1 Dim invm As String
List1.Clear c=1
i=0 For i = 1 To nr Step 1
While (Not EOF(1)) c = c * a(i)
Line Input #1, linea Next
i=i+1 invm = c
a(i) = linea inv = invertirCadena(invm)
List1.AddItem a(i) Label1.Caption = "La multiplicacion total es
Wend de : " & c
Label2.Caption = "El invertido de la i=1
multiplicacion total es : " & inv While Not (EOF(1))
End Sub Input #1, a(i)
Function invertirCadena(c As String) As String List1.AddItem a(i)
Dim res As String i=i+1
res = "" Wend
While (Len(c) > 0) nr = i - 1
res = res & Right(c, 1) Close #1
c = Left(c, Len(c) - 1) End Sub
Wend
invertirCadena = res Private Sub Command2_Click()
End Function Open "c:/aprobados" For Output As #2
For i = 1 To nr Step 1
29. BUSCAR NOMBRE pb = InStr(a(i), " ")
Dim a(100) As String nom = Left(a(i), pb - 1)
Dim nr As Integer nota = Mid(a(i), pb + 1, Len(a(i)) - pb)
If (Val(nota) >= 51) Then
Private Sub Command1_Click() List2.AddItem a(i)
Open "c:/nombres.txt" For Input As #1 Else
i=1 List3.AddItem a(i)
While Not (EOF(1)) End If
Input #1, a(i) End Sub
List1.AddItem a(i)
i=i+1
Wend
nr = i - 1
Close #1
End Sub

Private Sub Command2_Click()


Dim n As String
n = Text1.Text
For i = 1 To nr Step 1
aux = a(i)
pb = InStr(aux, " ")
nom = Left(aux, pb - 1)
If (UCase(nom) = UCase(n)) Then
List2.AddItem a(i)
Else
List2.AddItem "No existe"
End If
Next
End Sub

30. APROBADOS Y REPROBADOS


Dim a(100) As String
Dim nr As Integer
Private Sub Command1_Click()
Open "c:/algebra.txt" For Input As #1

You might also like