Tuesday, March 13, 2012

Should i change anything?

I'm just enquiring, i have a page full of functions in which would be alot of time and money to migrate to asp.net

I'm just wondering would i need to change anything about the following source code?

##############Code Start############

<%

function

k_f_getUserConfiguration(byVal strKey)

dim aryAdminUserConfiguration

aryAdminUserConfiguration = session(

"aryAdminUserConfiguration")

select

case strKeycase"kernel_userType_intCode"

k_f_getUserConfiguration = aryAdminUserConfiguration(0)

case"kernel_user_intKernel_user_PK"

k_f_getUserConfiguration = aryAdminUserConfiguration(1)

caseelse

k_f_getAdminUserConfiguration =

null

end select

end

function

function

k_f_getPageConfiguration(byVal strKey)

select

case strKeycase"intKernel_page_PK"

k_f_getPageConfiguration = k_v_aryThisPageConfiguration(0)

case"kernel_page_nvcharFileName"

k_f_getPageConfiguration = k_v_aryThisPageConfiguration(1)

case"intKernel_menuItem_PK"

k_f_getPageConfiguration = k_v_aryThisPageConfiguration(2)

case"intKernel_menuItem_PK_parent"

k_f_getPageConfiguration = k_v_aryThisPageConfiguration(3)

caseelse

k_f_getPageConfiguration =

null

end select

end

function

'retrieves values from the request

function

k_f_getRequest(byVal strVariableName)if lCase(request.serverVariables("request_method")) ="post" then

k_f_getRequest = trim(request.form(strVariableName))

else

k_f_getRequest = trim(request.queryString(strVariableName))

end

if

end

function

function

k_f_isEmail(byVal strValue)

dim regEx

set regEx =new regExp

regEx.ignoreCase =

true

regEx.pattern =

"^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@dotnet.itags.org.[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"

k_f_isEmail = regEx.test(strValue)

set regEx = nothing

end

function

'evaluates whether the input is an integer or not

function

k_f_isInteger(byVal value)

dim intRoundedNumber

if isNumeric(value) then

intRoundedNumber = cLng(value)

if intRoundedNumber = cDbl(value) then

k_f_isInteger =

trueelse

k_f_isInteger =

false

end

ifelse

k_f_isInteger =

false

end

if

end

function

'saves a client message in an array

sub k_f_saveClientMessage(byVal intMessageType, byVal strMessage)

session(

"aryClientMessage") = array(intMessageType, strMessage)

end sub

'dumps any existing client message

sub k_f_dumpClientMessage(byVal intMessageType, byVal strMessage)

session(

"aryClientMessage") =null

end sub

'renders a message out to the client

sub k_f_renderClientMessage()

dim intMessageType, strMessage

dim aryClientMessage

aryClientMessage = session(

"aryClientMessage")if isArray(aryClientMessage) then

intMessageType = aryClientMessage(0)

strMessage = aryClientMessage(1)

select

case intMessageTypecase k_v_intInformationMessage

response.write(

"<p class=""information"">" & strMessage &"</p>")case k_v_intErrorMessage

response.write(

"<p class=""error"">" & strMessage &"</p>")

end select

session(

"aryClientMessage") =nullelse

session(

"aryClientMessage") =null

end

if

end sub

sub k_f_renderHTMLOutput(byVal strText)

if not(isNull(strText)) then

response.write(server.htmlEncode(strText))

end

if

end sub

'sets the selected item in a check / select box

function

k_f_isSelected(byVal valueA, byVal valueB, byVal returnString)

dim strTempValueA, strTempValueB

if isNull(valueA) then

strTempValueA =

""else

strTempValueA = lCase(cStr(valueA))

end

ifif isNull(valueB) then

strTempValueB =

""else

strTempValueB = lCase(cStr(valueB))

end

ifif strTempValueA = strTempValueB then

k_f_isSelected = returnString

else

k_f_isSelected =

""

end

if

end

function

function

k_f_generatePassword()

dim intCharacterNumber, strPassword, i

dim intFirstNumberLocation, intSecondNumberLocation

randomize

intFirstNumberLocation =

int((k_v_intPasswordLength - 1 + 1) * rnd + 1)

randomize

intSecondNumberLocation =

int((k_v_intPasswordLength - 1 + 1) * rnd + 1)if (intSecondNumberLocation = intFirstNumberLocation) and (intFirstNumberLocation = k_v_intPasswordLength) then

intSecondNumberLocation = intSecondNumberLocation - 1

elseif (intSecondNumberLocation = intFirstNumberLocation) then

intSecondNumberLocation = intSecondNumberLocation + 1

end

iffor i = 1 to k_v_intPasswordLength

randomize

if (i = intFirstNumberLocation) or (i = intSecondNumberLocation) then

strPassword = strPassword & cstr(

int((9 - 0 + 1) * rnd + 0))else

intCharacterNumber =

int((122 - 97 + 1) * rnd + 97)

'l as a strPassword character is causing confusion - prevent l from being accepted

if (intCharacterNumber = 108) then

intCharacterNumber = 109

end

if

strPassword = strPassword & chr(intCharacterNumber)

end

if

next

k_f_generatePassword = strPassword

end

function

sub k_f_renderDoubleURLOutput(byVal strText)

if not(isNull(strText)) then

response.write(server.urlEncode(server.urlEncode(strText)))

end

if

end sub

function

k_f_renderTextForSQL(byVal strText)if not(isNull(strText)) then

k_f_renderTextForSQL = replace(strText,

"'","''")else

k_f_renderTextForSQL =

""

end

if

end

function

'creates a recordset sorting string

function

k_f_createSortString(byVal strPrimarySortColumn, byVal strPrimarySortOrder, byVal strDefaultSort, byVal rst)

dim objField, blnColumnExists, strSortOrder

if len(strPrimarySortColumn) > 0 and len(strPrimarySortOrder) > 0 then

blnColumnExists =

falsefor each objFieldin rst.fieldsif lCase(strPrimarySortColumn) = lCase(objField.name) then

blnColumnExists =

true

exit

for

end

if

next

if blnColumnExists thenif (len(strPrimarySortOrder) = 0) or ((lCase(strPrimarySortOrder) <>"asc") and (lCase(strPrimarySortOrder) <>"desc")) then

k_f_createSortString = strDefaultSort

elseif len(strDefaultSort) > 0 then

strSortOrder = strPrimarySortColumn &

" " & strPrimarySortOrder &", " & strDefaultSortelse

strSortOrder = strPrimarySortColumn &

" " & strPrimarySortOrder

end

if

k_f_createSortString = strSortOrder

end

ifelse

k_f_createSortString = strDefaultSort

end

ifelse

k_f_createSortString = strDefaultSort

end

if

end

function

'returns the primary sort parameters of a given sort string

function

k_f_getPrimarySort(byVal strSort)

dim strPrimaryColumn, strPrimaryOrder

dim strPrimarySort

if inStr(strSort,",") > 0 then

strPrimarySort = trim(left(strSort, (inStr(strSort,

",")-1)))if inStr(strPrimarySort," ") > 0 then

strPrimaryColumn = trim(left(strPrimarySort, inStr(strPrimarySort,

" ")))

strPrimaryOrder = right(strPrimarySort, (len(strPrimarySort) - inStr(strPrimarySort,

" ")))else

strPrimaryColumn = trim(strPrimarySort)

strPrimaryOrder =

"asc"

end

ifelse

strPrimarySort = trim(strSort)

if inStr(strPrimarySort," ") > 0 then

strPrimaryColumn = trim(left(strPrimarySort, inStr(strPrimarySort,

" ")))

strPrimaryOrder = right(strPrimarySort, (len(strPrimarySort) - inStr(strPrimarySort,

" ")))else

strPrimaryColumn = trim(strPrimarySort)

strPrimaryOrder =

"asc"

end

if

end

if

k_f_getPrimarySort = array(strPrimaryColumn, strPrimaryOrder)

end

function

'returns a valid scroll to page

function

k_f_createValidScrollToPage(byVal intScrollToPage, byVal rst)if len(intScrollToPage) > 0 thenif isNumeric(intScrollToPage) then

intScrollToPage = cInt(intScrollToPage)

if intScrollToPage < 1 then

k_f_createValidScrollToPage = 1

elseif intScrollToPage> rst.pageCount then

k_f_createValidScrollToPage = rst.pageCount

else

k_f_createValidScrollToPage = intScrollToPage

end

if

end

ifelse

k_f_createValidScrollToPage = 1

end

ifelse

k_f_createValidScrollToPage = 1

end

if

end

function

'renders the header of a standard paging recordset

sub k_f_renderPagingRecordsetHeader(byVal rst)

if not(rst.bof and rst.eof) thenif rst.recordCount = 1 then

response.write(rst.recordCount &

" record found.")else

response.write(rst.recordCount &

" records found.")

end

ifif rst.pageCount > 1 then

response.write(

" Showing page " & rst.absolutePage &" of " & rst.pageCount &".")

end

if

end

if

end sub

'renders the footer of a standard paging recordset

sub k_f_renderPagingRecordsetFooter(byVal rst, byVal strPagingURL, byVal strThisPrimarySortColumn, byVal strThisPrimarySortOrder)

dim strRecordsetFooter, i

dim intPagesToDisplay, intCurrentPage

intPagesToDisplay = 4

'set the current page

if rst.absolutePosition = adPosEOF then

intCurrentPage = rst.pageCount

else

intCurrentPage = rst.absolutePage - 1

end

ifif not(rst.bof and rst.eof) thenif inStr(strPagingURL,"?") > 0 then

strPagingURL = strPagingURL &

"&strPrimarySortColumn=" & strThisPrimarySortColumn &"&strPrimarySortOrder=" & strThisPrimarySortOrderelse

strPagingURL = strPagingURL &

"?strPrimarySortColumn=" & strThisPrimarySortColumn &"&strPrimarySortOrder=" & strThisPrimarySortOrder

end

ifif rst.pageCount > 1 then

strRecordsetFooter = strRecordsetFooter &

"<div class=""Paging-Recordset-Footer"">"if (intCurrentPage > 1) or (rst.absolutePage = adPosEOF) then

strRecordsetFooter = strRecordsetFooter &

"<div class=""Paging-Recordset-Footer-Left"">"if rst.absolutePage = adPosEOF then

strRecordsetFooter = strRecordsetFooter &

"<a href="http://links.10026.com/?link="" & strPagingURL &"&intScrollToPage=1""> |« </a> <a href="http://links.10026.com/?link="" & strPagingURL &"&intScrollToPage=" & (rst.pageCount - 1) &"""> « </a>"else

strRecordsetFooter = strRecordsetFooter &

"<a href="http://links.10026.com/?link="" & strPagingURL &"&intScrollToPage=1""> |« </a> <a href="http://links.10026.com/?link="" & strPagingURL &"&intScrollToPage=" & (intCurrentPage - 1) &"""> « </a>"

end

if

strRecordsetFooter = strRecordsetFooter &

"</div>"

end

if

strRecordsetFooter = strRecordsetFooter &

"<div class=""Paging-Recordset-Footer-Pages"">"

'count from below to current page

for i = 0 to intPagesToDisplayif ((intCurrentPage - (intPagesToDisplay - i)) > 0) and ((intCurrentPage - (intPagesToDisplay - i)) < intCurrentPage) then

strRecordsetFooter = strRecordsetFooter &

"<a href="http://links.10026.com/?link="" & strPagingURL &"&intScrollToPage=" & cStr(intCurrentPage - (intPagesToDisplay - i)) &"""> " & cStr(intCurrentPage - (intPagesToDisplay - i)) &" </a>"

end

if

next

'count current page

strRecordsetFooter = strRecordsetFooter &

"<span class=""list_nav_act""> " & cStr(intCurrentPage) &" </span>"

'count to further page

for i = 1 to intPagesToDisplayif ((intCurrentPage + i) <= rst.pageCount) then

strRecordsetFooter = strRecordsetFooter &

"<a href="http://links.10026.com/?link="" & strPagingURL &"&intScrollToPage=" & cStr(intCurrentPage + i) &"""> " & cStr(intCurrentPage + i) &" </a>"

end

if

next

strRecordsetFooter = strRecordsetFooter &

"</div>"if (intCurrentPage < rst.pageCount) and (rst.absolutePage <> adPosEOF) then

strRecordsetFooter = strRecordsetFooter &

"<div class=""Paging-Recordset-Footer-Right"">"

strRecordsetFooter = strRecordsetFooter &

"<a href="http://links.10026.com/?link="" & strPagingURL &"&intScrollToPage=" & (intCurrentPage + 1) &"""> » </a> <a href="http://links.10026.com/?link="" & strPagingURL &"&intScrollToPage=" & rst.pageCount &"""> »| </a>"

strRecordsetFooter = strRecordsetFooter &

"</div>"

end

if

strRecordsetFooter = strRecordsetFooter &

"<br style=""clear: both;"" /></div>"

response.write(strRecordsetFooter)

end

if

end

if

end sub

'renders the heading of a sortable column in standard paging recordset

sub k_f_renderColumnHeading(byVal strHeadingName, byVal strHeadingCode, byVal strHeadingURL, byVal strThisPrimarySortColumn, byVal strThisPrimarySortOrder)

dim strOrderToSort

if (strThisPrimarySortOrder ="asc") and (strThisPrimarySortColumn = strHeadingCode) then

strOrderToSort =

"desc"else

strOrderToSort =

"asc"

end

ifif inStr(strHeadingURL,"?") > 0 then

strHeadingURL = strHeadingURL &

"&strPrimarySortColumn=" & strHeadingCode &"&strPrimarySortOrder=" & strOrderToSortelse

strHeadingURL = strHeadingURL &

"?strPrimarySortColumn=" & strHeadingCode &"&strPrimarySortOrder=" & strOrderToSort

end

ifif strThisPrimarySortColumn = strHeadingCode thenif strThisPrimarySortOrder ="asc" then

response.write(

"<a href="http://links.10026.com/?link="" & strHeadingURL &""">" & strHeadingName &"</a> <img src="http://pics.10026.com/?src="theme/list_asc.gif"" heigth=""7"" width=""12"" border=""0"">")else

response.write(

"<a href="http://links.10026.com/?link="" & strHeadingURL &""">" & strHeadingName &"</a> <img src="http://pics.10026.com/?src="theme/list_desc.gif"" heigth=""7"" width=""12"" border=""0"">")

end

ifelse

response.write(

"<a href="http://links.10026.com/?link="" & strHeadingURL &""">" & strHeadingName &"</a>")

end

if

end sub

'returns an array of keywords from a list containing spaces and ""

function

k_f_getKeywords(byVal strKeywords)

dim blnInReplaceZone, strMouldedSearchText, strSubString, i, aryKeywords

if len(strKeywords) > 0 then

aryKeywords = split(strKeywords,

" ")else

aryKeywords =

null

end

if

k_f_getKeywords = aryKeywords

end

function

function

k_f_prepareForADOParameter(byVal value, byVal intDataType, byVal lngLength)

dim tempValue

tempValue = value

select

case intDataTypecase adIntegerif not(k_f_isInteger(tempValue)) then

tempValue =

nullelse

tempValue = cLng(tempValue)

end

ifcase adVarCharif not(isNull(tempValue)) then

tempValue = cStr(tempValue)

if len(tempValue) = 0 then

tempValue =

nullelse

tempValue = left(tempValue, lngLength)

end

if

end

ifcase adBooleanif varType(tempValue) <> vbBoolean then

tempValue = cBool(tempValue)

end

ifcase adDateif isDate(tempValue) then

tempValue = cDate(tempValue)

else

tempValue =

null

end

ifcase adDoubleif isNumeric(tempValue) then

tempValue = cDbl(tempValue)

else

tempValue =

null

end

ifcase adGUIDif len(tempValue) = 0 then

tempValue =

null

end

if

end select

k_f_prepareForADOParameter = tempValue

end

function

'returns an array of partnumbers from a list separated by vbCRLF

function

k_f_getPartnumbers(byVal strKeywords)

dim aryPartnumbers, i

if len(strKeywords) > 0 then

aryPartnumbers = split(strKeywords, vbCRLF)

for i = 0 to uBound(aryPartnumbers)

aryPartnumbers(i) = trim(aryPartnumbers(i))

next

else

aryPartnumbers =

null

end

if

k_f_getPartnumbers = aryPartnumbers

end

function

function

k_f_prepareForXMLOutput(value)

dim strOutput

'there are 5 special characters that need to be replaced in any data represented by XML

'& with &

'< with <

'> with >

'" with "

''with 'if isNull(value) then

k_f_prepareForXMLOutput =

""else

strOutput = cStr(value)

if len(strOutput) > 0 then

strOutput = replace(strOutput,

"&","&")

strOutput = replace(strOutput,

"<","<")

strOutput = replace(strOutput,

">",">")

strOutput = replace(strOutput,

"""",""")

strOutput = replace(strOutput,

"'","'")

end

if

k_f_prepareForXMLOutput = strOutput

end

if

end

function

function

k_f_prepareForXMLDateOutput(dtmValue)

dim strYear, strMonth, strDay

if isDate(dtmValue) then

strYear = cStr(datePart(

"yyyy", dtmValue))

strMonth = cStr(datePart(

"m", dtmValue))

strDay = cStr(datePart(

"d", dtmValue))if len(strMonth) = 1 then

strMonth =

"0" & strMonth

end

ifif len(strDay) = 1 then

strDay =

"0" & strDay

end

if

k_f_prepareForXMLDateOutput = strYear &

"-" & strMonth &"-" & strDayelse

k_f_prepareForXMLDateOutput =

null

end

if

end

function

function

k_f_prepareForXMLDateTimeOutput(dtmValue)

dim strYear, strMonth, strDay

dim strHour, strMinute, strSecond

if isDate(dtmValue) then

strYear = cStr(datePart(

"yyyy", dtmValue))

strMonth = cStr(datePart(

"m", dtmValue))

strDay = cStr(datePart(

"d", dtmValue))

strHour = cStr(datePart(

"h", dtmValue))

strMinute = cStr(datePart(

"n", dtmValue))

strSecond = cStr(datePart(

"s", dtmValue))if len(strMonth) = 1 then

strMonth =

"0" & strMonth

end

ifif len(strDay) = 1 then

strDay =

"0" & strDay

end

ifif len(strHour) = 1 then

strHour =

"0" & strHour

end

ifif len(strMinute) = 1 then

strMinute =

"0" & strMinute

end

ifif len(strSecond) = 1 then

strSecond =

"0" & strSecond

end

if

k_f_prepareForXMLDateTimeOutput = strYear &

"-" & strMonth &"-" & strDay &"T" & strHour &":" & strMinute &":" & strSecondelse

k_f_prepareForXMLDateTimeOutput =

null

end

if

end

function

function

k_f_prepareForXMLBooleanOutput(blnValue)if blnValue then

k_f_prepareForXMLBooleanOutput =

"true"else

k_f_prepareForXMLBooleanOutput =

"false"

end

if

end

function

function

k_f_getXMLValueFromSingleNode(byVal objNode, byVal intDataType)if objNode is nothing then

k_f_getXMLValueFromSingleNode =

nullelse

select

case intDataTypecase adVarChar

k_f_getXMLValueFromSingleNode = replace(trim(objNode.text), vbLF, vbCRLF)

caseelse

k_f_getXMLValueFromSingleNode = trim(objNode.text)

end select

end

if

end

function

function

k_f_renderIndent(byVal intSize, byVal intOffset)

k_f_renderIndent = string(intSize - intOffset,

" ")

end

function

function

k_f_RC4(ByRef pStrMessage, ByRef pStrKey)

Dim lBytAsciiAry(255)

Dim lBytKeyAry(255)

Dim lLngIndex

Dim lBytJump

Dim lBytTemp

Dim lBytY

Dim lLngT

Dim lLngX

Dim lLngKeyLength

' Validate data

If Len(pStrKey) = 0 Then Exit Function

If Len(pStrMessage) = 0 Then Exit Function

' transfer repeated key to array

lLngKeyLength = Len(pStrKey)

For lLngIndex = 0 To 255

lBytKeyAry(lLngIndex) = Asc(Mid(pStrKey, ((lLngIndex) Mod (lLngKeyLength)) + 1, 1))

Next

' Initialize S

For lLngIndex = 0 To 255

lBytAsciiAry(lLngIndex) = lLngIndex

Next

' Switch values of S arround based off of index and Key value

lBytJump = 0

For lLngIndex = 0 To 255

' Figure index to switch

lBytJump = (lBytJump + lBytAsciiAry(lLngIndex) + lBytKeyAry(lLngIndex)) Mod 256

' Do the switch

lBytTemp = lBytAsciiAry(lLngIndex)

lBytAsciiAry(lLngIndex) = lBytAsciiAry(lBytJump)

lBytAsciiAry(lBytJump) = lBytTemp

Next

lLngIndex = 0

lBytJump = 0

For lLngX = 1 To Len(pStrMessage)

lLngIndex = (lLngIndex + 1) Mod 256 ' wrap index

lBytJump = (lBytJump + lBytAsciiAry(lLngIndex)) Mod 256 ' wrap J+S()

' Add/Wrap those two

lLngT = (lBytAsciiAry(lLngIndex) + lBytAsciiAry(lBytJump)) Mod 256

' Switcheroo

lBytTemp = lBytAsciiAry(lLngIndex)

lBytAsciiAry(lLngIndex) = lBytAsciiAry(lBytJump)

lBytAsciiAry(lBytJump) = lBytTemp

lBytY = lBytAsciiAry(lLngT)

' Character Encryption ...

k_f_RC4 = k_f_RC4 & Chr(Asc(Mid(pStrMessage, lLngX, 1)) Xor lBytY)

Next

end

function

%>

########Code End###########

Would i have to change anything of the above source code? Or would i have to go through and re-do the entire thing?

I hope not :( only have about 7 days left to finish this project, and this file took about a week to code and debug

Cheers for the help

Looking at the code, I think its good idea to rewrite complete code in ASP.NET using existing logic from existing ASP code. If you decided to change in existing code, then you will lead to make modification in each and every line.

0 comments:

Post a Comment