Solved

Unusual Behavior

Posted on 2003-11-18
9
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9774053
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
ID: 9774100
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
ID: 9774106
Any chance that you are picking up the VBCrLf?

FtB
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 19

Expert Comment

by:Dexstar
ID: 9774179
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
 
LVL 2

Author Comment

by:funkyfinger
ID: 9774279
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
ID: 9774286
The code callin the function is
 isGUID( Server.CreateObject("Scriptlet.TypeLib").GUID  )
0
 
LVL 2

Author Comment

by:funkyfinger
ID: 9774299
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
ID: 9774332
- 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
ID: 9774585
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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