Another vbscript question

For some reason

nMyString = 43
len(nMyString)
returns  a value of 2, which is what I expect,

but if sMyString = sSomeOtherString
len(sMyString)

I get the same value returned
regardless of the length of the value of sSomeOtherString.
What's going on?

Tia,
Dena
LVL 1
denamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TTomCommented:
Hi Dena!  Me, again.

I just did:

<%
dim nMyString, sMyString
nMyString = 43
sMyString = "sSomeOtherString"
response.write len(nMyString) & "<br>" & vbcrlf
response.write len(sMyString) & "<br>" & vbcrlf
%>

with absolutely predictable response.  However, when I did:

<%
dim nMyString, sMyString
nMyString = 43
sMyString = sSomeOtherString
response.write len(nMyString) & "<br>" & vbcrlf
response.write len(sMyString) & "<br>" & vbcrlf
%>

I got "2" and "0", which makes sense, since I did not define "sSomeOtherString".  When I did:

<%
dim nMyString, sMyString, sSomeOtherString
nMyString = 43
sSomeOtherString = "This is my string"
sMyString = sSomeOtherString
response.write len(nMyString) & "<br>" & vbcrlf
response.write len(sMyString) & "<br>" & vbcrlf
%>

again, results were fine.

<%
dim nMyString, sMyString, sSomeOtherString
nMyString = 43
sMyString = 125
response.write len(nMyString) & "<br>" & vbcrlf
response.write len(sMyString) & "<br>" & vbcrlf
%>

Again, results were fine.

You must be doing something else wrong.  "len" seems to have no problem with numbers, strings, or variables.

HTH,

Tom

0
mgfranzCommented:
Could it be he needs to ReDim the MyString variable to get the new value?  Especially if the Dim MyString ios being called from the same script multiple times...

Mark
0
denamAuthor Commented:
Thanks for your answers tom and mgfranz.
You definately answered my question.  
Tom's answer was more detailed and
more directly to the point, so he
should get the points.

Dena
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

mgfranzCommented:
I read a good article yesterday in regards to Private, Public and Procedure level variable declaration but can't find the URL...  here is a basic 101 version of each type of declare;

Public:
Variables declared using the Public Statement are visible to all procedures in all modules in all applications.

Private:
Variables that are visible only to the script or sub in which they are declared.

Procedure level:
Describes statements located within a Function or Sub procedure. Declarations are usually listed first, followed by assignments and other executable code. For example:

Sub MySub() ' This statement declares a sub procedure block.
    Dim A ' This statement starts the procedure block.
    A = "My variable" ' Procedure-level code.
    Debug.Print A ' Procedure-level code.
End Sub ' This statement ends a sub procedure block.


Have fun!

Mark


0
denamAuthor Commented:
Thanks Mark :)
0
TTomCommented:
Dena,

Thanks.  Have you tried "accept comment as answer" or are you using "oldlook" (I don't think it's an option).

In any case, if you are on newlook and want to try, you need to be careful that the comment you accept is the right one (the one BELOW the "Comment" bar).

If not, I will happily post an answer.

Nice to hear from you again.  Tomato time is still a LONG way off.

Tom
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
denamAuthor Commented:
You're quite right about the tomatoes.  I could send you
some snowballs...
0
mgfranzCommented:
Your welcome... But where did the snowballs and tomatoes come in?  We don't get snowballs here in San Diego, and tomatoes are year round. ;-)

Mark
0
TTomCommented:
Mark:

Private conversation.  You had to be there.

Tom
0
mgfranzCommented:
... I can only imagine... :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.