Advertisement
2002VB String Manipulation #18550

Convert long address to IP address

Converts a long address (2220112843) to it's IP address (203.59.84.132)

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Function IPToString(Value As Double) As String
  Dim l As MyLong
  Dim i As MyIP
  l.Value = DoubleToLong(Value)
  LSet i = l
  IPToString = i.A & "." & i.B & "." & i.C & "." & i.D
End Function
Function DoubleToLong(Value As Double) As Long
  If Value <= 2147483647 Then
    DoubleToLong = Value
  Else
    DoubleToLong = -(4294967296# - Value)
  End If
End Function

In many large scale or user-based ASP projects, a large number of files need to be made available for download. It is inconvienient for users to have to download files one at a time as this would take a lot of their time and care to do so. A solution? Zip the files. Normally this needs to be done manually - but what if it is not possible to do this? What if the server is going to be unaccessable, or what if the number of files is going to greatly increase every day? Ladies and Gentlemen, I bring you the ZipFunctions component.
<p>
<b>What is it?</b><br>
It is an open-source component written in Java. It is completely free, and grants the magic ability to gzip a single file, or zip one or more files. It has been tested thoroughly under PWS and IIS 4.0.
<p>
<b>Installing the component</b><br>
First download the component (see bottom of this article) and then copy the ZipFunctions.class file into the windows\java\trustlib directory. If you are a Java developer, then you may want to edit the source code. When it comes to compiling, simply compile as normal (optimise with the -O flag if you are using Sun's JDK) and then copy the file into windows\java\trustlib
<p>
<b>Using the component</b><br>
A testing function is integrated into the component. This allows you to check to see if the component installed correctly. To use it the code is as follows:
<p>
<pre>
&lt;%
 Dim strResult
 set javaObject = GetObject("java:ZipFunctions")
 strResult = javaObject.test()
 response.write strResult
 set javaObject = nothing
%&gt;
</pre>
<p>
if the component was installed correctly, then you should see the text: test ok! as an output.
<p>
<b>GZipping a file</b><br>
To GZip a file, simply use the code below
<pre>
&lt;%
 Dim strResult
 set javaObject = GetObject("java:ZipFunctions")
 strResult = javaObject.GZipFile(Server.mappath("/asp/zipme.txt"), Server.mappath("/asp/zipme.txt.gz"))
 response.write strResult
 set javaObject = nothing
%&gt;
</pre>
<p>
This will compress the file zipme.txt into the file zipme.txt.gz. No files get deleted in the process, although if there is already a zipme.txt.gz it will be overwritten. Only one file can be GZipped at a time. If an error occurs, it will be stated in strResult. If everything goes to plan, then strResult will read 'Created filename' where filename is the file which was written to.
<p>
<b>Zipping files</b><br>
Zipping multiple files requires a slightly different procedure. The files are all passed as a string, with each filename being seperated by an asterisk (*). If only one file is passed, no asterisk is needed, so the string could be something like: file1.gif. If two files are passed then one asterisk is needed and the string would look something like this: file1.gif*file2.htm. Adding another file, another asterisk is needed and the string would become file1.gif*file2.htm*file3.zip.
<p>
To create the zip file, the following code is used:
<pre>
&lt;%
 Dim strResult, theFiles
 theFiles = Server.mappath("/asp/somefile.txt") & "*" & Server.mappath("/asp/anotherfile.zip")
 set javaObject = GetObject("java:ZipFunctions")
 strResult = javaObject.ZipFile(theFiles, Server.mappath("/asp/zipfile.zip"))
 response.write strResult
 set javaObject = nothing
%&gt;
</pre>
This compresses the file somefile.txt and anotherfile.zip into the file zipfile.zip. Once again, if zipfile.zip already exists, it will be overwritten. Any errors will be reported in strResult. Again, if no errors occur, then strResult will read 'Created filename' where filename is the zip file which was written.
<p>
<b>Potential Uses</b><br>
There are a large number of uses for this component, but beware - zipping takes up a lot of processing, and the more large files you compress, the longer it will take. Constant zipping could cause problems to your server if it is not very powerful.<br>
It would be fairly simple to zip a whole directory, certain files, databases, etc. The type of site that ZipFunctions will be used on is the only thing that can determine the potential uses of the component.<br>
Original Comments (3)
Recovered from Wayback Machine