Help, please please please!!!! Inputing a Hexadecimal Number 
Author Message
 Help, please please please!!!! Inputing a Hexadecimal Number

Hello all.  I have spent more time on this stupid little problem than I did
on my whole ASP Web application.  I have an ASP Web application that calls a
COM DLL.  The DLL returns a safearray of information (6 bytes) which I then
post to an access database.  This all works fine.  Now I need to allow the
user to input the 6 bytes (in HEX form) into a form and then post that
information to the database.  This code dosen't work.  I am trying to do it
all with Server Side Scripting.  The program flow goes like this.  The user
inputs the six hex numbers into a text field in a form.  The form is
submitted to a seperate ASP page for processing.  Here, I am trying to
convert the text string into a format that access will except.  Now, I am
always getting Type Mismatches on the data.  Below is the ENTIRE code for
the second ASP page.  If someone could have a peek and tell me what you
think, it would be great!

Thanks, Mike

<%
Function getHexAsInteger( hexstr )
 dim validHex
 validHex = "0123456789abcdefABCDEF"
 ' first, validate:
 For hc = 1 To Len( hexstr )
  If InStr( validHex, Mid(hexstr,hc,1) ) Then
   ' invalid number!  do something radical!
   getHexAsInteger = "Invalid HEX character(s) in " & hexstr
   Exit Function
  End If
 Next
 ' string is valid!
 getHexAsInteger = Cbyte("&H" & hexstr)

End Function
%>

<%
'Revision # .044
'June 10, 1999
'
'This Active Server Page was created and designed by:
'
'   Michael S. Kazmier
'   Network Administrator
'   University of Northern Colorado

'   (970) 351-1407
'
'This file and all associated files are copywrited by the above mentioned
party
'and are provided to the University of Northern Colorado royalty free.
'
'This product carries no written or implied warrantees.
'
'
'
'

%>
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>UNC DHCP Registration</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">

<div align="center"><center>

</head>

<body>
<table border="1" width="640" cellspacing="0" cellpadding="6">
  <tr>
    <td width="100%" colspan="2" align="middle"><strong><big><big><big><FONT
color=#000080
            face=Tahoma>
            <TABLE border=0 cellPadding=1 cellSpacing=1 width=100%>

                <TR>
                    <TD><IMG height=138
                        src="../images/UNC_Logo_Solid_Blue.gif"
                        style="HEIGHT: 138px; WIDTH: 131px" width=131
                        ></TD>
                    <TD>
                        <DIV align=center><STRONG><EM><FONT color=navy
face=""
                        size=6>Welcome
                        to the UNC DHCP Registration

System</FONT></EM></STRONG></DIV></TD></TR></TABLE></FONT></big></big></big>
</strong></td>
  </tr>
  <tr><td width="100%" colspan="2" bgcolor="#800000" align="middle"><font
color="#ffffff">
<h2>Thank You</h2></td></tr>
<tr><td width="100%" colspan="2"><center>
<%
Dim con
Dim rst
' Declare the Open method constants for database access
Const adOpen = 2
Const adLock = 3
Const adCmdText = 1

Set con = Server.CreateObject("ADODB.Connection")
con.Open "DHCPdsn", "Admin", ""
Set rst = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblMAC"
rst.Open strSQL, con, adOpen, adLock, adCmdText
rst.AddNew
if Request("AddMac")="true" then

 RegMac1 = getHexAsInteger(Request("MACaddress1"))
 If VarType( RegMac1 ) = 8 Then
  ' string returned instead of number...must
  ' be error message
  %>
  <script language=javascript>
  alert("Error: " & RegMac1);
  location.href="register.asp";
  </script>
  <%
 End If
 RegMac2 = getHexAsInteger(Request("MACaddress2"))
 If VarType( RegMac2 ) = 8 Then
  ' string returned instead of number...must
  ' be error message
  %>
  <script language=javascript>
  alert("Error: " & RegMac2);
  location.href="register.asp";
  </script>
  <%
 End If
 RegMac3 = getHexAsInteger(Request("MACaddress3"))
 If VarType( RegMac3 ) = 8 Then
  ' string returned instead of number...must
  ' be error message
  %>
  <script language=javascript>
  alert("Error: " & RegMac3);
  location.href="register.asp";
  </script>
  <%
 End If
 RegMac4 = getHexAsInteger(Request("MACaddress4"))
 If VarType( RegMac4 ) = 8 Then
  ' string returned instead of number...must
  ' be error message
  %>
  <script language=javascript>
  alert("Error: " & RegMac4);
  location.href="register.asp";
  </script>
  <%
 End If
 RegMac5 = getHexAsInteger(Request("MACaddress5"))
 If VarType( RegMac5 ) = 8 Then
  ' string returned instead of number...must
  ' be error message
  %>
  <script language=javascript>
  alert("Error: " & RegMac5);
  location.href="register.asp";
  </script>
  <%
 End If
 RegMac6 = getHexAsInteger(Request("MACaddress6"))
 If VarType( RegMac6 ) = 8 Then
  ' string returned instead of number...must
  ' be error message
  %>
  <script language=javascript>
  alert("Error: " & RegMac6);
  location.href="register.asp";
  </script>
  <%
 End If

 rst("MACaddress1")=RegMac1
 rst("MACaddress2")=RegMac2
 rst("MACaddress3")=RegMac3
 rst("MACaddress4")=RegMac4
 rst("MACaddress5")=RegMac5
 rst("MACaddress6")=RegMac6
 rst("UserID")=Request.Form("UserID")
 rst("UserIDCreated")=Session("UserID")
 rst("DateCreated")=Date()
 rst("Student")=False
 rst("Staff")=True
 rst("Resnet")=False
 rst("TagNumber")=Request.Form("TagNumber")
 rst("DateActivated")=NULL
 rst("Delete")=FALSE
 rst("DeleteDate")=NULL
 rst("DeleteUserID")=NULL

else

 rst("MACaddress1")=Session("MACaddress1")
 rst("MACaddress2")=Session("MACaddress2")
 rst("MACaddress3")=Session("MACaddress3")
 rst("MACaddress4")=Session("MACaddress4")
 rst("MACaddress5")=Session("MACaddress5")
 rst("MACaddress6")=Session("MACaddress6")
 rst("UserID")=Session("UserID")
 rst("UserIDCreated")=Session("UserIDCreated")
 rst("DateCreated")=Date()
 rst("Student")=Session("Student")
 rst("Staff")=Session("Staff")
 rst("Resnet")=Session("Resnet")
 rst("TagNumber")=Session("TagNumber")
 if Session("Resnet") = true then
  rst("DateActivated")=Date()
 else
  rst("DateActivated")=NULL
 end if
 rst("Delete")=FALSE
 rst("DeleteDate")=NULL
 rst("DeleteUserID")=NULL
end if
rst.Update
rst.Close
con.Close

%>
<BODY>

<P>&nbsp;</P>
<font size=4>The operation was Successful!!!</font><p>
<A href="register.asp">Return</a> to registration home page...
</td></tr></table>
</BODY>
</HTML>



Sat, 01 Dec 2001 03:00:00 GMT  
 Help, please please please!!!! Inputing a Hexadecimal Number
Sounds like what you need to do in script is build a variant containing an
array of bytes.  Just to be sure, query the data returned by the DLL returns
a safearray of information (6 bytes) with VarType.  If you get 8209 --- 8192
(vbArray) + 17 (vbByte), then that's what you need to create from user input
via script.

The problem is that in VBScript you can't create such an animal.  The
closest you can come is array of variants of subtype byte.  If the COM DLL
is one of yours, then consider adding a function that will take something
you _can_ create in script and return the same sort of safearray of
information (6 bytes).

If the COM DLL _isn't_ yours, you'll probably have to write one to do
this...

--
Michael Harris


| Hello all.  I have spent more time on this stupid little problem than I
did
| on my whole ASP Web application.  I have an ASP Web application that calls
a
| COM DLL.  The DLL returns a safearray of information (6 bytes) which I
then
| post to an access database.  This all works fine.  Now I need to allow the
| user to input the 6 bytes (in HEX form) into a form and then post that
| information to the database.  This code dosen't work.  I am trying to do
it
| all with Server Side Scripting.  The program flow goes like this.  The
user
| inputs the six hex numbers into a text field in a form.  The form is
| submitted to a seperate ASP page for processing.  Here, I am trying to
| convert the text string into a format that access will except.  Now, I am
| always getting Type Mismatches on the data.  Below is the ENTIRE code for
| the second ASP page.  If someone could have a peek and tell me what you
| think, it would be great!
|
| Thanks, Mike
|
| <%
| Function getHexAsInteger( hexstr )
|  dim validHex
|  validHex = "0123456789abcdefABCDEF"
|  ' first, validate:
|  For hc = 1 To Len( hexstr )
|   If InStr( validHex, Mid(hexstr,hc,1) ) Then
|    ' invalid number!  do something radical!
|    getHexAsInteger = "Invalid HEX character(s) in " & hexstr
|    Exit Function
|   End If
|  Next
|  ' string is valid!
|  getHexAsInteger = Cbyte("&H" & hexstr)
|
| End Function
| %>
|
|
| <%
| 'Revision # .044
| 'June 10, 1999
| '
| 'This Active Server Page was created and designed by:
| '
| '   Michael S. Kazmier
| '   Network Administrator
| '   University of Northern Colorado

| '   (970) 351-1407
| '
| 'This file and all associated files are copywrited by the above mentioned
| party
| 'and are provided to the University of Northern Colorado royalty free.
| '
| 'This product carries no written or implied warrantees.
| '
| '
| '
| '
|
| %>
| <HTML>
| <head>
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
| <title>UNC DHCP Registration</title>
| <meta name="GENERATOR" content="Microsoft FrontPage 3.0">
|
| <div align="center"><center>
|
| </head>
|
| <body>
| <table border="1" width="640" cellspacing="0" cellpadding="6">
|   <tr>
|     <td width="100%" colspan="2"
align="middle"><strong><big><big><big><FONT
| color=#000080
|             face=Tahoma>
|             <TABLE border=0 cellPadding=1 cellSpacing=1 width=100%>
|
|                 <TR>
|                     <TD><IMG height=138
|                         src="../images/UNC_Logo_Solid_Blue.gif"
|                         style="HEIGHT: 138px; WIDTH: 131px" width=131
|                         ></TD>
|                     <TD>
|                         <DIV align=center><STRONG><EM><FONT color=navy
| face=""
|                         size=6>Welcome
|                         to the UNC DHCP Registration
|
|
System</FONT></EM></STRONG></DIV></TD></TR></TABLE></FONT></big></big></big>
| </strong></td>
|   </tr>
|   <tr><td width="100%" colspan="2" bgcolor="#800000" align="middle"><font
| color="#ffffff">
| <h2>Thank You</h2></td></tr>
| <tr><td width="100%" colspan="2"><center>
| <%
| Dim con
| Dim rst
| ' Declare the Open method constants for database access
| Const adOpen = 2
| Const adLock = 3
| Const adCmdText = 1
|
|
|
| Set con = Server.CreateObject("ADODB.Connection")
| con.Open "DHCPdsn", "Admin", ""
| Set rst = Server.CreateObject("ADODB.Recordset")
| strSQL = "SELECT * FROM tblMAC"
| rst.Open strSQL, con, adOpen, adLock, adCmdText
| rst.AddNew
| if Request("AddMac")="true" then
|
|
|
|  RegMac1 = getHexAsInteger(Request("MACaddress1"))
|  If VarType( RegMac1 ) = 8 Then
|   ' string returned instead of number...must
|   ' be error message
|   %>
|   <script language=javascript>
|   alert("Error: " & RegMac1);
|   location.href="register.asp";
|   </script>
|   <%
|  End If
|  RegMac2 = getHexAsInteger(Request("MACaddress2"))
|  If VarType( RegMac2 ) = 8 Then
|   ' string returned instead of number...must
|   ' be error message
|   %>
|   <script language=javascript>
|   alert("Error: " & RegMac2);
|   location.href="register.asp";
|   </script>
|   <%
|  End If
|  RegMac3 = getHexAsInteger(Request("MACaddress3"))
|  If VarType( RegMac3 ) = 8 Then
|   ' string returned instead of number...must
|   ' be error message
|   %>
|   <script language=javascript>
|   alert("Error: " & RegMac3);
|   location.href="register.asp";
|   </script>
|   <%
|  End If
|  RegMac4 = getHexAsInteger(Request("MACaddress4"))
|  If VarType( RegMac4 ) = 8 Then
|   ' string returned instead of number...must
|   ' be error message
|   %>
|   <script language=javascript>
|   alert("Error: " & RegMac4);
|   location.href="register.asp";
|   </script>
|   <%
|  End If
|  RegMac5 = getHexAsInteger(Request("MACaddress5"))
|  If VarType( RegMac5 ) = 8 Then
|   ' string returned instead of number...must
|   ' be error message
|   %>
|   <script language=javascript>
|   alert("Error: " & RegMac5);
|   location.href="register.asp";
|   </script>
|   <%
|  End If
|  RegMac6 = getHexAsInteger(Request("MACaddress6"))
|  If VarType( RegMac6 ) = 8 Then
|   ' string returned instead of number...must
|   ' be error message
|   %>
|   <script language=javascript>
|   alert("Error: " & RegMac6);
|   location.href="register.asp";
|   </script>
|   <%
|  End If
|
|
|  rst("MACaddress1")=RegMac1
|  rst("MACaddress2")=RegMac2
|  rst("MACaddress3")=RegMac3
|  rst("MACaddress4")=RegMac4
|  rst("MACaddress5")=RegMac5
|  rst("MACaddress6")=RegMac6
|  rst("UserID")=Request.Form("UserID")
|  rst("UserIDCreated")=Session("UserID")
|  rst("DateCreated")=Date()
|  rst("Student")=False
|  rst("Staff")=True
|  rst("Resnet")=False
|  rst("TagNumber")=Request.Form("TagNumber")
|  rst("DateActivated")=NULL
|  rst("Delete")=FALSE
|  rst("DeleteDate")=NULL
|  rst("DeleteUserID")=NULL
|
| else
|
|  rst("MACaddress1")=Session("MACaddress1")
|  rst("MACaddress2")=Session("MACaddress2")
|  rst("MACaddress3")=Session("MACaddress3")
|  rst("MACaddress4")=Session("MACaddress4")
|  rst("MACaddress5")=Session("MACaddress5")
|  rst("MACaddress6")=Session("MACaddress6")
|  rst("UserID")=Session("UserID")
|  rst("UserIDCreated")=Session("UserIDCreated")
|  rst("DateCreated")=Date()
|  rst("Student")=Session("Student")
|  rst("Staff")=Session("Staff")
|  rst("Resnet")=Session("Resnet")
|  rst("TagNumber")=Session("TagNumber")
|  if Session("Resnet") = true then
|   rst("DateActivated")=Date()
|  else
|   rst("DateActivated")=NULL
|  end if
|  rst("Delete")=FALSE
|  rst("DeleteDate")=NULL
|  rst("DeleteUserID")=NULL
| end if
| rst.Update
| rst.Close
| con.Close
|
| %>
| <BODY>
|
| <P>&nbsp;</P>
| <font size=4>The operation was Successful!!!</font><p>
| <A href="register.asp">Return</a> to registration home page...
| </td></tr></table>
| </BODY>
| </HTML>
|
|
|



Sat, 01 Dec 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

2. Can anyone HELP me PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE

3. PLEASE HELP PLEASE HELP PLEASE HELP

4. PLEASE PLEASE PLEASE HELP!!!!

5. Design Help PLEASE PLEASE PLEASE!

6. Please Please PLEASE HELP!!!!!

7. URGENT HELP PLEASE PLEASE PLEASE???

8. Please please please, help me :-)

9. Please, Please, Please I need help working with dates

10. Please, please, please help!!

11. Cloning problem -- please please please help

12. Please, please, please, help!

 

 
Powered by phpBB® Forum Software