You are on page 1of 3

Práctica 7a: USO DE FUNCIONES Y SUB RUTINAS

_____________________________________________________________________

Public Class Form1


Dim ndatos As Integer
Dim Tc As Single
Dim pc As Single
Dim v(1000) As Single
Dim t(1000) As Single
Dim p(1000) As Single
Dim medv As Single
Dim medt As Single
Dim medp As Single
Dim dsv As Single
Dim dst As Single
Dim dsp As Single
Dim a As Single
Dim b As Single
_____________________________________________________________________

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
ingresar()
End Sub
_____________________________________________________________________

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
calcular()
End Sub
_____________________________________________________________________

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Media_ds()
End Sub
_____________________________________________________________________

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
limpiar()
End Sub
_____________________________________________________________________

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
End
End Sub

_____________________________________________________________________
Sub ingresar()
ndatos = Val(TextBox1.Text)
For i As Integer = 0 To ndatos - 1
v(i) = Val(InputBox("Ing. volumen No "& i + 1))
ListBox1.Items.Add(v(i))
t(i) = Val(InputBox("ing. temperatura No."& i + 1))
ListBox2.Items.Add(t(i))
Next
End Sub
_____________________________________________________________________

Sub calcular()
Tc = Val(TextBox2.Text)
pc = Val(TextBox3.Text)
a = 27 * 0.08205 ^ 2 * Tc ^ 2 / (64 * pc)
b = 0.08205 * Tc / (8 * pc)
For i As Integer = 0 To ndatos - 1
p(i) = 0.08205 * t(i) / (v(i) - b) - a / v(i) ^ 2
ListBox3.Items.Add(p(i))
Next
End Sub
_____________________________________________________________________

Sub media_ds()
medv = 0
medt = 0
medp = 0
For i As Integer = 0 To ndatos - 1
medv = medv + v(i)
medt = medt + t(i)
medp = medp + p(i)
Next
medv = medv / ndatos
medt = medt / ndatos
medp = medp / ndatos
dsv = 0
dst = 0
dsp = 0
For i = 0 To ndatos - 1
dsv = dsv + (v(i) - medv) ^ 2
dst = dst + (t(i) - medt) ^ 2
dsp = dsp + (p(i) - medp) ^ 2
Next
dsv = (dsv / (ndatos - 1)) ^ 0.5
dst = (dst / (ndatos - 1)) ^ 0.5
dsp = (dsp / (ndatos - 1)) ^ 0.5
TextBox4.Text = Format(medv, "##0.000")
TextBox6.Text = Format(medt, "##0.000")
TextBox8.Text = Format(medp, "##0.000")
TextBox5.Text = Format(dsv, "##0.000")
TextBox7.Text = Format(dst, "##0.000")
TextBox9.Text = Format(dsp, "##0.000")
End Sub
_____________________________________________________________________

Sub limpiar()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
ListBox1.Items.Clear()
ListBox2.Items.Clear()
ListBox3.Items.Clear()
For i As Integer = 0 To ndatos - 1
v(i) = 0
t(i) = 0
p(i) = 0
Next
End Sub
_____________________________________________________________________

End Class
_____________________________________________________________________

You might also like