Hola yo soy un estudiante de la Universidad Veracruzana de Ciencias químicas y una de mis materias es algoritmos comunicacionales este es mi código de programa final no es para que lo copien por que no les va a salir pero si pueden tomar códigos como el bloqueo de Textbox para que solo acepte un punto decimal y números o comprueben como es mas o menos las ecuaciones, espero les sirva suerte y denme suerte que mi examen es mañana y es todo esto
Este es mi código y empieza aquí :
Public Class Form1
'declaracion de variables
'Dim GV, D1, d2, A1, a2, V1, v2, P, VS, T1, t2, H1, h2, P1, p2, Pt, Re1, Re2, f1, f2, hl1, hl2, hl, ht1, ht2, ht, pt1, w
Dim D1, z, d2, P, X, H1, h2, P1, p2, Li, Lf, Pi, Pf, A1, a2, GV, V1, V2, VS, Pt, f1, f2, Re1, Re2, hl, hl1, hl2, ht1, ht2, ht, pt1, w, T1, t2, D1c, d2c As Double
Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
If TextBox5.Text <> "" Then
If TextBox5.Text <> "." Then
If ComboBox8.Text = "m3/s" Then
w = TextBox5.Text * 1
Else
w = TextBox5.Text
End If
End If
End If
End Sub
Private Sub ComboBox10_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox10.SelectedIndexChanged
'CAUDAL
If TextBox5.Text <> "" Then
If TextBox5.Text <> "." Then
If ComboBox8.Text = "m3/s" Then
w = TextBox5.Text * 1
Else
w = TextBox5.Text
End If
End If
End If
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
'Longitud F I N A L
If TextBox4.Text <> "" Then
If TextBox4.Text <> "." Then
If ComboBox8.Text = "m" Then
Lf = TextBox4.Text * 1
ElseIf ComboBox8.Text = "in" Then
Lf = TextBox4.Text * 0.0254
ElseIf ComboBox8.Text = "ft" Then
Lf = TextBox4.Text * 0.304
End If
End If
End If
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
'Altura F I N A L
'Dim valorX As Decimal
If TextBox2.Text <> "" Then
If TextBox2.Text <> "." Then
If ComboBox7.Text = "m" Then
h2 = Val(TextBox2.Text)
ElseIf ComboBox7.Text = "in" Then
h2 = TextBox2.Text * 0.0254
ElseIf ComboBox7.Text = "ft" Then
h2 = TextBox2.Text * 0.304
End If
End If
End If
'h2 = valorX
End Sub
Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs) Handles TextBox8.TextChanged
'Presión F I N A L
If TextBox8.Text <> "" Then
If TextBox8.Text <> "." Then
p2 = TextBox8.Text * 101325
Else
p2 = TextBox8.Text
End If
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
'Material I N I C I A L
If ComboBox1.Text = "Hierro Galvanizado" Then
T1 = 0.24
ElseIf ComboBox1.Text = "Hierro Fundido" Then
T1 = 0.25
ElseIf ComboBox1.Text = "Hierro Forjado" Then
T1 = 0.09
End If
Label47.Text = T1
End Sub
Private Sub ComboBox6_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox6.SelectedIndexChanged
'Altura I N I C I A L
If TextBox1.Text <> "" Then
If TextBox1.Text <> "." Then
If ComboBox6.Text = "m" Then
H1 = TextBox1.Text * 1
ElseIf ComboBox6.Text = "in" Then
H1 = TextBox1.Text * 0.0254
ElseIf ComboBox6.Text = "ft" Then
H1 = TextBox1.Text * 0.304
End If
End If
End If
Label43.Text = H1
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
'Altura I N I C I A L
If TextBox1.Text <> "" Then
If TextBox1.Text <> "." Then
If ComboBox6.Text = "m" Then
H1 = TextBox1.Text * 1
ElseIf ComboBox6.Text = "in" Then
H1 = TextBox1.Text * 0.0254
ElseIf ComboBox6.Text = "ft" Then
H1 = TextBox1.Text * 0.304
End If
End If
End If
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
'Longitud I N I C I A L
If TextBox3.Text <> "" Then
If TextBox3.Text <> "." Then
If ComboBox3.Text = "m" Then
Li = TextBox3.Text * 1
ElseIf ComboBox3.Text = "in" Then
Li = TextBox3.Text * 0.0254
ElseIf ComboBox3.Text = "ft" Then
Li = TextBox3.Text * 0.304
End If
End If
End If
Label44.Text = Li
End Sub
Private Sub Textbox7_keypress(sender As Object, e As KeyPressEventArgs) Handles TextBox7.KeyPress
'RESULTADO F I N A L
If InStr(1, "" & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
'Longitud I N I C I A L
If TextBox3.Text <> "" Then
If TextBox3.Text <> "." Then
If ComboBox3.Text = "m" Then
Li = TextBox3.Text * 1
ElseIf ComboBox3.Text = "in" Then
Li = TextBox3.Text * 0.0254
ElseIf ComboBox3.Text = "ft" Then
Li = TextBox3.Text * 0.304
End If
End If
End If
End Sub
Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged
'Presión I N I C I A L
If TextBox6.Text <> "" Then
If TextBox6.Text <> "." Then
P1 = TextBox6.Text * 101325
Else
P1 = TextBox6.Text
End If
End If
End Sub
Private Sub TextBox8_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox8.KeyPress
'Presión F I N A L
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
Else
If InStr(1, TextBox8.Text & Chr(8), e.KeyChar) <> 0 Then
If e.KeyChar = "." Then
e.KeyChar = ""
End If
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
End If
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
'TEMPERATURA
If ComboBox2.Text = "20°C" Then
P = 998.2
VS = 0.001
ElseIf ComboBox2.Text = "30°C" Then
P = 995.7
VS = 0.8
ElseIf ComboBox2.Text = "40°C" Then
P = 992.2
VS = 0.656
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
'Botón INFORMACIÓN
Form2.Show()
End Sub
Private Sub TextBox5_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox5.KeyPress
'Caudal
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
Else
If InStr(1, TextBox5.Text & Chr(8), e.KeyChar) <> 0 Then
If e.KeyChar = "." Then
e.KeyChar = ""
End If
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
End If
End If
End Sub
Private Sub ComboBox9_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox9.SelectedIndexChanged
'Material F I N A L
If ComboBox9.Text = "Hierro Galvanizado" Then
t2 = 0.24
ElseIf ComboBox9.Text = "Hierro Fundido" Then
t2 = 0.25
ElseIf ComboBox9.Text = "Hierro Forjado" Then
t2 = 0.09
End If
Label48.Text = t2
End Sub
Private Sub ComboBox7_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox7.SelectedIndexChanged
'Altura F I N A L
If TextBox2.Text <> "" Then
If TextBox2.Text <> "." Then
If ComboBox7.Text = "m" Then
h2 = TextBox2.Text * 1
ElseIf ComboBox7.Text = "in" Then
h2 = TextBox2.Text * 0.0254
ElseIf ComboBox7.Text = "ft" Then
h2 = TextBox2.Text * 0.304
End If
End If
End If
Label45.Text = h2
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Declaracion de variables
D1 = ComboBox4.Text * 0.0254 'Diámetro, conversión de pulgadas a metros
d2 = ComboBox5.Text * 0.0254
D1c = D1 * 1000 'Diámetro, conversión de metros a milímetros
d2c = d2 * 1000
'Mensajes a pantalla
If TextBox1.Text = "" Or TextBox1.Text = "." Then
MsgBox("Error. Introduzca un número referente a la altura inicial")
TextBox1.Show()
Label9.Text = ""
ElseIf TextBox2.Text = "" Or TextBox2.Text = "." Or TextBox2.Text = "-" Or TextBox2.Text = "-." Or TextBox2.Text = ".-" Then
MsgBox("Error. Introduzca un número referente a la altura final")
TextBox2.Show()
Label9.Text = ""
ElseIf TextBox6.Text = "" Or TextBox6.Text = "." Then
MsgBox("Error, por favor escriba la presión inicial")
TextBox6.Show()
Label9.Text = ""
ElseIf TextBox8.Text = "" Or TextBox8.Text = "." Then
MsgBox("Error, por favor introduzca la presión final")
TextBox8.Show()
Label9.Text = ""
ElseIf TextBox3.Text = "" Or TextBox3.Text = "." Then
MsgBox("Error, por favor introduzca la longitud Inicial")
TextBox3.Show()
Label9.Text = ""
ElseIf ComboBox4.Text = "" Or ComboBox4.Text = "." Then
MsgBox("Error, por favor introduzca el diámetro inicial")
ComboBox4.Show()
Label9.Text = ""
ElseIf TextBox5.Text = "" Or TextBox5.Text = "." Then
MsgBox("Error, por favor introduzca el caudal")
TextBox5.Show()
Label9.Text = ""
ElseIf ComboBox5.Text = "" Or ComboBox5.Text = "." Then
MsgBox("Error, por favor introduzca el diámetro final")
ComboBox5.Show()
Label9.Text = ""
ElseIf TextBox4.Text = "" Or TextBox4.Text = "." Then
MsgBox("Error, por favor introduzca la longitud final")
TextBox4.Show()
Label9.Text = ""
ElseIf P1 < p2 Then
MsgBox("Error, la presión inicial no puede ser menor a la presión final")
TextBox8.Show()
Label9.Text = ""
ElseIf d2 < D1 Then
MsgBox("Error, el diámetro final tiene que ser mayor al diámetro inicial")
ComboBox5.Show()
Label9.Text = ""
ElseIf H1 < h2 Then
MsgBox("Error, la altura inicial tiene que ser mayor a la altura final")
ElseIf Li < H1 Then
MsgBox("Error, la altura inicial no debe ser mayor a la longitud inicial")
ElseIf Lf < Math.Abs(-h2) Then
MsgBox("la altura final no puede ser mayor a la loguitud final")
Else
P1 = Pi * 101325
p2 = Pf * 101325
GV = 9.81
A1 = (Math.PI * (D1 * D1)) / 4 'Velocidad de las zonas A y B
Label18.Text = A1
a2 = (Math.PI * (d2 * d2)) / 4
Label19.Text = a2
V1 = w / A1
Label20.Text = V1
V2 = w / a2
Label21.Text = V2
Re1 = (P * D1 * V1) / VS 'R E Y N O L D S
Label22.Text = Re1
Re2 = (P * d2 * V2) / VS
Label23.Text = Re2
f1 = 1.325 / (Math.Log((T1 / (D1c * 3.7)) + (5.74 / Re1 ^ 0.9))) ^ 2 'Relación RUGOSIDAD y DIÁMETRO
Label24.Text = f1
f2 = 1.325 / (Math.Log((t2 / (d2c * 3.7)) + (5.74 / Re2 ^ 0.9))) ^ 2
Label25.Text = f2
hl1 = (f1 * ((Li / D1) * ((V1 * V1) / (2 * GV)))) 'PERDIDA DE CARGA
Label26.Text = hl1
hl2 = (f2 * ((Lf / d2) * ((V2 * V2) / (2 * GV))))
Label16.Text = hl2
hl = (hl1 + hl2)
Label28.Text = hl
ht = ((P1 / (P * GV) + (V1 * V1) / (2 * (GV))) + H1) - (((p2 / (P * GV) + (V2 * V2) / 2 * GV) + h2) - hl) 'BERNOULLI
Label27.Text = ht
Pt = (P * GV * w * ht) 'POTENCIA
Label42.Text = Pt
pt1 = Pt / 1000
TextBox7.Text = CStr(pt1) + "kw"
If pt1 < 0 Then
MsgBox("Error, la potencia no puede ser negativa. Verifique sus valores")
End If
If pt1 > 0 Then
TextBox7.Text = CStr(pt1) + "kw"
Me.TextBox7.Text = CStr(System.Math.Round(Val(pt1), 2))
End If
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox10.Text = "m3/s"
ComboBox2.Text = "20°C"
ComboBox1.Text = "Hierro Galvanizado"
ComboBox3.Text = "m"
ComboBox9.Text = "Hierro Galvanizado"
ComboBox8.Text = "m"
ComboBox6.Text = "m"
ComboBox7.Text = "m"
ComboBox4.Text = "12"
ComboBox5.Text = "24"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Botón FINALIZAR
Close()
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
'Altura INICIAL
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
Else
If InStr(1, TextBox1.Text & Chr(8), e.KeyChar) <> 0 Then
If e.KeyChar = "." Then
e.KeyChar = ""
End If
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
End If
End If
End Sub
Private Sub TexBox2_keypress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
'Altura FINAL
If InStr(1, "-0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
Else
If InStr(1, TextBox2.Text & Chr(8), e.KeyChar) <> 0 Then
If e.KeyChar = "." Then
e.KeyChar = ""
End If
If InStr(1, "-0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
End If
End If
End Sub
Private Sub TextBox3_Keypress(sender As Object, e As KeyPressEventArgs) Handles TextBox3.KeyPress
'Longitud INICIAL
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
Else
If InStr(1, TextBox3.Text & Chr(8), e.KeyChar) <> 0 Then
If e.KeyChar = "." Then
e.KeyChar = ""
End If
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
End If
End If
End Sub
Private Sub Textbox4_keypress(sender As Object, e As KeyPressEventArgs) Handles TextBox4.KeyPress
'Longitud FINAL
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
Else
If InStr(1, TextBox4.Text & Chr(8), e.KeyChar) <> 0 Then
If e.KeyChar = "." Then
e.KeyChar = ""
End If
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
End If
End If
End Sub
Private Sub Textbox6_keypress(sender As Object, e As KeyPressEventArgs) Handles TextBox6.KeyPress
'Presión INICIAL
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
Else
If InStr(1, TextBox6.Text & Chr(8), e.KeyChar) <> 0 Then
If e.KeyChar = "." Then
e.KeyChar = ""
End If
If InStr(1, "0123456789." & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
End If
End If
End Sub
Private Sub ComboBox8_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox8.SelectedIndexChanged
'Presión FINAL
If TextBox4.Text <> "" Then
If TextBox4.Text <> "." Then
If ComboBox8.Text = "m" Then
Lf = TextBox4.Text * 1
ElseIf ComboBox8.Text = "in" Then
Lf = TextBox4.Text * 0.0254
ElseIf ComboBox8.Text = "ft" Then
Lf = TextBox4.Text * 0.304
Else
Lf = TextBox4.Text
End If
End If
End If
Label46.Text = Lf
End Sub
End Class