Private Function paseParametros(Optional a As Float = 0, Optional b As Float = 0, Optional c As Float = 0) As Float
'Codigo aqui
End
Public Function FindX(TableX As String, WhereX As String, ...) As Variant
'
Dim Res As Result
'
Res = ConnX.Find(TableX, ConnX.Subst(WhereX, ...))
'
Return Res
'
Catch
Return Error.Text
'
End
Public Sub WebButton1_Click()
Message.Info(SumaX(28.75, 450.50, 450.75))
End
Private Function SumaX(...) As Variant
'
Message.Info("Total de Parámetros: " & Param.Count)
Dim suma As Float
For Each NumX As Float In Param
suma += NumX
Next
'
Return suma
'
Catch
Return Error.Text
End
pasarParametro(v=0.50, r=0.25)
Public Sub Form_Open()
paseParametros(10.5, 20.0) 'Se pasan 2 parámetros
Print "---"
paseParametros(0.0) 'Se pasa un 0
Print "---"
paseParametros(1.0, 2.0, 3.0) 'Se pasan 3 parámetros
Print "---"
paseParametros() 'No se pasa ningún parámetro
End
Public Sub paseParametros(Optional a As Float = -1, Optional b As Float = -1, Optional c As Float = -1)
If a = -1 Then
Print "El parametro " & Quote("a") & " no fue pasado"
Else
Print "El parametro " & Quote("a") & " fue pasado. Su valor es: " & Str(a)
Endif
If b = -1 Then
Print "El parametro " & Quote("b") & " no fue pasado"
Else
Print "El parametro " & Quote("b") & " fue pasado. Su valor es: " & Str(b)
Endif
If c = -1 Then
Print "El parametro " & Quote("c") & " no fue pasado"
Else
Print "El parametro " & Quote("c") & " fue pasado. Su valor es: " & Str(c)
Endif
End
Public Sub Form_Open()
Print Ohm()
Print Ohm(5.0)
Print Ohm(5.0, 4.0)
Print Ohm(5.0, Null, 4.0)
Print Ohm(Null, 5.0, 4.0)
Print Ohm(5.125, 4.0)
Print Ohm(5.0, Null, 4.125)
Print Ohm(Null, 5.0, 4.125)
Print Ohm(5.0, 0.0)
Print Ohm(5.0, Null, 0.0)
Print Ohm(Null, 5.0, 0.0)
Print Ohm(5.0, 4.0, 3.0)
End
Public Function Ohm(Optional v As Variant, Optional r As Variant, Optional i As Variant) As String
Dim count As Integer
' Si alguno de los valores no es numérico (ni Null), entonces es inválido
If (Not IsNull(v) And Not IsFloat(CStr(v))) Or (Not IsNull(r) And Not IsFloat(CStr(r))) Or (Not IsNull(i) And Not IsFloat(CStr(i))) Then
Return "Valores inválidos"
End If
' Si se han dado más de dos parámetros, no se puede calcular ninguno
If IsFloat(CStr(v)) Then count += 1
If IsFloat(CStr(r)) Then count += 1
If IsFloat(CStr(i)) Then count += 1
'Si no ha dado mínimo dos parámetros no se puede calcular
If count <> 2 Then Return "Valores inválidos"
'En caso de haber recibido dos parámetros aplicamos la ley de Ohm
If IsFloat(CStr(v)) And IsFloat((CStr(r))) Then
'Evita división por cero
If CFloat(r) = 0 Then Return "Valores inválidos"
'Devuelve la intensidad
Return "I = " & Format$(CFloat(v) / CFloat(r), "0.00")
Else If IsFloat(CStr(v)) And IsFloat(CStr(i)) Then
'Evita división por cero
If CFloat(i) = 0 Then Return "Valores inválidos"
'Devuelve la resistencia
Return "R = " & Format$(CFloat(v) / CFloat(i), "0.00")
Else If IsFloat(CStr(r)) And IsFloat(CStr(i)) Then
'Devuelve el voltaje
Return "V = " & Format$(CFloat(r) * CFloat(i), "0.00")
Else
Return "Valores inválidos"
End If
End Function
Cita:Valores inválidos
Valores inválidos
I = 1,25
R = 1,25
V = 20,00
I = 1,28
R = 1,21
V = 20,63
Valores inválidos
Valores inválidos
V = 0,00
Valores inválidos
(29-05-2025, 13:25)Grandamakulo escribió: Me «via metel ande naide me llama», pero, ¿y probando con IsNaN, IsNumber, IsBlank etc. según corresponda?