Page

F.14.2- Sample File Specification 02 - Parsing Data

  by NT Community Manager.
Last Updated  by NT Community Manager.  

PublicCategorized as Appendix F.

Not tagged.
<< F.14.1- Sample File Specification 01 - Simple Specification AppendixFF.15.0- Two Frequently Asked Questions about Forms >>

Sample File Specification 02 – Parsing Data

This example uses the same form code as File01Form.htm, with the ACTION changed to the response page Form02Response.asp. However, this time we will parse the data to retrieve information such as the drive or extension of the file.

 

In a simple case of a file like a .doc we could just take the right 3 characters as the extension, but the code must handle cases where extensions are 1 or 2 characters. In addition, with current versions of Windows, periods can be used within a file name, which means we can't just search for periods – we must find a period which is in the last four characters.

 

The following code uses these variables:

 

varFileSpec

String

Whole string returned from form

varDrive

String

Characters to the left of the first colon

varExtArea

String

Area where the file extension would be located, if it exists:

Last four characters of the whole string

varLen

integer

Number of characters in the whole string, i.e. the varFileSpec.

varLocExtDot

Integer

Location of period in varExtArea, counting from the left

varRLocExtDot

Integer

Location of period in varExtArea, counting from the right

varExt

String

The file extension

 

...

<BODY>

<H3>File 02 Response</H3>

 

Full File Spec =

<%varFileSpec = Request.QueryString("FilePicked")

Response.Write varFileSpec%><BR><BR>

 

Drive = <%varDrive = left(varFileSpec,instr(varFileSpec,":"))

Response.Write varDrive%><BR><BR>

 

Extension =

<%

varExtArea = right(varFileSpec,4)

varLocExtDot = instr(varExtArea,".")

If varLocExtDot<>0 then

varLocExtDot = instr(varExtArea,".")

varRLocExtDot = len(varExtArea)-instr(varExtArea,".")+1

varExt = right(varExtArea,varRLocExtDot)

Response.Write varExt

Else

Response.write "There is no discernable extension"

End If%><BR><BR>

 

Path =

<%varLen = len(varFileSpec)

varLocColon = instr(varFileSpec,":")

For CharCount=1 To varLen

If mid(varFileSpec,CharCount,1)="\" Then

varLocLastSlash=CharCount

End If

Next

varDriveAndPath = left(varFiLeSpec,varLocLastSlash-1)

varPath = mid(varDriveAndPath,varLocColon+1)

Response.Write varPath

%></BODY>

...

 

The result will look something like this:

 

Appendixf_image035

 

<< F.14.1- Sample File Specification 01 - Simple SpecificationAppendixFF.15.0- Two Frequently Asked Questions about Forms >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |