The following subtraction and multiplacation
of two strings appear to give correct answers
without having to use Cint etc.
Subtracting strings in this way could gain me
speed! Is it safe? Does VB automatically
convert the strings anyway?
TIA Mick.
Private Sub Command1_Click()
Dim a As String * 3, b As String * 3
a = "140": b = "002"
Print b - a
Print b + a 'joins strings
Print b * a
End Sub
Frank Adam - 17 Oct 2004 21:59 GMT
>The following subtraction and multiplacation
>of two strings appear to give correct answers
[quoted text clipped - 13 lines]
>
>End Sub
IMO, it won't gain you any speed, it'll just makes the RTL work
harder.
I'm thinking, what happens is that with the subtraction, the String
library still gets the job, then when it realises that it can not do a
string operation, it passes it over to the maths library.
By using Val() should see you cutting out the String check.

Signature
Regards, Frank
Jim Mack - 17 Oct 2004 22:01 GMT
> The following subtraction and multiplacation
> of two strings appear to give correct answers
[quoted text clipped - 13 lines]
>
> End Sub
You will gain nothing, certainly not speed. In fact, it will probably
cost you time. And your code will be more obscure and prone to odd
results under circumstances you haven't anticipated.
It's good practice to use appropriate types and specify which
conversions you want to take place. Yes, VB will do the conversions for
you, using its best guess at what you want. But it's not a perfect
guesser and it may perform more conversions than are strictly necessary.

Signature
Jim Mack
MicroDexterity Inc
www.microdexterity.com
Jan Hyde - 18 Oct 2004 09:06 GMT
"Michael Harrington" <mikharr@bigpond.com>'s wild thoughts
were released on Mon, 18 Oct 2004 06:47:08 +1000 bearing the
following fruit:
>The following subtraction and multiplacation
>of two strings appear to give correct answers
[quoted text clipped - 13 lines]
>
>End Sub
Dont use + for concanination, use &, otherwise you may get
unexpected results
Dim a As String
Dim b As Integer
a = "1"
b = 2
MsgBox a + b
And no, your method is not faster, the type conversion will
still take place, but the compiler will have to guess what
the relevant type is.
Jan Hyde (VB MVP)

Signature
Have you heard about the downhill skier who was an exhibitionist?
He was arrested for in-descent exposure. (Richard Lederer)
[Abolish the TV License - http://www.tvlicensing.biz/]
ak - 29 Nov 2004 08:37 GMT
As long as you are dealing with integer values
you should convert strings by CLng() instead of CInt().
Despite Longs is longer than Integers, -LongValues makes
the fastest aritmetic.
The reason. LongValues fits perfect into the CPUs
aritmetic unit.
Regards ako
> The following subtraction and multiplacation
> of two strings appear to give correct answers
[quoted text clipped - 13 lines]
>
> End Sub