Word Document Properties


Listing 4-2 Adding versus Concatenating Strings



Download 8,82 Mb.
Pdf ko'rish
bet82/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   78   79   80   81   82   83   84   85   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Listing 4-2
Adding versus Concatenating Strings
Public Sub AddVersusConcatenate()
‘ Create three strings for testing.
Dim Address1 As String
Dim Address2 As Variant
Dim OtherInfo As String
‘ Place a value into the strings.
Address1 = “123 First Street”
OtherInfo = “Somewhere, NV 12345”
(continued)
85
Chapter 4: Storing and Modifying Information
09_046500 ch04.qxp 12/5/06 5:54 PM Page 85


Listing 4-2 
(continued)
‘ Place a Null value into the second address line.
Address2 = Null
‘ Concatenate the string to a null.
Dim ConString As String
ConString = Address1 & vbCrLf & _
Address2 & vbCrLf & _
OtherInfo
‘ Display the result. You see a blank line for the 
‘ null.
MsgBox ConString
‘ Add the string to a null.
Dim AddString As String
AddString = Address1 & vbCrLf & _
(Address2 + vbCrLf) & _
OtherInfo
‘ Display the result. You see no blank line.
MsgBox AddString
‘ Show that the results are correct when Address2
‘ contains a value.
Address2 = “Apt 3G”
AddString = Address1 & vbCrLf & _
(Address2 + vbCrLf) & _
OtherInfo
MsgBox AddString
End Sub
When you run this code, the first 
MsgBox
call displays the output with a
blank line between 
Address1
and 
OtherInfo
because 
Address2
is 
Null
.
However, the second 
MsgBox
call displays the data correctly because it relies
on 
+
for concatenation.
Now that you’ve seen the first two cases showing a 
Null
value, it’s time to
see what happens when 
Address2
contains a string. The code places a value
into 
Address2
, re-creates the 
AddString
value, and displays the message
box again. This time, the 
Address2
value appears between 
Address1
and
OtherInfo
, just as it should.
The 
+
can improve performance in other ways. For example, when you need to
check for a null in a variable, you can use the 
+
instead of the 
&
to improve per-
formance. Because of the way 
+
works, you don’t need to use the 
IsNull()
function to verify that a variant contains a null value before you process it.
86

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   78   79   80   81   82   83   84   85   ...   207




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish