Thats an interesting bug! heres a sorta workaround:

<cfscript>

function Hex7toStr(Char){
        var newchar = "";
        var asciiChar = "";
        var i=0;

        for(i=1;i lte len(char);i=i+1){
                asciiChar = asciiChar&asc(mid(char,i,1));
        }

        switch (asciiChar)
        {
        case asc("0")&asc("0"):
                newchar = "NUL";
                break;
        case asc("0")&asc("A"):
                newchar = "LF";
                break;
        }
        return newchar;
}

</cfscript>

<cfoutput>
00:#Hex7toStr("00")#<br>
0A:#Hex7toStr("0A")#<br>
</cfoutput>


-----Original Message-----
From: AFM [mailto:[EMAIL PROTECTED]
Sent: 08 July 2005 17:39
To: CF-Talk
Subject: Coldfusion Switch Error - Hex Characters


Hello,

I have an odd error with a piece of code I'm migrating from CF5 to
MX6.1.  It is a simple switch statement that takes Hex7 values as a
string and spits out the ascii equivilent as a string.

Problem is, it is reading hex value '00' and '0A' as the same thing,
and returns a duplicate value error for 0.0.  I've tried chr codes,
changing it to IF statements, and more.  I was hoping an expert could
look at it and give me a hint to a fix.  Below is a small snippet of
the overall code.  Thanks.

<cfscript>
function Hex7toStr(Char){
        switch (Char)
        {
        case "00":
                newchar = "NUL";
                break;
        case "0A":
                newchar = "LF";
                break;
        case "30":
                newchar = "0";
                break;
        case "41":
                newchar = "A";
                break;
        case "EB":
                newchar = "a";
                break;
        }
        return Trim(newchar);
}


</cfscript>
<cfset hexChar1 = "00">
<cfset hexChar2 = "0A">
<cfset hexChar3 = "30">
<cfset hexChar4 = "41">
<cfset hexChar5 = "E1">
<CFSET hexStr1 = #Hex7toStr(hexChar1)#>
<CFSET hexStr2 = #Hex7toStr(hexChar2)#>
<CFSET hexStr3 = #Hex7toStr(hexChar3)#>
<CFSET hexStr4 = #Hex7toStr(hexChar4)#>
<CFSET hexStr5 = #Hex7toStr(hexChar5)#>
<cfoutput>
<table>
<tr><td>#hexChar1#</td><td>#hexStr1#</td></tr>
<tr><td>#hexChar2#</td><td>#hexStr2#</td></tr>
<tr><td>#hexChar3#</td><td>#hexStr3#</td></tr>
<tr><td>#hexChar4#</td><td>#hexStr4#</td></tr>
<tr><td>#hexChar5#</td><td>#hexStr5#</td></tr>
</table>
</cfoutput>



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:211519
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to