What if one string in concatenation is null; instantiation and defining string

Banaticus

Registered User.
Local time
Today, 09:44
Joined
Jan 23, 2006
Messages
153
.property = string1 & string2
If one string is null, does an error occur? Do I have to write that as:
.property = Nz(string1) & Nz(string2)

How can I instantiate a string variable and set its value at the same time? Like:
Dim someString as String = NullString or "" or whatever
 
Dim someString as String both creates the string and initializes it to "" a zero length string.

MsgBox IsNull(someString)

A string can not contain a Null only a variant can contain a Null. Text fields in tables are not strings; they are variants sub classed as strings.

You cannot Dim a string to an initial value other than a zero length string. You can do it on one line: -
Dim someString As String: someString = "Fred"

You can do it if the 'string' is a constant: -
Const someString As String = "Fred"
MsgBox someString

You could 'fake' it with a class module: -

Class module name is clsMyString.
Code:
Option Explicit
Option Compare Text

Public x As String
Public y As String
Public z As String

Private Sub Class_Initialize()

    x = "Fred"
    y = "Sam"
    z = "Tom"

End Sub

Called as: -
Code:
Sub TestIt()
    Dim someString As New clsMyString
    
    MsgBox someString.x
    MsgBox someString.y
    MsgBox someString.z

End Sub
Hope that helps.

Regards,
Chris.
 

Users who are viewing this thread

Back
Top Bottom