• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VB.NET, is there a special Const?

SoftwareEng

Senior member
Is there a special type of Const that can be initialized in code separately from declaration? It's like a write-once variable, that once you set its value, it becomes a constant.

It's like

Public Const sSERVER_NAME As String

'-- And then, later:
sSERVER_NAME = "windows"

?

 
Never heard of that, but I am not a VB expert, and wouldn't be that surprised to see a hack like that in VB 😉. It's not const if it can be changed after initialization.
 
No there isn't. Probably the closest thing you could do would be something like this:

Public Class TestClass
Private m_ServerName As String

Public Sub New()
m_ServerName = "SERVER NAME"
End Sub

Public Property ServerName() As String
Get
Return m_ServerName
End Get

Set(ByVal value As String)
Throw New ApplicationException("Variable is constant")
End Set
End Property
End Class


This way you can set the value in the constructor and as long as all the rest of the code uses the ServerName property, you'll get what you're looking for.

Hope this helps.

Dave
 
Umm... is is just me (probably) or is the whole "attach code" thing all fsck'ed up?

I tried attaching code 5 or 6 times, and all of them would come out messed up.

Dave
 
Thanks for your help guys. I saw something like this in C#, don't remember what it's called... "Initialize-once" variables or something like that. Ehh.

I've never used the Attach Code feature here, is it broxen?
 
That's it, static readonly in C#. There doesn't seem to be an equivalent in VB.NET 2005, but at least we know what they are.

thank you guys
 
Back
Top