473,503 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

const string = chr() & chr() is picky

I am trying to set a const string made up of Chr(), but if the value
passed into Chr() is too large, the compiler complains that it is not
constant!! Example:

Public Const m_Data As String = Chr(&HD) & Chr(&HE) 'ok
Public Const m_Data As String = Chr(&HD0) & Chr(&HE0) 'not ok

But, Char stores 0..255, so it should be ok in both cases. What's
going on?

Zytan

Feb 13 '07 #1
7 2568
"Zytan" <zy**********@yahoo.comschrieb:
>I am trying to set a const string made up of Chr(), but if the value
passed into Chr() is too large, the compiler complains that it is not
constant!! Example:

Public Const m_Data As String = Chr(&HD) & Chr(&HE) 'ok
Public Const m_Data As String = Chr(&HD0) & Chr(&HE0) 'not ok

But, Char stores 0..255, so it should be ok in both cases. What's
going on?
Note that 'Chr' uses Windows ANSI. Maybe it's better to use 'ChrW', which
is Unicode-enabled, instead.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 13 '07 #2
Hello Zytan,
Public Const m_Data As String = Chr(&HD) & Chr(&HE) 'ok
Public Const m_Data As String = Chr(&HD0) & Chr(&HE0) 'not ok

But, Char stores 0..255, so it should be ok in both cases. What's
going on?
It might be a Unicode issue. Try ChrW instead.

Best regards,

Martin
Feb 13 '07 #3
Note that 'Chr' uses Windows ANSI. Maybe it's better to use 'ChrW', which
is Unicode-enabled, instead.
You are completely right. I knew the above, but i didn't think it
mattered. I was thinking ChrW() would return a two byte Char. Which
it does, and so does Chr(), since it's all unicode in VB .NET. Duh.

I still don't understand why it was complaining. I should note that
Chr() does accept 0..255, and I was within that range. So, something
is still wrong here.

But your suggestion works, so thanks!

Zytan

Feb 13 '07 #4
"Zytan" <zy**********@yahoo.comschrieb:
>Note that 'Chr' uses Windows ANSI. Maybe it's better to use 'ChrW',
which
is Unicode-enabled, instead.

You are completely right. I knew the above, but i didn't think it
mattered. I was thinking ChrW() would return a two byte Char. Which
it does, and so does Chr(), since it's all unicode in VB .NET. Duh.

I still don't understand why it was complaining. I should note that
Chr() does accept 0..255, and I was within that range. So, something
is still wrong here.

'Chr' does not accept values greater than 127 when used in constants. The
reason is that 'Chr' would return different characters depending on the
system's Windows ANSI codepage for larger values. 'ChrW' always returns the
same character for a certain character code.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 13 '07 #5
'Chr' does not accept values greater than 127 when used in constants.

Sounds peculiar...
The
reason is that 'Chr' would return different characters depending on the
system's Windows ANSI codepage for larger values.
....until you said that.
'ChrW' always returns the
same character for a certain character code.
It all makes sense. And now that's something I'll remember. Again,
thanks for a very informative post, Herfried.

Zytan
Feb 14 '07 #6
It might be a Unicode issue. Try ChrW instead.
>
Best regards,

Martin
Yup, thanks. Please read Herfried's very informative post for the
precise cause.

Zytan

Feb 14 '07 #7
Note that 'Chr' uses Windows ANSI. Maybe it's better to use 'ChrW', which
is Unicode-enabled, instead.
Wait, luckily i had a debug.assert() to ensure things were ok, and i
found the following are not equivalent:

Dim a As String = Chr(&HD0) & Chr(&HE0)
Dim b As String = ChrW(&HD0) & ChrW(&HE0)

So, using ChrW(), while it allows b to be Const, where a cannot be
Const, it does not make b = a.

Zytan

Feb 14 '07 #8

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

Similar topics

16
2433
by: Steven T. Hatton | last post by:
In the following code, the only way I can figure out to pass an array of const is by setting the template argument to const in the instanciation expression. It would be (or seem to me) better if I...
6
15274
by: p|OtrEk | last post by:
What is practic difference between this two declarations? If i want call my func with func("blah") i could write: 1) func(std::string const& arg1) 2) func(const std::string& arg1) Whats better to...
6
91597
by: C L Humphreys | last post by:
Hi, I'm trying to concatenate address fields and insert a LF&CR after each line. The SQL I use is based on select address1 & chr(10) & chr(13)& address2 & chr(10) & chr(13)& address3 & ...
1
8345
by: jdph40 | last post by:
I am trying to enter text to look like paragraphs in a text box on a report, making it look like a memo. I enter (Chr$(13) & Chr$(10) & Chr$(10)) to insert a carriage return and 2 line breaks, but...
2
18103
by: lauren quantrell | last post by:
Has anyone cunstructed a function to remove multiple carriage returns and replace it with a single return? Replace(mytext, Chr(13) & Chr(10) & Chr(13) & Chr(10), Chr(13) & Chr(10)) ... only...
0
1683
by: tom olson | last post by:
After more searching I found that defining const operators can cause problems with many compilers due to the way it interprets the C++ standard. I removed the const operators from my class and it...
11
5325
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
3
2503
by: Rich Shepard | last post by:
I need to learn how to process a byte stream from a form reader where each pair of bytes has meaning according to lookup dictionaries, then use the values to build an array of rows inserted into a...
2
4078
by: Joe Duchtel | last post by:
Hello - I was wondering why I can do a ... Public Const A As Char = Chr(36) .... but not a ... Public Const B As Char = Chr(165)? It seems like 0-127 are okay with the Chr(). Is this...
0
7199
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
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
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
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.