[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

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
0
denam
Asked:
denam
  • 4
  • 3
  • 3
1 Solution
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now