473,388 Members | 1,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

A97 - always necessary to encapsulate ampersands in spaces?

MLH
I have tried the following in the immediate window.
It yields an error...

?"Hello"&vbCrLf&"there"&vbCrLf&"next"&vbCrLf&"line ."

'Type declaration character does not match declared data type.

But the following does works as expected...
?"Hello" & vbCrLf & "there" & vbCrLf & "next" & vbCrLf & "line."

Is it pretty much standard that concatenations must be constructed
with spaces surrounding the ampersands ALL the time? I do not
believe that was the case with Access Basic in Access 2.0.
Nov 13 '05 #1
4 2106
The ampersand also functions as a type declaration for a long integer, i.e.:
2
would be an integer, but:
2&
is a long integer.

If you open the immediate window (Ctrl+G), and enter:
? 200 * 200
Access gives you an overflow error.
If you specify one of the values as a Long, it does not overflow, e.g.:
? 200& * 200

So, there are contexts in which VBA can misunderstand the ampersand as a
type declaration characters if you do not enter a space before it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.net> wrote in message
news:b7********************************@4ax.com...
I have tried the following in the immediate window.
It yields an error...

?"Hello"&vbCrLf&"there"&vbCrLf&"next"&vbCrLf&"line ."

'Type declaration character does not match declared data type.

But the following does works as expected...
?"Hello" & vbCrLf & "there" & vbCrLf & "next" & vbCrLf & "line."

Is it pretty much standard that concatenations must be constructed
with spaces surrounding the ampersands ALL the time? I do not
believe that was the case with Access Basic in Access 2.0.

Nov 13 '05 #2
MLH
That's a perfect explanation, Allen. Many thanks.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The ampersand also functions as a type declaration for a long integer, i.e.:
2
would be an integer, but:
2&
is a long integer.

If you open the immediate window (Ctrl+G), and enter:
? 200 * 200
Access gives you an overflow error.
If you specify one of the values as a Long, it does not overflow, e.g.:
? 200& * 200

So, there are contexts in which VBA can misunderstand the ampersand as a
type declaration characters if you do not enter a space before it.


Nov 13 '05 #3

"MLH" <CR**@NorthState.net> schreef in bericht news:b7********************************@4ax.com...
I have tried the following in the immediate window.
It yields an error...

?"Hello"&vbCrLf&"there"&vbCrLf&"next"&vbCrLf&"line ."

'Type declaration character does not match declared data type.

But the following does works as expected...
?"Hello" & vbCrLf & "there" & vbCrLf & "next" & vbCrLf & "line."

Is it pretty much standard that concatenations must be constructed
with spaces surrounding the ampersands ALL the time? I do not
believe that was the case with Access Basic in Access 2.0.


You don't HAVE to do it ALL the time:
?"Hello"&"there"&"next"&"line." will work.
but I guess it is pretty much standard that readability is also important, so I would always use spaces.

Your example would also error in Access 2.0 but we did not 'have' vbCrLf there

Arno R
Nov 13 '05 #4
MLH
Now I understand. Because the ampersand performs
a double roll. one must take care how one uses it.
xxxxxxxxxxxxxxxxxx

You don't HAVE to do it ALL the time:
?"Hello"&"there"&"next"&"line." will work.
but I guess it is pretty much standard that readability is also important, so I would always use spaces.

Your example would also error in Access 2.0 but we did not 'have' vbCrLf there

Arno R


Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily...
1
by: leegold2 | last post by:
The subject title is a sedgeway into my question that may slightly of topic but I've asked many sources and don't have an answer yet so I ask it here. I have a text fields of html marked up...
2
by: micha | last post by:
my php script gets delivered text that contains special chars (like german umlauts), and these chars may, may partially or may not be coverted into html entities already. i don't know beforhand. ...
5
by: kaeli | last post by:
Hey all, In trying to get my site to validate (html 4.01 transitional), I ran across an issue with this type of url in an href: http://www.server.com/somePage?param1=1&param2=2 etc Notably:...
1
by: jjbutera | last post by:
How do I escape these? The backslash doesn't seem to be working.
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
5
by: AJ Brown | last post by:
How does one allow the use of ampersands (or other special characters for that matter) within Element text and Attribute text? I have problems using LoadXml from a string "<text value="Jack &...
0
by: MLH | last post by:
In the following code snippet, notice ("PIN=1234567890&MSSG=Here+is+a+short+message+-+no+spaces+-+just+plusses&Q1=0") I have it that way because I thought PLUSes were required and that spaces...
3
by: gwainguard | last post by:
Hi from reading the ECMA spec. I know understand that the bracketed code after 'void Main' is an instruction that method Main accepts a string parameter array. Can someone explain to me why this...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.