|Sorry, this always seems to happen after I post but I think I get it now. I'm trying to assign a value to a class. It compiles if i do this:
Private Sub ab(Optional ByVal val As EncryptKey = Nothing)
I was confused by this:
Private Sub ab(Optional ByVal val As String = "")
I don't know how String is defined to be able to accept this but what I'm doing won't work.
Sorry again for the ugly post.
Sorry about the subject line; didn't know how to describe my problem.
Through searching around the internet i've come up with this class to be able to process a string value.
Private _string As String = String.Empty
Public Sub New(ByVal value As String)
' Remove white space
Me._string = value.Trim()
Public Shared Widening Operator CType(ByVal value As String) As EncryptKey
Return New EncryptKey(value)
Public Overrides Function ToString() As String
Public Function Length() As Integer
Public Function IsEmpty() As Boolean
Return (_string.Length = 0)
Public Shared Operator +(ByVal s1 As EncryptKey, ByVal s2 As EncryptKey) As EncryptKey
' Concat and remove white space
Dim temp As String = (s1._string + s2._string).Trim()
Return New EncryptKey(temp)
The class is working except for this case:
Private Sub ab(Optional ByVal val As EncryptKey = "")
' Results in this error for the Optional assigment:
'error BC30060: Conversion from 'String' to 'EncryptKey' cannot occur in a constant expression.
Is there a way to make the class able to accept this assignment as an Optional parameter?
-- modified 30-Sep-20 12:34pm.