Trabajo de Programas

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

Arreglo simple:

Public Class Form1



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim ArrA(3, 4) As Integer
Dim ArrB(3, 4) As Integer
Dim ArrD(3, 4) As Integer
Dim suma As Integer
Dim F, C As Integer
Dim sr As IO.StreamReader = IO.File.OpenText("arreglo3.txt")

'leer Arreglo A

For F = 1 To 3
For C = 1 To 4
ArrA(F, C) = Sr.Readline
Next

Next

For F = 1 To 3
For C = 1 To 4
ArrB(F, C) = sr.ReadLine
Next

Next

For F = 1 To 3
For C = 1 To 4
ArrD(F, C) = ArrB(F, C) + ArrD(F, C)
Next
Next
ListBox1.Items.Add("ArregloA")
For F = 1 To 3
ListBox1.Items.Add(ArrA(F, 1) & " " & ArrA(F, 2) & " " & ArrA(F, 3))
Next
ListBox1.Items.Add("ArregloB")
For F = 1 To 3
ListBox1.Items.Add(ArrB(F, 1) & " " & ArrB(F, 2) & " " & ArrB(F, 3))
Next
ListBox1.Items.Add("ArregloD")
For F = 1 To 3
ListBox1.Items.Add(ArrD(F, 1) & " " & ArrD(F, 2) & " " & ArrD(F, 3))
Next
End Sub
End Class

















Arreglo con Archivo :

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim sr As IO.StreamReader = IO.File.OpenText("notas.txt")
Dim arreglo(10) As Double
Dim I, sum, promedio As Double
For I = 1 To 10
arreglo(I) = sr.ReadLine
sum = sum + arreglo(I)
Next
promedio = sum / 10
ListBox1.Items.Add("el promedio es " & promedio)
End Sub
End Class













Calcular Prestamo :



Public Class Form1

Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Label6.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

End Sub

Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
'update label apr when scroll moved
Label3.Text = HScrollBar1.Value * 0.01
End Sub

Private Sub HScrollBar2_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HScrollBar2.Scroll
'update label years when scroll moved
Label5.Text = HScrollBar2.Value
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim Monthlypayment As Double
'if amount is not a number,then message,else perform calculations
If IsNumeric(TextBox1.Text) = False Then
MsgBox("please enter loan amount in numbers only", 48, "warning")
TextBox1.Text = " "
TextBox1.Focus() 'ubicar el cursar
Else
Monthlypayment = Pmt(0.0001 * HScrollBar1.Value / 12, HScrollBar2.Value * 12,
-1 * TextBox1.Text, 0, 1)

Label6.Text = Format$(Monthlypayment, "currency")
Label7.Text = Format$(Monthlypayment * HScrollBar2.Value * 12, "currency")
Label8.Text = Format$(Label7.Text - TextBox1.Text, "currency")



End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
TextBox1.Text = ""
Label6.Text = ""
Label7.Text = ""
Label8.Text = ""
End Sub



Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
Me.Close()
End Sub











Pelicula:

Public Class Form1

Private Sub Radio1_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Radio1.CheckedChanged
Dim price As Double
Dim num As Integer
num = 1
If Chkdisc.Checked = True Then
price = 3.5
Else
price = 5
End If
lblprecioTextBox.Text = Format$(num * price, "currency")
End Sub

Private Sub Radio2_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Radio2.CheckedChanged
Dim price As Double
Dim num As Integer
num = 2
If Chkdisc.Checked = True Then
price = 3.5
Else
price = 5
End If
lblprecioTextBox.Text = Format$(num * price, "currency")
End Sub

Private Sub Radio3_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Radio3.CheckedChanged
Dim price As Double
Dim num As Integer
num = 3
If Chkdisc.Checked = True Then
price = 3.5
Else
price = 5
End If
lblprecioTextBox.Text = Format$(num * price, "currency")
End Sub

Private Sub Radio4_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Radio4.CheckedChanged
Dim price As Double
Dim num As Integer
num = 4
If Chkdisc.Checked = True Then
price = 3.5
Else
price = 5
End If
lblprecioTextBox.Text = Format$(num * price, "currency")
End Sub

Private Sub Radio5_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Radio5.CheckedChanged
Dim price As Double
Dim num As Integer
num = 5
If Chkdisc.Checked = True Then
price = 3.5
Else
price = 5
End If
lblprecioTextBox.Text = Format$(num * price, "currency")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If ComboBox1.Text = "selecciona Pelicula" Then
MsgBox("no ha seleccionado pelicula", , "aviso")
Else
ListBox1.Items.Add(ComboBox1.Text & " " & lblprecioTextBox.Text &
vbNewLine)
Chkdisc.Checked = False
Radio1.Checked = False
Radio2.Checked = False
Radio3.Checked = False
Radio4.Checked = False
Radio5.Checked = True
Labelprecio.Text = " "
ComboBox1.Text = "selecciona pelicula"
End If

End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ListBox1.SelectedIndexChanged

End Sub
End Class
























Subrutina Informe de Ventas:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
ListBox1.Items.Clear()
'dim sr as io.streamreader=io.file.opentext("inventgario.txt")
Dim fmtstr As String = "{0,-20}{1,10}"
Dim total, cantidad As Double
Dim departamento As String

ListBox1.Items.Add(" Informe de ventas ")
ListBox1.Items.Add("")
ListBox1.Items.Add(String.Format(fmtstr, "Departamento", " cantidad "))
leer(departamento, cantidad, total)

ListBox1.Items.Add("total es " & FormatCurrency(total, 2))

End Sub

Sub leer(ByRef departamento As String, ByRef cantidad As Double, ByRef total As Double)
Dim sr As IO.StreamReader = IO.File.OpenText("informedeventas.txt ")
Do While sr.Peek <> -1
departamento = sr.ReadLine
cantidad = sr.ReadLine
calcular(cantidad, total)
imprimir(departamento, cantidad)
Loop

End Sub
Sub calcular(ByRef cantidad As Double, ByRef total As Double)
total = total + cantidad
End Sub
Sub imprimir(ByVal departamento As String, ByVal cantidad As Double)
Dim fmtstr As String = "{0,-20}{1,10}"
ListBox1.Items.Add(String.Format(fmtstr, departamento, FormatNumber(cantidad,0)))
End Sub

End Class



















Mantenimiento de archivos secuencias:


Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim msg As String
If (txtname.text <> "") And (txtyear.text <> "") Then
Dim sw As IO.StreamWriter = IO.File.AppendText("file.txt")
sw.WriteLine(txtname.text)
sw.WriteLine(txtyear.Text)
sw.Close()
txtname.Clear()
txtyear.Clear()
txtname.Focus()
Else
msg = "You must enter a name and year of birth"
MsgBox(msg, , "Information Incomplete")
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Dim msg As String
If txtname.Text <> "" Then
If IO.File.Exists("file.txt") Then
displayYEAR()
Else
msg = "Either no file has yet been created or"
msg = msg & "the file is nowhere to be found"
MsgBox(msg, , "File not found")
End If
Else
MsgBox("You must enter a name.", , "Information Incomplete")
End If
txtname.Focus()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
Dim msg As String
If txtname.Text <> "" Then
If IO.File.Exists("file.txt") Then
DeletePERSON()
Else
msg = "Either no file has yet been created or"
msg = msg & "the file is nowhere expected"
MsgBox(msg, , "File not found")
End If
Else
MsgBox("You must enter a name.", , "Information Incomplete")
End If
End Sub
Sub DisplayYEAR()
Dim name As String, yob As Integer
txtyear.Clear()
Dim sr As IO.StreamReader = IO.File.OpenText("file.txt")
Do While (name <> txtname.Text) And (sr.Peek <> -1)
name = sr.ReadLine
yob = CInt(sr.ReadLine)
Loop
If name = txtname.Text Then
MsgBox(name & " was born in " & yob, , "Name Found")
txtname.Clear()
txtyear.Clear()
Else
MsgBox("Person is not in file.", , "")
txtname.Clear()
End If
sr.Close()
End Sub
Sub DeletePERSON()
Dim name As String, yob As Integer
Dim flag As Boolean = False
Dim sr As IO.StreamReader = IO.File.OpenText("file.txt")
Dim sw As IO.StreamWriter = IO.File.CreateText("temp.txt")
Do While (sr.Peek <> -1)
name = sr.ReadLine
yob = CInt(sr.ReadLine)
If (name <> txtname.Text) Then
sw.WriteLine(name)
sw.WriteLine(yob)
Else
flag = True
End If
Loop
sr.Close()
sw.Close()
IO.File.Delete("file.txt")
IO.File.Move("temp.txt", "file.txt")
If Not flag Then
MsgBox("The name was not found.", , "")
Else
txtname.Clear()
txtyear.Clear()
End If
End Sub
End Class



















Instituto Tecnolgico de Guayama
Guayama, P.R.







Richmarie Pica Amaro
Sistema de Informacin
Prof.Carlos Rivera
Visual Basic

You might also like