Solved

Unusual Behavior

Posted on 2003-11-18
9
368 Views
Last Modified: 2012-06-27
I am getting unusual behavior with some code I am writing, I have reproduced the errors in the code below. I do not believe that the error is with my code.
Here is what's going on:
a GUID is passed to a function as a string. A GUID such as "{D498A854-FBAC-4554-B2F1-C266B45326D5}" is 38 characters long, yet the Len function is returning 40, (?) so I wrote a loop displaying each of the 40 characters with their ascii values, which displays the 38 characters and their ascii values normally, and then it seems that the response.write method starts behaving strangley. The numbers 39 and 40 are displayed however there is no characters nor ascii values, also in the output is the string "<br>" which should produce a newline character, but does not show up after lines 39 and 40.

Another strange behavior, is that if I write the GUID parameter then the lenght of the parameter the length does not show up, however if I write the length then the parameter, it works normally.

Can anyone help me to make since of this?!?!?!
ff

--CODE--
Function isGUID( dataIn )

dim i
i=1
while( i<=40 )
 response.write( i & ")" & mid(dataIn,i,1) & " " & asc(mid(dataIn,i,1)) & "<br>" )
 i=i+1
wend

response.write "<hr>"
response.write Len(dataIn) & " " & dataIn
response.write "<hr>"
response.write dataIn & " " & Len(dataIn) & " this text does not show up"
response.write "<hr>"


End Function

--OUTPUT-- // note: the line breaks that appear after <br> and <hr> are mine
1){ 123<br>
2)5 53<br>
3)F 70<br>
4)3 51<br>
5)4 52<br>
6)B 66<br>
7)8 56<br>
8)2 50<br>
9)A 65<br>
10)- 45<br>
11)A 65<br>
12)9 57<br>
13)9 57<br>
14)4 55<br>
15)- 45<br>
16)4 52<br>
17)C 67<br>
18)5 53<br>
19)C 67<br>
20)- 45<br>
21)3 56<br>
22)4 52<br>
23)1 49<br>
24)4 52<br>
25)- 45<br>
26)C 67<br>
27)8 56<br>
28)1 55<br>
29)4 52<br>
30)7 55<br>
31)3 51<br>
32)1 49<br>
33)2 50<br>
34)6 54<br>
35)C 67<br>
36)A 65<br>
37)1 48<br>
38)} 125<br>
39)40)
<hr>
40 {5F34B82A-A997-4C5C-8414-C87473126CA0}
<hr>
{5F34B82A-A997-4C5C-8414-C87473126CA0}
<hr>

0
Comment
Question by:funkyfinger
  • 5
  • 3
9 Comments
 
LVL 19

Expert Comment

by:Dexstar
Comment Utility
funkyfinger:

> A GUID such as "{D498A854-FBAC-4554-B2F1-C266B45326D5}" is 38 characters long,
> yet the Len function is returning 40

Something is clear wrong with that.
Look at this:

     Dim str
     str = "{D498A854-FBAC-4554-B2F1-C266B45326D5}"
     Response.Write "Length = " & Len(str) & ", Value = """ & str & """"

That should print out a length of 38.  Where are you getting the GUID value?  Maybe you have some whitespace on there that needs to be trimmed off...  Add this line to the top of your isGUID function:
     dataln = TRIM(dataln)

Hope That Helps,
Dex*
0
 
LVL 2

Author Comment

by:funkyfinger
Comment Utility
Yes indeed,
I tried the trim function and it seems to have no effect, size is unchanged and behavior remains the same,
Running your code I get correct output:
Length = 38, Value = "{D498A854-FBAC-4554-B2F1-C266B45326D5}"
Even if I switch it around str first then len()
Weird huh?
Do you think is has something to do with being a parameter ?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Any chance that you are picking up the VBCrLf?

FtB
0
 
LVL 19

Expert Comment

by:Dexstar
Comment Utility
funkyfinger:

Try running the string through this function first:

     Function FixString( strString )
          FixString = Trim( strString )
          FixString = Replace( FixString, vbNewLine, "" )
          FixString = Replace( FixString, vbCR, "" )
          FixString = Replace( FixString, vbLF, "" )
     End Function

Can anyone else think of any other values to throw in there?

Dex*
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 2

Author Comment

by:funkyfinger
Comment Utility
With the FixString function I get different results
about 80% of the time I get a character for line 40 but not 39,
the character for line 40 has been random characters some of which are not valid GUID characters
This probably doesn't help but the characters are always
r, c, 5, 4, }
about 20% of the time I get the same results as before - no character

???
0
 
LVL 2

Author Comment

by:funkyfinger
Comment Utility
The code callin the function is
 isGUID( Server.CreateObject("Scriptlet.TypeLib").GUID  )
0
 
LVL 2

Author Comment

by:funkyfinger
Comment Utility
I also tried not passing the GUID but creating it in the function - same result
Even more confused
0
 
LVL 2

Author Comment

by:funkyfinger
Comment Utility
- actually the characters are not random they are in a pattern rcc3c54r_ (where _ is no character)
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 100 total points
Comment Utility
funkyfinger:

It isn't you.  I think this is a problem with the Scriptlet.TypeLib class.  I looked at the TypeLibrary for that object and the GUID property returns a string.  The string that it returns actually has a length of 40, even though it should only be 38.  You are not doing anything wrong.

For now, I would just add these lines to the top of isGUID:
     If Len(dataIn) > 38 Then
          dataIn = Left(dataIn, 38)
     End If

That will work around the issue...  I don't know why that module is returning the wrong string, but it isn't you, and you won't be able to fix it.  You'll just be able to work around it.

Dex*
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now