gshriki
asked on
CDec in ASP
Hey,
I have the folowing code in ASP file, but it seems like the third line generates an error.
this is a simple conversion from hexa value to decimal. and it works fine in VB.
HexStr = "FFFFFF"
msgbox "&h"+cstr(HexStr)
msgbox CDec("&h" +cstr(HexStr))
msgbox "end"
* The end message doesn't appere!
I have the folowing code in ASP file, but it seems like the third line generates an error.
this is a simple conversion from hexa value to decimal. and it works fine in VB.
HexStr = "FFFFFF"
msgbox "&h"+cstr(HexStr)
msgbox CDec("&h" +cstr(HexStr))
msgbox "end"
* The end message doesn't appere!
msgbox and CDec are not available in ASP.
Msgbox is avalible if you do it in VBScript:
<SCRIPT language="VBScript">
Dim intBoxResult
intBoxResult = MsgBox("Blaha Blaha" & vbCrLf & vbCrLf & "Are you sure?",52,"Sure?")
select case intBoxResult
case 6 ' Yes
location.replace("xx.asp?d o=deleteid =<%=intID% >")
case 7 ' No
history.go(-1)
end select
</SCRIPT>
That will display a msgbox...
As and you can see it's possible to mix in ASP code (<%=intID%>....
~Gizmo
<SCRIPT language="VBScript">
Dim intBoxResult
intBoxResult = MsgBox("Blaha Blaha" & vbCrLf & vbCrLf & "Are you sure?",52,"Sure?")
select case intBoxResult
case 6 ' Yes
location.replace("xx.asp?d
case 7 ' No
history.go(-1)
end select
</SCRIPT>
That will display a msgbox...
As and you can see it's possible to mix in ASP code (<%=intID%>....
~Gizmo
This might explain things a bit better.. =)
<%
Sub DisplayMsgBoxConfirm(intID )
<SCRIPT language="VBScript">
Dim intBoxResult
intBoxResult = MsgBox("Blaha Blaha" & vbCrLf & vbCrLf & "Are you sure?",52,"Sure?")
select case intBoxResult
case 6 ' Yes
location.replace("xx.asp?i d=<%=intID %>")
case 7 ' No
history.go(-1)
end select
</SCRIPT>
end sub
' blaha blaha....
DisplayMsgBoxConfirm(intID )
%>
One thing to think about is that ASP code is run before the VBScript....
~Gizmo
<%
Sub DisplayMsgBoxConfirm(intID
<SCRIPT language="VBScript">
Dim intBoxResult
intBoxResult = MsgBox("Blaha Blaha" & vbCrLf & vbCrLf & "Are you sure?",52,"Sure?")
select case intBoxResult
case 6 ' Yes
location.replace("xx.asp?i
case 7 ' No
history.go(-1)
end select
</SCRIPT>
end sub
' blaha blaha....
DisplayMsgBoxConfirm(intID
%>
One thing to think about is that ASP code is run before the VBScript....
~Gizmo
To clarify even further on what gizmo is saying...
You can use VBScript on the client-side to implement MsgBox, however, this will only be supported in IE browsers. For Javascript on the client-side, you'd have to use
<script language=javascript>
alert("This is your message.\n\nSee how it works?");
</script>
But CDec still is not supported.
You can use VBScript on the client-side to implement MsgBox, however, this will only be supported in IE browsers. For Javascript on the client-side, you'd have to use
<script language=javascript>
alert("This is your message.\n\nSee how it works?");
</script>
But CDec still is not supported.
ASKER
All the other msgboxes works fine.
but, what can I do with the CDec ? how can i cnvert Hex value to Decimal ???
thank you all for your comments.
but, what can I do with the CDec ? how can i cnvert Hex value to Decimal ???
thank you all for your comments.
ASKER
All the other msgboxes works fine.
but, what can I do with the CDec ? how can i cnvert Hex value to Decimal ???
thank you all for your comments.
but, what can I do with the CDec ? how can i cnvert Hex value to Decimal ???
thank you all for your comments.
<script language="VBScript">
Sub Hex2Dec(Hvalue, Dvalue)
dim q,a,p
if Left(Hvalue,2)<>"&h" or Left(Hvalue)<>"&H" then
alert("Wrong number format!")
else
q = mid(Hvalue,3)
Dvalue=0
while q<>""
a=left(q,1)
q=mid(q,2)
select case a
case "1"
p=0
case "2"
p=2
case "3"
p=3
case "4"
p=4
case "5"
p=5
case "6"
p=6
case "7"
p=7
case "8"
p=8
case "9"
p=9
case "A","a"
p=10
case "B","b"
p=11
case "C","c"
p=12
case "D","d"
p=13
case "E","e"
p=14
case "F","f"
p=15
case else
p=0
end select
Dvalue=Dvalue+p*16^len(q)
wend
end if
End Sub
</script>
<!---------* Call the proc *---------->
<body>
<script>
Hvalue="&hA23"
Call Hex2Dec(Hvalue,Dvalue)
alert(Dvalue)
</script>
</body>
Sub Hex2Dec(Hvalue, Dvalue)
dim q,a,p
if Left(Hvalue,2)<>"&h" or Left(Hvalue)<>"&H" then
alert("Wrong number format!")
else
q = mid(Hvalue,3)
Dvalue=0
while q<>""
a=left(q,1)
q=mid(q,2)
select case a
case "1"
p=0
case "2"
p=2
case "3"
p=3
case "4"
p=4
case "5"
p=5
case "6"
p=6
case "7"
p=7
case "8"
p=8
case "9"
p=9
case "A","a"
p=10
case "B","b"
p=11
case "C","c"
p=12
case "D","d"
p=13
case "E","e"
p=14
case "F","f"
p=15
case else
p=0
end select
Dvalue=Dvalue+p*16^len(q)
wend
end if
End Sub
</script>
<!---------* Call the proc *---------->
<body>
<script>
Hvalue="&hA23"
Call Hex2Dec(Hvalue,Dvalue)
alert(Dvalue)
</script>
</body>
What I can find CDec is only supported in VBA.
The workaround I found is to do the conversation in JavaScript...
using the object.toString function...
But I'm no JavaScript expert (But MSDN makes you one.. hehe)...
But I'm not sure that's the easiest way to do it..
~Gizmo
The workaround I found is to do the conversation in JavaScript...
using the object.toString function...
But I'm no JavaScript expert (But MSDN makes you one.. hehe)...
But I'm not sure that's the easiest way to do it..
~Gizmo
This function converts a hexadecimal value represented by a string into a decimal value.
Function HexToDec(strHex)
dim lngResult
dim intIndex
dim strDigit
dim intDigit
dim intValue
lngResult = 0
for intIndex = len(strHex) to 1 step -1
strDigit = mid(strHex, intIndex, 1)
intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
if intDigit >= 0 then
intValue = intDigit * (16 ^ (len(strHex)-intIndex))
lngResult = lngResult + intValue
else
lngResult = 0
intIndex = 0 ' stop the loop
end if
next
HexToDec = lngResult
End Function
Function HexToDec(strHex)
dim lngResult
dim intIndex
dim strDigit
dim intDigit
dim intValue
lngResult = 0
for intIndex = len(strHex) to 1 step -1
strDigit = mid(strHex, intIndex, 1)
intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
if intDigit >= 0 then
intValue = intDigit * (16 ^ (len(strHex)-intIndex))
lngResult = lngResult + intValue
else
lngResult = 0
intIndex = 0 ' stop the loop
end if
next
HexToDec = lngResult
End Function
Or try this, it's a bit simpler....
HexStr = "&h" & "FFFFFF"
If IsNumeric(HexStr) Then
Response.Write "Dec value: " & CLng(HexStr)
End If
HexStr = "&h" & "FFFFFF"
If IsNumeric(HexStr) Then
Response.Write "Dec value: " & CLng(HexStr)
End If
But you'd better check the length of the hex string first
a = "&hffffffff"
If IsNumeric(a) Then
response.write Cdbl(a)
End If
"ffffffff" is the largest hex number that will be converted with CLng
a = "&hffffffff"
If IsNumeric(a) Then
response.write Cdbl(a)
End If
"ffffffff" is the largest hex number that will be converted with CLng
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks !!! it works !!!
Yes, amazing isn't it?
Cheers, have a good day
Cheers, have a good day