Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Create an assignment operator that accepts as const value: CLOSED

Create an assignment operator that accepts as const value: CLOSED

Scheduled Pinned Locked Moved Visual Basic
helpalgorithmstutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mo1492
    wrote on last edited by
    #1

    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) end Sub I was confused by this: Private Sub ab(Optional ByVal val As String = "") end Sub 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. Class EncryptKey Private _string As String = String.Empty Public Sub New(ByVal value As String) ' Remove white space Me._string = value.Trim() End Sub Public Shared Widening Operator CType(ByVal value As String) As EncryptKey Return New EncryptKey(value) End Operator Public Overrides Function ToString() As String Return _string End Function Public Function Length() As Integer Return Me._string.Length End Function Public Function IsEmpty() As Boolean Return (_string.Length = 0) End Function 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) End Operator End Class 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. End Sub Is there a way to make the class able to accept this assignment as an Optional parameter? Thank you

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups