dcsimg

Simple ASP Application Page 2

By ServerWatch Staff (Send Email)
Posted Oct 27, 1998


Here's the code for Enhanced.ASP

The function neg_to_red takes a string and returns a string with <font color = "red"> around all the negative numbers. This function assumes the maximum length of a line on the report is 132 and negative sign is trailing on negative numbers ex 12.23- Feel free to use the function if you ever find a need for it.

<%

function neg_to_red(line)

pos = 2

last_end = 0

Do While pos < 133

chr1 = Mid(Line, pos, 1)

chr2 = Mid(Line, (pos - 1), 1)

chr3 = Mid(Line, (pos + 1), 1)

If ((chr1 = "-") And (chr3 = " ") And (IsNumeric(chr2))) then

        pnt = pos - 1

       finished = 0

       Do While finished = 0

              If ptr < last_end Then

                 finished = 1

             Else

            If Mid(Line, pnt, 1) = " " Then

                  hold_line = "<font color = " & Chr(34) & "red" & Chr(34) & ">"

                 build_line = build_line & Mid(Line, last_end + 1, (pnt - last_end))

                 build_line = build_line & hold_line

                 build_line = build_line & Mid(Line, pnt + 1, (pos - (pnt)))

                 build_line = build_line & "</font>"

                 last_end = pos

                 finished = 1

            Else

                    pnt = pnt - 1

                   If pnt = 1 Then

                        hold_line = "<font color = " & Chr(34) & "red" & ">"

                        build_line = build_line & Mid(Line, last_end + 1, (pnt - last_end + 1))

                        build_line = build_line & hold_line

                        build_line = build_line & Mid(Line, pnt + 1, (pos - (pnt)))

                         build_line = build_line & "</font>"

                        last_end = pos

                        finished = 1

                    End If

              End If

           End If

         Loop

         End If

    pos = pos + 1

Loop

build_line = build_line & Mid(Line, (last_end + 1), pos - (last_end + 1))

neg_to_red = build_line

end function

%>

Here is the code that reads and displays the text file

<%

RESPONSE.WRITE "<BODY BACKGROUND = " & CHR(34) & "GREENBAR.BMP" & CHR(34) & ">"

'CHR(34) is a double quote the line ends up being   written as <BODY BACKGROUND = "GREENBAR.BMP">

FTP_VIRTUAL_PATH = "/REPORTS"

FTP_PATH = SERVER.MAPPATH(FTP_VIRTUAL_PATH) ' Get the physical path to the reports directory

SET O_FSO = CREATEOBJECT("SCRIPTING.FILESYSTEMOBJECT")

IN_FILE = REQUEST ("E_FILE")         'Get the file name posted to the page

FILE_NAME = FTP_PATH & IN_FILE

SET INSTREAM = FILEOBJECT.OPENTEXTFILE ( FILE_NAME, 1, FALSE, FALSE)  'Open the text file for input

RESPONSE.WRITE "<PRE>"               'Use the HTML tag <Pre>meaning the following code is preformatted(keeps the spacing)

WHILE NOT INSTREAM.ATENDOFSTREAM     'Proccess until end of file reached

   IN_LINE = INSTREAM.READLINE

   IF INSTR (IN_LINE, "-") THEN             ' If there is a negative sign in the line call the function neg_to_red

         RESPONSE.WRITE     NEG_TO_RED(IN_LINE) & "<BR>"  

   ELSE                                                          ' Else we just write back the line

         RESPONSE.WRITE      IN_LINE & "<BR>"

  END IF

WEND

%>

Page 2 of 2


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.


 

 


Thanks for your registration, follow us on our social networks to keep up-to-date