DTP


 
Lively discussions on the graphic arts and publishing — in print or on the web


Go Back   Desktop Publishing Forum > General Discussions > Web Site Building & Maintenance

Reply
 
Thread Tools Display Modes
Old 06-21-2011, 03:42 AM   #1
LoisWakeman
Staff
 
LoisWakeman's Avatar
 
Join Date: Jan 2005
Location: Uplyme, Devon, England
Posts: 1,402
Default Classic ASP VBScript code help please!

I am using this script to make breadcrumbs from the directory structure of an ASP site.
Code:
Function BreadCrumb(FullPath)
 
Do Until instr(1,FullPath,"/") = 0
 
    '## Create an array of letters in the alphabet.
    Letters = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
 
    '## split on the /
    tmpPath = mid(FullPath,1,instr(1,FullPath,"/")-1)
    strTmpPath = Trim(tmpPath)
    DirPath = DirPath & strTmpPath & "/"
 
    '## upshift the first character
    firstLetter = ucase(mid(strTmpPath,1,1))
    strTmpPath = firstLetter & mid(strTmpPath,2,len(strTmpPath))
 
    '## replace underscores with spaces and upshift the following character
    for each letter in letters
        strTmpPath = Replace(Trim(strTmpPath),"_" & lcase(letter)," " & UCase(letter))
    next
 
    '## split the next one out    <----------------------
    FullPath = mid(FullPath,instr(1,FullPath,"/")+1,Len(FullPath)-Len(tmpPath))
 
    '## separate them with >> symbols
    IF strTmpPath = "" THEN
        response.write "<a href=""/"" style=""text-decoration:none"">Home Page</a>"
    ELSEIF strTmpPath = "Home" THEN
    ELSE
        response.write " &gt; <a href=""" & DirPath & """ style=""text-decoration:none"">" & strTmpPath & "</a>"
    END IF
Loop
 
IF PageTitle = "" THEN
    response.write " : Current Page"
ELSE
    response.write " : " & PageTitle
END IF
 
End Function %>
It replaces the first underscore with a space, and capitalises all words but doesn't replace a second underscore, for example in "facts-and-figures", one gets "Facts And_Figures".

I think the error is just after the comment marked with <--------, but my brain is mush today and I can't see why. All assistance gratefully received.
LoisWakeman is offline   Reply With Quote
Old 06-21-2011, 06:05 AM   #2
Steve Rindsberg
Staff
 
Join Date: Nov 2004
Posts: 7,047
Default

I have to run out the door in a few seconds but quickly:

At some point, do this:

FullPath = Replace (FullPath, " ", "_")

But not in the context of the For Each Letter In Letters loop.
Replace will fix the whole string in one go.

   
__________________
Steve Rindsberg
====================
www.pptfaq.com
www.pptools.com
and stuff
Steve Rindsberg is offline   Reply With Quote
Old 06-21-2011, 01:45 PM   #3
Steve Rindsberg
Staff
 
Join Date: Nov 2004
Posts: 7,047
Default

You might also have a go with an approach like this; I don't have a simple way to test asp scripts so am not sure whether this does all your script is supposed to do but on the face of it, it's perhaps simpler to understand.

Try running it in Word VBA for starters ... easier to step through and test that way.

Sub TestThis()
TryThis "//server/asome/path/or/zother/test-and-a-half.html"
End Sub
Function TryThis(FullPath)

Dim pathbits
Dim workingpath
Dim tmpStr
Dim outStr
Dim x
Dim y

' Strip off any leading characters up to and including //
workingpath = Mid(FullPath, InStr(pathbits, "//") + 3)

' Break the remaining path up into components, split at the /
pathbits = Split(workingpath, "/")

' then tweak each of the components
For x = LBound(pathbits) To UBound(pathbits)
outStr = ""
' replace dashes with underscores
tmpStr = Replace(pathbits(x), "-", "_")
' you could do other replacements here if you wish;
' eliminate spaces, for example

' lowercase the string to start with
tmpStr = LCase(tmpStr)

' asc("a") is 97, asc("z") is 122
' this caps the first letter of any component whose first letter is in that range
For y = 1 To Len(tmpStr)

If 96 < Asc(Mid(tmpStr, y, 1)) < 123 Then
outStr = outStr & UCase(Mid(tmpStr, y, 1))
outStr = outStr & Mid(tmpStr, y + 1)
Exit For
Else
outStr = outStr & Mid(tmpStr, y, 1)
End If
Next

Debug.Print outStr
Next

End Function

   
__________________
Steve Rindsberg
====================
www.pptfaq.com
www.pptools.com
and stuff
Steve Rindsberg is offline   Reply With Quote
Old 06-22-2011, 07:36 AM   #4
LoisWakeman
Staff
 
LoisWakeman's Avatar
 
Join Date: Jan 2005
Location: Uplyme, Devon, England
Posts: 1,402
Default

Thanks Steve - will try it out and let you know - several projects on the go now, so it may be a day or two.

(I thought you were running out the door at the thought of debugging VBscript when I first glanced at your reply )
LoisWakeman is offline   Reply With Quote
Old 06-22-2011, 08:48 PM   #5
Steve Rindsberg
Staff
 
Join Date: Nov 2004
Posts: 7,047
Default

Quote:
Originally Posted by LoisWakeman View Post
Thanks Steve - will try it out and let you know - several projects on the go now, so it may be a day or two.

(I thought you were running out the door at the thought of debugging VBscript when I first glanced at your reply )
The thought HAD crossed my mind. But no ... really. Had somewhere I had to be. No, seriously. I really did. Really.

   
__________________
Steve Rindsberg
====================
www.pptfaq.com
www.pptools.com
and stuff
Steve Rindsberg is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compuserve Classic ISP going bye-bye... terrie The Corner Pub 88 05-22-2009 04:14 PM
Hex code for silver dacoyle Print Design 8 10-27-2006 09:38 PM
Who owns the code? Linda Baldwin General Publishing Topics 15 03-31-2006 05:06 PM
Valid code, or perhaps not... Bo Aakerstrom Web Site Building & Maintenance 5 03-01-2006 12:43 PM


All times are GMT -8. The time now is 09:34 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Contents copyright 2004–2019 Desktop Publishing Forum and its members.