0% found this document useful (0 votes)
21 views

Codigo 2

This document contains VBA code that calculates and plots the response of a first order system. It defines variables to store the initial and final times, time increment, number of points, resistances, and capacitor value. It then collects these values from the user via input boxes. The code generates a table with the time and response values, and creates a scatter plot graph of the results on a new chart sheet. Additional formatting is applied to the chart including titles, labels, and positioning.

Uploaded by

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

Codigo 2

This document contains VBA code that calculates and plots the response of a first order system. It defines variables to store the initial and final times, time increment, number of points, resistances, and capacitor value. It then collects these values from the user via input boxes. The code generates a table with the time and response values, and creates a scatter plot graph of the results on a new chart sheet. Additional formatting is applied to the chart including titles, labels, and positioning.

Uploaded by

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

Private Sub RespIndcal_click() 'cmdCreateTable_Click()

Dim T As Single, T1 As Single 'Tempo en abscsas


Dim T0 As Single, Dt As Single, tf As Single
Dim w As Single, p As Single, sigma As Single
Dim RespImpulso1Orden As Double
Dim R1 As Single, R2 As Single, C As Single
'Titulos en Celdas
Range("B2").Select
ActiveCell.FormulaR1C1 = "Tempo"
Range("B2").Select
Selection.Fout.Bold = True
Range("C2").Select
ActiveCell.FormulaR1C1 = "Respuesta al impulso sistema de 1er Orden"
Range("C2").Select
Selection.Fout.Bold = True
Range("A2").Select
ActiveCell.FormulaR1C1 = "Tinicial"
Private Sub RespIndical_click() 'cmdCreateTable_Click()
Dim T As Single, T1 As Single 'Tempo en abscsas
Dim t0 As Single, Dt As Single, tf As Single
Dim w As Single, p As Single, sigma As Single
Dim RespImpulso1Orden As Double
Dim R1 As Single, R2 As Single, C As Single
'Titulos en Celdas
Range("B2").Select
ActiveCell.FormulaR1C1 = "Tempo"
Range("B2").Select
Selection.Fout.Bold = True
Range("C2").Select
ActiveCell.FormulaR1C1 = "Respuesta al impulso sistema de 1er Orden"
Range("C2").Select
Selection.Fout.Bold = True
Range("A2").Select
ActiveCell.FormulaR1C1 = "Tinicial"
Range("A2").Select
Selection.Fout.Bold = True
Range("A4").Select
ActiveCell.FormulaR1C1 = "Tfinal"
Range("A4").Select
Selection.Fout.Bold = True
Range("A6").Select
ActiveCell.FormulaR1C1 = "Incremento de Tiempo"
Range("A6").Select
Selection.Fout.Bold = True
Range("A8").Select
ActiveCell.FormulaR1C1 = "Nro de Puntos"
Range("A8").Select
Selection.Fout.Bold = True
Range("A10").Select
ActiveCell.FormulaR1C1 = "Constante de tiempo"
Range("A10").Select
Selection.Fout.Bold = True
Range("A12").Select
ActiveCell.FormulaR1C1 = "Valor de p - nro De Periodos"
Range("A12").Select
Selection.Fout.Bold = True
Range("A14").Select
ActiveCell.FormulaR1C1 = "R1"
Range("A14").Select
Selection.Fout.Bold = True
Range("A16").Select
ActiveCell.FormulaR1C1 = "R2"
Range("A16").Select
Selection.Fout.Bold = True
Range("A18").Select
ActiveCell.FormulaR1C1 = "C"
Range("A18").Select
Selection.Fout.Bold = True
'Pedir datos
t0 = InputBox("Valor inicial de t (t0):"): Cells(3, 1) = t0 'Tiempo inicial
tf = InputBox("Valor final de t (tf):"): Cells(5, 1) = tf 'Tiempo final
Dt = InputBox("Incremento de t (Dt):"): Cells(7, 1) = Dt 'Incremento
n = Int((tf - t0) / (Dt)) + 1: Cells(9, 1) = n 'Numero de puntos
R1 = InputBox("R1:"): Cells(15, 1) = R1 'Recistencia R1
R2 = InputBox("R2:"): Cells(17, 1) = R2 'Recistencia R2
C = InputBox("C:"): Cells(19, 1) = C 'Capacitor C
T1 = C * R1: Cells(11, 1) = T1 'Tau

'Borra las celdas de rrespuestas anteriores


contador = 0
While Abs(Cells(contador + 3, 2)) Or Abs(Cells(contador + 3, 3)) > 0
Cells(contador + 3, 2) = "": Cells(contador + 3, 3) = ""
contador = contador + 1
Wend
'Tabla de valores de tiempo-Respuesta Indicial
For w = t0 To tf Step Dt
p = (w - t0) / Dt: Cells(13, 1) = p
Cells(p + 3, 3) = RespImpulso1Orden
Next w
Call grafico

End Sub
'Grafico
Sub grafico()
Dim n As Integer, p As Single, ChartsTemp As Object, graf As Object
Dim datos As String
n = Cells(9, 1): p = Cells(13, 1)
'Eliminar datos grafico anterior
Set ChartsTemp = ActiveSheet.ChartObjects
If ChartsTemp.Count > 0 Then
ChartsTemp(ChartsTemp.Count).Delete
End If
datos = Range(Cells(3, 2), Cells(p + 3, 3)).Address 'rango a greficar
Set graf = Charts.Add 'grafico y sus caracteristicas
'Caracteristicas
With graf
.Name = "Grafico"
.ChartType = x1XYScatterSmoothNoMarkers
.SetSourceData Source:=Sheets("hoja1").Range(dtos), PlotBy:=x1Columna
.Location Where:=x1LocationAsObject, Name:="Hoja1"
End With
With ActiveChart
.HasTitle = True
.ChartTitle.Charaters.Text = "RESPUESTA AL IMPULSO SISTEMA DE 1er ORDEN"
.Axes(x1Category, x1Primary).HasTitle = True
.Axes(x1Category, x1Primary).AxisTitle.Characters.Text = "tiempo"
.Axes(x1Value, x1Primary).HasTitle = True
.Axes(x1Value, x1Primary).AxisTitle.Characters.Text = "Respuesta Indical"
.Axes(x1Value, x1Primary).HasTitle = True
End With
With ActiveChart.Parent
.Left = 200:
.Top = 20:
End With
'El programa termina en una celda vacia
'Range("A15".select
'ActiveCell.FormulaR1C1=""
'Range("A15").Select
'Selection.Font:Bold=True
'ActiveChart.HasLegend=false
'Activechart.ApplyDataLabels Type:x1dataLabelsShowValue,LegendKey:=False

End Sub

You might also like