Using math equation to create path to images dynam

# Thread: Using math equation to create path to images dynam

1. Junior Member
Join Date
Dec 1969
Posts
11

## Using math equation to create path to images dynam

I have a database application that stores only the parent directory and the file name (minus the file extension) in db tables. In order to know the full path to a file, the application runs a calculation based on the following formula:<BR><BR>Object Id is the column name containing the image file name stored as a number in a table.<BR><BR>Directory: Object ID / 1024 / 1024<BR><BR>Sub-directory: (Object ID / 1024) mod 1024<BR><BR>File name formula:<BR><BR>If the object id is less than 100,000,000, then the file name is the object id (1 - 99,999,999)<BR><BR>If the object id is between 100,000,000 and 2,147,483,647 (this is the upper limit), then the file name is in hex, and it goes from A0000000 through HFFFFFFF.<BR><BR>I have no idea how to code a formula like this into code that will run in an ASP script to produce the full path resembling and displaying it as hyperlink:<BR><BR>\servershareparentdir1024.bin< BR><BR>Any help is greatly appreciated.<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Numbers make no sense

Hex A0000000 is -1,610,612,736<BR><BR>Why would you use hex for number greater than 100,000,000 and then skip 1.7 billion numbers?<BR><BR>And, in any case, you say "If the object id is between 100,000,000 and 2,147,483,647" but then you have the hex numbers start with a number far outside that range.<BR><BR>Are you saying there are never more than two levels of directory, plus then the files?<BR><BR>How many files in the last level of directory?<BR><BR>And why the hokey idea of having some names be decimal and others be hex, to begin with?<BR><BR>And what is HFFFFFFF supposed to be??? 7FFFFFFF is the same as 2,147,483,647. Is that what you were after?<BR><BR>

3. Junior Member
Join Date
Dec 1969
Posts
11

## RE: Numbers make no sense

Let me preface this by saying this is a purchased application so I can&#039;t necessarily explain all the logic.<BR>I have investigated and hopefully can clarify some things.<BR><BR>"And what is HFFFFFFF supposed to be??? 7FFFFFFF is the same as 2,147,483,647. Is that what you were after?"<BR>Yes, it appears that mathematically it should be 7FFFFFFF. However as you will see below, I tested the system and it did in fact generate a file named HFFFFFFF when I forced the counter to 2,147,483,647.<BR> <BR>"Are you saying there are never more than two levels of directory, plus then the files?"<BR>Yes, each image file is never deeper than 2 levels. The structure is:<BR>1024 files in each sub-dir, 1024 sub-dirs in a parent dir, then a new dir is created. This continues until it creates dir number 2047 with sub-dir number 1023 and the last file it created is HFFFFFFF.<BR>I advanced the counter value (it stores it in a table) to 2,147,483,646 and then imported a file to force the counter to the last value of 2,147,483,647 and it created a file named HFFFFFFF.bin. So I have no idea how it converts hex.<BR><BR>"And why the hokey idea of having some names be decimal and others be hex, to begin with?"<BR>This is a carryover from their DOS 8.3 days. They don&#039;t want to store a file with more than 8 characters and hex allows them to go higher than 99,999,999 files.<BR><BR>"Hex A0000000 is -1,610,612,736"<BR>I forced it to start at 99,999,999 and the file name that got created is 99999999.bin and then the next one for object id 100,000,000 is A5F5E100.bin. So again, I don&#039;t understand why their documentation states that last file would be A0000000.<BR><BR>Hopefully this makes a little more sense now. Do you think you can help me? I&#039;d like to hear your theories too if you have any on how they convert that top number to a hex value that does not match what a calculator will produce.<BR>

4. Junior Member
Join Date
Dec 1969
Posts
11

## One more thing

I just checked the hex value of 100,000,000 and it is 5F5E100, however the application creates a file named A5F5E100. I don&#039;t understand why there is an A in the file. Again, it appears there is some freaky hex conversion going on. Do you have any ideas what they are doing to produce such values?<BR><BR>I will try calling their support dept. tomorrow and see if they will tell me what is going on.

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Boy oh boy, how hokey!

Pure idiocy!<BR><BR>Why didn&#039;t they just *ALWAYS* use the HEX form???<BR><BR>Okay...I guess I see what to do. Sigh.<BR><BR>&#060;%<BR>funny = ... one of those funny numbers *AS A STRING* ...<BR><BR>bias = InStr( "ABCDEFGH", Left(funny,1), vbTextCompare )<BR><BR>If bias &#062; 0 Then<BR> &#039; the funny started with a letter...<BR> &#039; but the letter is HEX A too big...so adjust it:<BR> &#039; "A" becomes "0", "B" becomes "1", etc.<BR> &#039; (since bias will be 1 to 8, bias-1 will be 0 to 7...ta da)<BR> hexnum = "&H" & (bias-1) & Mid(funny,2)<BR> &#039; this should now be a proper hex number, in string form<BR> pathnum = CLng( hexnum ) &#039; so convert it to a numeric value<BR><BR>Else<BR> &#039; if we get here, we had a decimal number instead of <BR> &#039; a funny hex number... so just get its value:<BR> pathnum = CLng( funny )<BR>End If<BR><BR>&#039; so now, no matter what, we have the number as a simple 32 bit integer<BR>&#039; sanity check:<BR>Response.Write "DEBUG: pathnum is " & pathnum _<BR> & ", Hex " & Right("00000000"&Hex(pathnum),8) & "&#060;HR&#062;"<BR><BR>&#039; the lowest 10 bits of that number give us the file number:<BR>filenum = pathnum AND &H000003FF<BR><BR>&#039; the next 10 bits give us the subdir number:<BR>subdirnum = (pathnum AND &H000FFC00) / &H00000400<BR><BR>&#039; and the next 11 bits (max) give use the dir number:<BR>dirnum = (pathnum AND &H7FF00000) / &H00100000<BR><BR>&#039; then we convert all that back into a path, I guess:<BR>path = "C:whatever\" & dirnum & "\" & subdirnum & "\" & filenum & ".bin"<BR><BR>....<BR>%&#062;<BR><BR>See how that works out.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•