What's the difference? 
Author Message
 What's the difference?

Oops, now I know why I was missing the ;

Willy.


Quote:
> Joe / Willy,

> >The first arg should be a char, you passed a string.

> True, but...

> >Change "Y" into 'Y'

> ... this is a VB group, so make that "Y"C  :-)

> MyString = New String("Y"C, 10)

> Matt

> ====================================

> http://www.*-*-*.com/

> CodeHound - The Software Developer's Search Engine
> http://www.*-*-*.com/



Tue, 02 Sep 2003 04:24:47 GMT  
 What's the difference?
How come this works: MyString = New String(Chr(89), 10)
but this doesn't:    MyString = New String("Y", 10)

I'm just after a string filled with 10 Ys.  What is the proper .NET way to do
what in VB6 would be MyString = String$(10,"Y")?



Tue, 02 Sep 2003 03:56:50 GMT  
 What's the difference?
The first arg should be a char, you passed a string.
Change "Y" into 'Y'

MyString = New String('Y', 10)

Willy.


How come this works: MyString = New String(Chr(89), 10)
but this doesn't:    MyString = New String("Y", 10)

I'm just after a string filled with 10 Ys.  What is the proper .NET way to
do
what in VB6 would be MyString = String$(10,"Y")?



Tue, 02 Sep 2003 04:07:12 GMT  
 What's the difference?
Joe / Willy,

Quote:
>The first arg should be a char, you passed a string.

True, but...

Quote:
>Change "Y" into 'Y'

... this is a VB group, so make that "Y"C  :-)  

MyString = New String("Y"C, 10)

Matt

====================================

http://www.msjogren.net/dotnet/

CodeHound - The Software Developer's Search Engine
http://www.codehound.com



Tue, 02 Sep 2003 04:15:31 GMT  
 What's the difference?
Joe,

Quote:
>As a VB programmer I've got to say that that is about the dumbest syntax I've ever seen.

So what would you've preferred instead? ' is already used for
comments. I have to agree that it's not so obvious at first. But now
that I know it, I kinda like it. You can still use Chr() or CChar() if
you don't.

Quote:
>Are there any other letters besides C that can be used in this way?

C -> Char
D -> Decimal
R -> Double
F -> Single
L -> Long
I -> Integer
S -> Short

Matt

====================================



Tue, 02 Sep 2003 05:48:05 GMT  
 What's the difference?
Well I guess I would have preferred String("Y",10).  I realize that "Y" is a
string and not a character and that the function is generating a string from a
bunch of characters but BASIC has been able to interpret a one character string
like "Y" as a character since the earliest versions.  Besides String("Y"C,10)
looks like some sort of secret code, which I guess it is, because I couldn't find
anything about it in the help file.  I also don't want to have to learn all those
codes (if they are going to use F for Single why not just give up on Single and
call it a Float?)  CChar() is, to me, the best option.  This is a ridiculously
minor issue but it is the sort of thing that is going to make being productive in
VB.Net very hard.  Anyway, thanks for helping me out as I had spent an hour just
trying to create a 10 character string.  I seem to be doing a lot of that lately.
Quote:
-----Original Message-----

Thanks.  String("Y"C, 10) does indeed work.  As a VB programmer I've got to say
that that is about the dumbest syntax I've ever seen.  Are there any other
letters besides C that can be used in this way?

-----Original Message-----
Joe / Willy,

>The first arg should be a char, you passed a string.

True, but...

>Change "Y" into 'Y'

..... this is a VB group, so make that "Y"C  :-)  

MyString = New String("Y"C, 10)

Matt

====================================

http://www.msjogren.net/dotnet/

CodeHound - The Software Developer's Search Engine
http://www.codehound.com
..

.



Tue, 02 Sep 2003 06:19:04 GMT  
 What's the difference?
Thanks.  String("Y"C, 10) does indeed work.  As a VB programmer I've got to say
that that is about the dumbest syntax I've ever seen.  Are there any other
letters besides C that can be used in this way?
Quote:
-----Original Message-----

Joe / Willy,

>The first arg should be a char, you passed a string.

True, but...

>Change "Y" into 'Y'

.... this is a VB group, so make that "Y"C  :-)  

MyString = New String("Y"C, 10)

Matt

====================================

http://www.msjogren.net/dotnet/

CodeHound - The Software Developer's Search Engine
http://www.codehound.com
.



Tue, 02 Sep 2003 04:42:22 GMT  
 What's the difference?
Joe,

Quote:
>Well I guess I would have preferred String("Y",10).  I realize that "Y" is a
>string and not a character and that the function is generating a string from a
>bunch of characters but BASIC has been able to interpret a one character string
>like "Y" as a character since the earliest versions.

Sure, but things get a bit more complicated when you have function
overloading for example.

Sub Foo(ByVal c As Char)

Sub Foo(ByVal s As String)

--

Foo("A")

What would that call? There has to be a way to distinguish a Char from
a single character String.

Quote:
>Besides String("Y"C,10) looks like some sort of secret code, which I guess it is, because I
>couldn't find anything about it in the help file.

VB Language Reference | Data Types | Char Data Type

Quote:
>I also don't want to have to learn all those codes

At least I it's more obvious what they mean than the old style type

Quote:
>Anyway, thanks for helping me out as I had spent an hour just
>trying to create a 10 character string.

You know, the following still works too

Dim s As String
s = "YYYYYYYYYY"

;-)

Matt

====================================



Tue, 02 Sep 2003 07:07:01 GMT  
 What's the difference?

Quote:

> Sure, but things get a bit more complicated when you have function
> overloading for example.

> Sub Foo(ByVal c As Char)

> Sub Foo(ByVal s As String)

> --

> Foo("A")

> What would that call? There has to be a way to distinguish a Char from
> a single character String.

Foo(s) should throw if passed an empty string and pass the first character
to Foo(c) if the string isn't empty? A small speed hit, but oh well.

--

WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Tue, 02 Sep 2003 13:25:49 GMT  
 What's the difference?
Quote:
> As a VB programmer I've got to say

that that is about the dumbest syntax I've ever seen.

It is a return to type declaration characters from the Basic era (i.e.
FirstName$). An unfortunate side-effect of strict type casting.

--
Jonathan Allen


Thanks.  String("Y"C, 10) does indeed work.  As a VB programmer I've got to
say
that that is about the dumbest syntax I've ever seen.  Are there any other
letters besides C that can be used in this way?

Quote:
-----Original Message-----

Joe / Willy,

>The first arg should be a char, you passed a string.

True, but...

>Change "Y" into 'Y'

.... this is a VB group, so make that "Y"C  :-)

MyString = New String("Y"C, 10)

Matt

====================================

http://www.msjogren.net/dotnet/

CodeHound - The Software Developer's Search Engine
http://www.codehound.com
.



Tue, 02 Sep 2003 06:42:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. what's the difference...(chr(13)) and vbCr

2. What's the difference between ....

3. What's the difference between .Send and .Save

4. What's the difference

5. what's the difference

6. In this case, what's the difference between CSharp and VB.NET Exception Handling

7. what's the difference

8. Where's the difference

9. What's the difference

10. OCX vs DLL: what's the difference ?

11. what's the difference?

12. Join and Where: What's the difference?

 

 
Powered by phpBB® Forum Software