Sólo otro punto de vista
En lugar de anulable que puede manejar esto mediante el uso Opcional
Si se define como Optional BLABLA As Integer
que tendrá un valor predeterminado 0
así que si es nulo o vacío tendrá un valor predeterminado como 0
..
¡Aquí hay un ejemplo que hice por mí mismo! Podría ser útil:
Uso:
ProgressInc ProgressBar1 'you can add other options if you want as shown below
'ProgressInc ProgressBar1, 500, 50, 25, True
'I always change Min value to 1 in my ProgressInc so if you even choose it as 0 it still gonna be 1
también funciona de esta manera
Dim TheThing As Long
ProgressInc ProgressBar1 ,TheThing
'See no definition about TheThing except being Long type
'cause of this its value is 0
Sub:
Public Sub ProgressInc(ProgressBarName As ProgressBar, Optional Max As Long, Optional Min As Long, Optional Inc As Long, Optional Continues As Boolean = False)
Dim Recent As Long
On Err GoTo ProgressBarErr
ProgressBarName.ShowWhatsThis
DoEvents
'Maximum ProgressBar Value
If Max <> 0 Then
ProgressBarName.Max = Max
Else
Max = 100
ProgressBarName.Max = Max
End If
'Minimum ProgressBar Value
If Min <> 0 Then
ProgressBarName.Min = Min
Else
Min = 1
ProgressBarName.Min = Min
End If
If Inc <> 0 Then Inc = Inc Else Inc = 1
'When the ProgressBar value is at Maximum
'Return to the Minimum value
If Continues = True And ProgressBarName.Value = Max Then
ProgressBarName.Value = Min
End If
'Checkout Recent progress (pre calculate bar value)
Recent = ProgressBarName.Value + Inc
If Recent >= Max Then
'Recent value is higher than or equals to Max value
'to avoid errors caused by this issue Value should equal to Max
ProgressBarName.Value = Max
ElseIf Recent < Max Then
'Recent(pre calculated bar value) is lower than Max
'So nothing wrong here, proceed..
ProgressBarName.Value = ProgressBarName.Value + Inc
End If
Exit Sub
ProgressBarErr:
'ProgressBar error report.
MsgBox "With " & Err.Number & " number : '" & Err.Description & "' error occured. "
End Sub
ver allí im conseguir Min , Max, Inc Como largo y cuando no los defino, tienen 0
como valor predeterminado.
¿Se puede usar VB.NET en su lugar? ¿O un tipo de 'variante'? – Juliet
Uso C# para cualquier aplicación nueva, pero desafortunadamente estoy atrapado detrás de una montaña de código VB6 "heredado". –