Beginner: str and str$ functions 
Author Message
 Beginner: str and str$ functions

Why should I use one or the other of these functions?
Apparently the str$ function is the one to use, but it isn't in VB Help or
in our text.  It would be helpful to understand why.

TIA

Peter



Fri, 05 Sep 2003 18:14:39 GMT  
 Beginner: str and str$ functions
The first one returns a variant with subtype = string,
the second one returns a string.

Dag.


Quote:
> Why should I use one or the other of these functions?
> Apparently the str$ function is the one to use, but it isn't in VB Help or
> in our text.  It would be helpful to understand why.

> TIA

> Peter



Fri, 05 Sep 2003 19:23:07 GMT  
 Beginner: str and str$ functions

Quote:
> Why should I use one or the other of these functions?
> Apparently the str$ function is the one to use, but it isn't in VB Help or
> in our text.  It would be helpful to understand why.

As someone said, its' the return types that are different.  Str() returns a
"variant" (see VB's help for a description of variants) and Str$() returns a
string.  This will make little difference in your code since VB
automatically converts the types to what it needs when it uses them.

In general, using Str$ will be a little bit faster since the return value
doesn't have to be converted from a variant, but the difference is probably
not enough to notice. I'd recommend just using Str() since it is easier to
type and looks cleaner in your code.

-- Roger
Harry Nilsson's The Point!
http://www.jadebox.com/nilsson/thepoint.html
Oblio, Arrow, Ring Toss, The Count



Sat, 06 Sep 2003 00:24:15 GMT  
 Beginner: str and str$ functions
Thanks, Dag.
I saw in Help that str returns a variant.

What I'd like to know is;
a. why you would choose one or the other of these functions (they appear
nearly identical)
b. why str$ is undocumented (is there a disadvantage in using it?)

I guess similar situation applies to string / string$, trim / trim$ and
others.

cheers

Peter


Quote:
> The first one returns a variant with subtype = string,
> the second one returns a string.

> Dag.



> > Why should I use one or the other of these functions?
> > Apparently the str$ function is the one to use, but it isn't in VB Help
or
> > in our text.  It would be helpful to understand why.

> > TIA

> > Peter



Sat, 06 Sep 2003 03:13:18 GMT  
 Beginner: str and str$ functions
str sends and returns varient variables and in thoery is slowwer then the
str$ that sends and returnsa string variable.

--
The Lazy Typer


"Just say it! Let's keep it in the group"

~~~~~~~~~~~~~~~~~~~


Quote:
> Why should I use one or the other of these functions?
> Apparently the str$ function is the one to use, but it isn't in VB Help or
> in our text.  It would be helpful to understand why.

> TIA

> Peter



Sat, 06 Sep 2003 10:42:52 GMT  
 Beginner: str and str$ functions
Thanks everyone,
the comments are helpful
I was just wondering if str$ was kosher, seeing as how it is not in Help,
etc.

cheers

Peter


Quote:
> Why should I use one or the other of these functions?
> Apparently the str$ function is the one to use, but it isn't in VB Help or
> in our text.  It would be helpful to understand why.

> TIA

> Peter



Sat, 06 Sep 2003 14:56:02 GMT  
 Beginner: str and str$ functions


| > Why should I use one or the other of these functions?
| > Apparently the str$ function is the one to use, but it isn't in VB Help
or
| > in our text.  It would be helpful to understand why.
|
| As someone said, its' the return types that are different.  Str() returns
a
| "variant" (see VB's help for a description of variants) and Str$() returns
a
| string.  This will make little difference in your code since VB
| automatically converts the types to what it needs when it uses them.
|
| In general, using Str$ will be a little bit faster since the return value
| doesn't have to be converted from a variant, but the difference is
probably
| not enough to notice. I'd recommend just using Str() since it is easier to
| type and looks cleaner in your code.
|
And besides that, Str$() will be dropped in VB.NET (VB7). Only Str() is
left, which actually will be the same as the current Str$(). The Upgrade
Tool will handle the conversion of functions like Str() and Str$() to the
new Str().

Look at:
http://msdn.microsoft.com/vstudio/nextgen/technology/vbupgrade.asp
and:
http://msdn.microsoft.com/library/techart/vb6tovbdotnet.htm

Johan.

|
| -- Roger
| Harry Nilsson's The Point!
| http://www.jadebox.com/nilsson/thepoint.html
| Oblio, Arrow, Ring Toss, The Count
|
|



Sat, 06 Sep 2003 15:51:06 GMT  
 Beginner: str and str$ functions
There's several reasons for using the specific
string-type instead of a variant-version:

The two main reasons is Speed and Size.

Another thing, is that I want to know the datatype
I'm working with, since I don't trust VB's
"Evil Typecasts" at all...

Like in using the plus (+) sign to concatenate strings:

sAmount = "123" + "456", when what one wants is
sAmount = "123" & "456"...

As for your other question, that is correct.
(Str$, Format$, Left$, Mid$, Right$, Trim$, etc...)

Dag.


Quote:
> Thanks, Dag.
> I saw in Help that str returns a variant.

> What I'd like to know is;
> a. why you would choose one or the other of these functions (they
appear
> nearly identical)
> b. why str$ is undocumented (is there a disadvantage in using it?)

> I guess similar situation applies to string / string$, trim / trim$
and
> others.

> cheers

> Peter



> > The first one returns a variant with subtype = string,
> > the second one returns a string.

> > Dag.



> > > Why should I use one or the other of these functions?
> > > Apparently the str$ function is the one to use, but it isn't in VB
Help
> or
> > > in our text.  It would be helpful to understand why.

> > > TIA

> > > Peter



Sun, 07 Sep 2003 15:03:57 GMT  
 Beginner: str and str$ functions


Quote:
> There's several reasons for using the specific
> string-type instead of a variant-version:

> The two main reasons is Speed and Size.

<cut>

Just to add to the confusion, there are exceptions:  Date/Date$ and
Time/Time$

The Date and Time functions return the result in the internal date format
which is locale-independent and can then be manipulated or formatted as
needed.

The Date$ and Time$ functions return fixed-formatted strings which have to
be broken apart to use the value.



Sun, 07 Sep 2003 22:47:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. str( ) and str$( ). What is the real difference

2. Int to Str or Str to Int ??

3. Convert Int to Str & Str to Int

4. Converting "str str" to "str%20str"

5. Date, Trim, STR Functions Don't Work

6. VB complains about str( ) function

7. Program error in VB4-32 with Str$ function

8. What happened to the STR function?

9. illegal Operation reading txt file str ?

10. Bug or omission with STR$(number)?

11. Formatting an HREF within a str

12. Using STR()

 

 
Powered by phpBB® Forum Software