Is it possible to implement a Nullable Type, e.g. NullableOfInteger, in VB6

Just wondering if anyone knows of a way to implement a typed Nullable type like NullableOfInteger in VB6? (I try to avoid using options)

You can easily create a custom NullableOfInteger class and use its uninitialized state to indicate Null state, but this has obvious disadvantages.

Also, I can’t think of other ways? My gut tells me there won't be a good way.

+6
source share
3 answers

VB6 does not have operator overloading or a custom implicit cast that uses NULL types in VB.NET. You really can't do it better than an option.

An alternative is to select a specific value and always treat this value as null. In .NET 1.0 days, people used int.MinValue . I do not know what the equivalent of VB6 is, but I am sure that there is something. This works and is not as bad as it seems (but null types are better).

+7
source

I think you answered your question; Nullable is a convenience - .NET has an implementation, VB6 does not (mainly due to Variant). If you need a version with security type for VB6, you have to implement it, and many of them - I remember that the usual place to see this was in the database API.

+2
source

Another point of view

Instead of Nullable, you can handle this using Optional

If you define it as Optional BLABLA As Integer , it will have a default value of 0 , so if its null or empty u will have a default value of 0 ..

Here is an example I made for myself! This may come in handy:

Application:

 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 

also works this way

 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 

see im there, getting Min, Max, Inc As Long , and when I don't define them, they have 0 as the default value.

+1
source

Source: https://habr.com/ru/post/888608/


All Articles