티스토리 뷰

asp페이지에서 function사용


이전 내용 include

include 사용하면서 특정 파일에 function 을 모아놓으면 관리가 좀 편안함



'------------------------------------------------------------------------------------

' 문자열 자르기

'------------------------------------------------------------------------------------

' 설  명 : 문자열을 자른후 뒤에 지정된 문자를 붙여서 반환

' 일반형 : cutString(문자열, 자를길이, 뒤에 붙일문자)

' 예  제 : Title = cutString(Title, 20, "...")

'------------------------------------------------------------------------------------

Function cutString(ByVal str, ByVal strlen, ByVal addstr)

Dim rValue, nLength

Dim tmpStr, tmpLen

Dim f


nLength = 0.00

rValue  = ""

if str = "" Or IsNull(str) then

cutString = ""

else

for f = 1 to len(str)

tmpStr = MID(str,f,1)

tmpLen = ASC(tmpStr)


if (tmpLen < 0) then

nLength = nLength + 1.4

rValue = rValue & tmpStr

elseif (tmpLen >= 97 and tmpLen <= 122) then

nLength = nLength + 0.75

rValue = rValue & tmpStr

elseif (tmpLen >= 65 and tmpLen <= 90) then

nLength = nLength + 1

rValue = rValue & tmpStr

else

nLength = nLength + 0.6

rValue = rValue & tmpStr

end if


If (nLength > strlen) then

rValue = rValue & addstr

exit for

end if

next


cutString = rValue

end if

End Function



이런식으로. 구성된 것들을 쭉~ 늘어놓으면 관리도 쉽고.. 하지만..

같은 기능을 하는 것들은 모아 두는 것이 관리가 더 편리하다, 파일을 쪼개도 되고, 한 파일에 주석을 잘 활용해서 구분


'====================================================================================

' 문자열

'====================================================================================


이렇게.~

수동 그룹핑.;;;



가장 중요한 사용법을;;

사용법은 여러가지.


strTmpPassword = getRandomString(30)

이렇게 변수에 담아서


Response.Write strTmpPassword & "<br />"

이렇게 찍거나


Response.Write getRandomString(30)

바로 찍거나


Call alertMsg("완료되었습니다.", "history.back()")

이렇게 해도되고.