Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use the len command to count the length of string that has leading zeros

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
Hello

How do I use the LEN command to count a string that has leading zeros

The following string is entered into a datatable as '00

When I run the following

CharacterCount = Len(Test2 )
Print CharacterCount

I get a returned value of '0'

Please advise

Thanks
 
Let's pretend this odd variant of VBS exists. My question to the OP would be: what is the output that you get if we make a minor modfication to your code?

CharacterCount = Len(Test2 )
Print Test2, CharacterCount

as I rather suspect that Test2 may not contain what you think it does.

 
Hello,

I am able to get the correct length to display if I utilize the following syntax

It is only when I try to assign a variable name to the len statement do I get an incorrect result for the string containing '00

This string is not entered as "00" it is entered as '00 to retain the leading zeroes in a DataTable

We are using the QTP testing tool which allows the use of vbscript within the tool

I would like to be able to assign a variable name to use the result in a Select Case statement

What is the correct syntax to store the correct length of "2" for CharacterCount2 variable?

Dim CharacterCount2
CharacterCount2= Len(ISA_101_Author_Info_Qualifier)
'Print CharacterCount2


Print "(ISA_I01_Author_Info_Qualifier Length"
print len(ISA_I01_Author_Info_Qualifier) 'prints 3
Print ("Test2 Length")
print len(Test2)
msgbox CharacterCount2 ' the result for this is 0 rather than 2



RESULTS from print log
(ISA_I01_Author_Info_Qualifier Length
2
Test2 Length
6

Results from MSG box

0



 
Ahhh..... it is always important to post ALL the relevant code, not just a snippet, or we are just jumping through hoops trying to see what's going on.

Now that you posted the relevant code, you misspelled the variable:
Code:
Dim CharacterCount2
CharacterCount2= Len(ISA_[highlight #FCE94F]101[/highlight]_Author_Info_Qualifier)
'Print CharacterCount2


Print "(ISA_[highlight #FCE94F]I01[/highlight]_Author_Info_Qualifier Length"
print len(ISA_[highlight #FCE94F]I01[/highlight]_Author_Info_Qualifier) 'prints 3
Print ("Test2 Length")
print len(Test2)
msgbox CharacterCount2 ' the result for this is 0 rather than 2

I highly recommend adding Option Explicit to the top of your code, as it would have pointed out the error immediately.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top