달력

42024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

function ReadFromTextFile (FileUrl,CharSet)
    dim str
    set stm=server.CreateObject("adodb.stream")
    stm.Type=2 'for text type
    stm.mode=3
    stm.charset=CharSet
    stm.open
    stm.loadfromfile FileUrl
    str=stm.readtext
 response.write str
    stm.Close
    set stm=nothing
    ReadFromTextFile=str
end function

 
Sub WriteToTextFile (FileUrl,byval Str,CharSet)       
    set stm=server.CreateObject("adodb.stream")
    stm.Type=2 'for text type
    stm.mode=3
    stm.charset=CharSet
    stm.open
    stm.WriteText str
    stm.SaveToFile fileurl,2   
    stm.flush
    stm.Close
    set stm=nothing
end sub

Readfile=readfromtextfile ("c:/11/readfilename.csv","utf-8")
writetotextfile "c:/11/writefilename.txt",Readfile,"utf-8"

 

일부 텍스트 파일은 한 줄 끝에 줄 넘기는 문자로 인해 텍스트 파일을 쓸 때 약간의 문제가 생길 수 있다

dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.CreateTextFile("c:/11/writefilename.txt",true)
f.write(readfile)
'f.write("How are you today?")
f.close
set f=nothing
set fs=nothing

을 사용하면 문제가 해결 될 수 있다

 

function은 리턴값이 ReadFromTextFile이 된다. 즉 함수명과 동일한 이름에 리턴값을 저장해야 한다.

sub는 리턴값이 없다. 단지 실행만 할뿐이다.

호출에서도 차이가 있다.

-----------------------------------------------------------------------------------

ASP에서 사용하는 Sub, Function

Sub는 단독 동작
Function은 동작하며 반환값을 돌려주는 녀석입니다.

Sub를 사용한 예제를 보면

Sub TestSub1()
  response.write("TestSub1성공"&"<br>")
End Sub
TestSub1()

Sub TestSub2(Astr)
  response.write("TestSub2성공"& Astr &"<br>")
End Sub
TestSub2("냠냠")

Sub TestSub3(Aint)
  response.write("TestSub3성공"& Aint+99 &"<br>")
End Sub
TestSub3(1)

Sub TestSub4(Aint,Bint)
  response.write("TestSub4성공"& Aint+Bint &"<br>")
End Sub
'TestSub4(1,99) ==> 이렇게 하면 에러납니다. *리턴값이 없는 Function도 똑같습니다.
TestSub4 1 , 99 '이렇게 하거나 또는
Call TestSub4(1 , 999) '이렇게 합니다. *리턴값이 없는 Function도 똑같습니다.


Function을 사용한 예제를 보세요

Function TestFunction2(Astr)
  TestFunction2 = "TestFunction2성공 - "& Astr &"<br>"
End Function
AAA=TestFunction2("냠냠")
response.write(AAA)


Function TestFunction3(Astr)
  TestFunction3 = "TestFunction3성공 - "& Astr + 99 &"<br>"
End Function
AAA=TestFunction3(1)
response.write(AAA)

Function TestFunction4(Aint,Bint)
  TestFunction4 = "TestFunction4성공 - "& Aint + Bint &"<br>"
End Function
AAA=TestFunction4(1,99)
response.write(AAA)


Function TestFunction5(Astr,Bstr)
  TestFunction5 = "TestFunction5성공 - "& Astr + Bstr &"<br>"
End Function
AAA=TestFunction5("냠냠","나나")
response.write(AAA)




출처:http://www.hoho31.com/hohoman/133

----------------------------------------------------------

일반 텍스트 파일 읽기

Dim fso
set fso = server.createObject("Scripting.FileSystemObject")''    일반 텍스트 파일 읽는 함수

if fso.FileExists(filePath) then
    set textStream = fso.OpenTextFile(filePath, 1, false,0)
    Dim contents

 Do While Not textStream.AtEndOfStream
 txtLine = textStream.ReadLine
 Response.Write txtline & "dd<br>"  '화면에 보여줄때 줄넘김을 위해 <br> 태그 추가
 Loop
    textStream.Close
    set textStream = nothing
else
     Response.write  "Error"
end if
set fso = nothing

'ASP' 카테고리의 다른 글

asp xml 파싱  (0) 2012.07.09
asp에서 웹페이지 소스 가져오기, 파싱  (0) 2012.06.29
ASP 날짜 처리 함수  (0) 2012.05.10
ASP 종료 함수  (0) 2012.04.05
ASP 문자열 함수  (0) 2012.04.02
Posted by dewlit
|

ASP 날짜 처리 함수

ASP 2012. 5. 10. 13:51
Now()  ==> 2009-07-09 오후 4:48:49
Date()  ==> 2009-07-09
Time() ==> 오후 4:48:49
FormatDateTime(Now(), 0) ==> 2009-07-09 오후 4:48:49
FormatDateTime(Now(), 1) ==> 2009년 7월 9일 목요일
FormatDateTime(Now(), 2) ==> 2009-07-09
FormatDateTime(Now(), 3) ==> 오후 4:48:49
FormatDateTime(Now(), 4) ==> 16:48

 

'ASP' 카테고리의 다른 글

asp에서 웹페이지 소스 가져오기, 파싱  (0) 2012.06.29
ASP UTF-8 파일 읽기,쓰기 및 실행 예제  (0) 2012.05.11
ASP 종료 함수  (0) 2012.04.05
ASP 문자열 함수  (0) 2012.04.02
ASP 함수  (0) 2012.03.29
Posted by dewlit
|

할당받은 IP를 임의로 "210.129.123.138이라고 하겠습니다.
그리고 netmask를 "255.255.255.0"으로 하고
gateway를 "210.129.123.1" 마지막으로
DNS서버를 "168.126.63.1" 로 가정하고 설정해보겠습니다.

일단 /ect/network/interfaces 의 내용을 변경해주어야합니다.
처음엔 간단히


  

  <내용>
    auto lo
    iface lo inet loopback



이라고 적혀있을겁니다.
여기에 아래의 설정내용을 추가합니다.

    auto eth0
    iface eth0 inet static
        address 210.129.123.138
        netmask 255.255.255.0
        gateway 210.129.123.1
        # network 210.129.123.0
        # broadcast 210.129.123.255



다음과 같이 설정내용을 적어준뒤 저장하고 /etc 로 이동합니다.
여기에 resolv.conf 파일이 있어야 합니다. 기본으론 없기 때문에 만들어주어야 합니다.

        $sudo vim resolv.conf

        <내용>
        nameserver 168.126.63.1



과 같이 내용을 적고 저장합니다.
그리고 networking을 다시시작해야합니다.

    $sudo /etc/init.d/networking restart

다음과 같이 해주셨으면 아마도 거의 대부분의 경우 네트워크 설정이 정상적을 잡혔을 겁니다.
정상적으로 잡혔는지 확인을 하기 위해서 ping으로 확인해봅니다.

    $ping google.co.kr

패킷이 정상적으로 반응하면 성공입니다. ^^
만약 ping으로 확인했는데 패킷이 잡히지 않는다면 DNS의 문제인지 gateway의 문제인지 확인해봐야 합니다.

    $ping 168.126.63.1    [ 여기에서 정상이 아니면 DNS 설정이 잘못 ]
    $ping 210.129.123.1   [ 여기에서 정상이 아니면 gateway 설정이 잘못 ]

출처:http://towanouta.tistory.com/110

Posted by dewlit
|