• (cs)

    If only there was a command for that...

    O wait is it not the '?'

  • (cs)
    link = "bar"
    Seriously? I'll never understand some people. link = "bar"
  • (cs)

    Also, this could cause great fun if the request URL is something like /dir/dir/../dir2/../../file. Better hope the server you're running on is smart enough to refuse access below the root level...

  • Chris (unregistered) in reply to bstorer
    bstorer:
    Also, this could cause great fun if the request URL is something like /dir/dir/../dir2/../../file. Better hope the server you're running on is smart enough to refuse access below the root level...

    Or /dir///dir/

  • (cs) in reply to Chris
    Chris:
    bstorer:
    Also, this could cause great fun if the request URL is something like /dir/dir/../dir2/../../file. Better hope the server you're running on is smart enough to refuse access below the root level...

    Or /dir///dir/

    Actually, I'm not up on ASP. Does Request.ServerVariables ("URL") return the URL requested, or does it return the server translated URL? In other words, does a request for /dir/../file return "/dir/../file" or simply "/file"?

  • GregM (unregistered) in reply to bstorer
    bstorer:
    link = "bar"
    Seriously? I'll never understand some people. link = "bar"

    That would work, were it not for it trying to keep the first two portions of the path when in development mode:

    /dev/dir/foo/bar.asp instead of /foo/bar.asp

  • Anonymous (unregistered)

    Okay, we get it. VB programmers always write basic string functions from scratch using Mid(), and they always get it wrong.

    I swear, if i see For...Mid...InStr one more time...

  • (cs) in reply to Anonymous

    'finds the root level. good for use on pages than may 'span multiple directories, such as 404 and 500 error 'pages.

    Because configuring your web server to serve these out of a standard directory is something only other people do.

    Seriously. I know I'm weird in that I do servers AND code, but if you do web design you should sort of understand how web servers work, so as not to create abortions like this.

  • (cs) in reply to GregM
    GregM:
    bstorer:
    link = "bar"
    Seriously? I'll never understand some people. link = "bar"

    That would work, were it not for it trying to keep the first two portions of the path when in development mode:

    /dev/dir/foo/bar.asp instead of /foo/bar.asp

    Which is why a development server should simply be given a different root directory.
  • Freddy Bob (unregistered)
    for iLoop = 1 to iCount RootLevel = RootLevel & "../" next
    Forgive my ignorance here (or bless it) but is that recursing? Inside a loop?
  • (cs) in reply to bstorer
    bstorer:
    GregM:
    bstorer:
    link = "bar"
    Seriously? I'll never understand some people. link = "bar"

    That would work, were it not for it trying to keep the first two portions of the path when in development mode:

    /dev/dir/foo/bar.asp instead of /foo/bar.asp

    Which is why a development server should simply be given a different root directory.
    too simple. this was an "Enterprise Application" - simple is paradoxical to enterprise. Duh!
  • (cs)

    this is why I like ASP.NET...

    link = "bar";

    works sooo much better!
  • SomeCoder (unregistered) in reply to Freddy Bob
    Freddy Bob:
    for iLoop = 1 to iCount RootLevel = RootLevel & "../" next
    Forgive my ignorance here (or bless it) but is that recursing? Inside a loop?

    No, that's how you handle return values for functions in VB. The automatic return value is a variable with the same name as your function. It's one of VB's syntax oddities.

    I really hate VB.

  • (cs) in reply to Freddy Bob

    No, in VB you set the return value by assigning to the name of the function.

  • Shinobu (unregistered) in reply to Freddy Bob
    Freddy Bob:
    for iLoop = 1 to iCount RootLevel = RootLevel & "../" next
    Forgive my ignorance here (or bless it) but is that recursing? Inside a loop?
    Which is why I call bollocks on this one. If the URL contains a "/" then iCount will be greater than zero. Which means RootLevel will be called from within the above loop. Considering URL has not changed, this means... infinite recursion! Yay!
  • Shinobu (unregistered) in reply to Shinobu
    Shinobu:
    Which is why I call bollocks on this one. If the URL contains a "/" then iCount will be greater than zero. Which means RootLevel will be called from within the above loop. Considering URL has not changed, this means... infinite recursion! Yay!
    Bleep... see the comments above. Please forgive my ignorance too. Even though I knew that assigning to the function name sets the return value, I didn't know that you could also read it. Although that is a bit odd, considering the very same syntax outside that function denotes a call.
  • Russ (unregistered) in reply to Satanicpuppy
    Satanicpuppy:
    'finds the root level. good for use on pages than may 'span multiple directories, such as 404 and 500 error 'pages.

    Because configuring your web server to serve these out of a standard directory is something only other people do.

    Seriously. I know I'm weird in that I do servers AND code, but if you do web design you should sort of understand how web servers work, so as not to create abortions like this.

    Well it said that this application is in VB6, which means ASP, which most likely means IIS. If they were using XP or something, IIS only allows for a single site, so it might not be possible to set things up with virtual sites for every production site. Which is exactly the reason I use Apache even on windows.

  • (cs) in reply to Shinobu
    RootLevel = RootLevel & "../"

    In VB, you set the return value of a function by its name from within the function. In order to get recursion, it would have to look like "RootLevel = RootLevel(xyz)"... I wish I didn't know that.

  • (cs) in reply to Russ
    Russ:
    Satanicpuppy:
    'finds the root level. good for use on pages than may 'span multiple directories, such as 404 and 500 error 'pages.

    Because configuring your web server to serve these out of a standard directory is something only other people do.

    Seriously. I know I'm weird in that I do servers AND code, but if you do web design you should sort of understand how web servers work, so as not to create abortions like this.

    Well it said that this application is in VB6, which means ASP, which most likely means IIS. If they were using XP or something, IIS only allows for a single site, so it might not be possible to set things up with virtual sites for every production site. Which is exactly the reason I use Apache even on windows.

    even if you can only set up a single site IIS, you should be coding in such a fashion that you can deploy to a virtual directory inside of IIS just as easily.

    That being said, XP is still not a good choice for production.

  • Tarwn (unregistered) in reply to bstorer
    bstorer:
    Chris:
    bstorer:
    Also, this could cause great fun if the request URL is something like /dir/dir/../dir2/../../file. Better hope the server you're running on is smart enough to refuse access below the root level...

    Or /dir///dir/

    Actually, I'm not up on ASP. Does Request.ServerVariables ("URL") return the URL requested, or does it return the server translated URL? In other words, does a request for /dir/../file return "/dir/../file" or simply "/file"?

    Actually it's worse than that. Request.ServerVariables("URL") returns the base URL. Basically everything except the domain portion and the querystring. I believe Request.ServerVariables("HTTP_HOST") would be what you were looking for.

    Although I have to admit I am enjoying the ignorance of the people bashing VB. Not that I don't agree, VB is crap, but personally I think I would want to make sure my assumptions were correct before announcing them to the world. The [incorrect] assumption being that ASP uses VB. Thats like saying Linux and BSD are the same thing (/duck).

  • bahbar (unregistered)

    Continuing on the vb oddities... What is the inital value of the return value, before initialized ? Because the first

    RootLevel = RootLevel & "../" 

    uses an uninited RootLevel

  • MaW (unregistered) in reply to bahbar

    I'd guess at the empty string, since it's clearly a string variable, but that might be too sensible for VB.

  • (cs) in reply to bstorer
    bstorer:
    GregM:
    bstorer:
    link = "bar"
    Seriously? I'll never understand some people. link = "bar"

    That would work, were it not for it trying to keep the first two portions of the path when in development mode:

    /dev/dir/foo/bar.asp instead of /foo/bar.asp

    Which is why a development server should simply be given a different root directory.

    I want to see the database code! (pseudo code, because I don't know what crazy moon language this is)

     query = 'SELECT * FROM account'
     CASE devel
      query .= '_dev'
     CASE test
      query .= '_test'
     query .= ' WHERE username = ' . username . ';'
    
  • MaW (unregistered) in reply to MaW

    Replying to myself, of course there's no way VB can know for sure that it's a string variable, so who knows? It could take a good guess based on that it's being used on the left of a string concatenation there in its first appearance, but...

    I like my languages with lots of type information in the syntax. The very thought of a function which doesn't have an explicit return type is quite awful, which doesn't help me out when I'm writing Perl.

  • (cs) in reply to bahbar
    bahbar:
    Continuing on the vb oddities... What is the inital value of the return value, before initialized ? Because the first
    RootLevel = RootLevel & "../" 
    uses an uninited RootLevel

    VBScript auto-initializes variables to an empty variant. This stringizes to "".

  • (cs) in reply to MaW
    MaW:
    I like my languages with lots of type information in the syntax. The very thought of a function which doesn't have an explicit return type is quite awful, which doesn't help me out when I'm writing Perl.

    Hooray for the Variant type!

    As a young programmer, for about 2 weeks, I thought that was a pretty cool feature of VB6. Never touched Variants again.

    Maybe someone who's used VB more could tell of a good reason to use it. (JeffS?)

  • (cs) in reply to Freddy Bob
    Freddy Bob:
    for iLoop = 1 to iCount RootLevel = RootLevel & "../" next
    Forgive my ignorance here (or bless it) but is that recursing? Inside a loop?

    Nope. In VB(A/6), that's how you assign a return value to a function. Used to be that way in Pascal, too.

  • (cs) in reply to Jojosh_the_Pi
    Jojosh_the_Pi:
    MaW:
    I like my languages with lots of type information in the syntax. The very thought of a function which doesn't have an explicit return type is quite awful, which doesn't help me out when I'm writing Perl.

    Hooray for the Variant type!

    As a young programmer, for about 2 weeks, I thought that was a pretty cool feature of VB6. Never touched Variants again.

    Maybe someone who's used VB more could tell of a good reason to use it. (JeffS?)

    You called? First off, note that this is VBScript. It is a SCRIPTING language, like javascript, and like javascript, EVERYTHING is a variant.

    As for VB6, nothing forces you to use variants. that's up to you. Once again, try to take responsibility for your own code and don't blame the tools. Let's not get into the usual ignorant flame wars. Fighting ignorance is fun sometimes, but it gets old after a while.

  • Freddy Bob (unregistered) in reply to KenW
    KenW:
    Freddy Bob:
    for iLoop = 1 to iCount RootLevel = RootLevel & "../" next
    Forgive my ignorance here (or bless it) but is that recursing? Inside a loop?

    Nope. In VB(A/6), that's how you assign a return value to a function. Used to be that way in Pascal, too.

    Yes and no on the Pascal, hence my question. FunctionName := 'Some string'; sets the return value but FunctionName := FunctionName + 'some string'; or SomeVariable := FunctionName + 'some string'; from within FunctionName would cause a recurse (and a curse again).

    To get the same effect without the recursion would need. SomeVar := 'A'; SomeVar := SomeVar + 'B'; SomeVar := SomeVar + 'C'; FunctionName := SomeVar;

    Delphi (Object Pascal) made this a little clearer by introducing an implicit Result variable. Assigning to that set the return value and reading from it got the 'current' value for the function without causing recursion.

  • (cs)

    Looks like someone's taken the term "path" a little too literally. --RA

  • null reference (unregistered) in reply to Rank Amateur

    I'm not sure if this exists in classic ASP, but in ASP.Net there's the handy Request.ApplicationPath property, that is the application root =)

  • (cs)

    I wonder what goes through the mind of someone when they choose to use iCount as a variable name instead of slashCount or numSlashes. (Not that using good variable names would redeem this code.)

  • (cs) in reply to Jeff S
    Jeff S:
    Jojosh_the_Pi:
    MaW:
    I like my languages with lots of type information in the syntax. The very thought of a function which doesn't have an explicit return type is quite awful, which doesn't help me out when I'm writing Perl.

    Hooray for the Variant type!

    As a young programmer, for about 2 weeks, I thought that was a pretty cool feature of VB6. Never touched Variants again.

    Maybe someone who's used VB more could tell of a good reason to use it. (JeffS?)

    You called? First off, note that this is VBScript. It is a SCRIPTING language, like javascript, and like javascript, EVERYTHING is a variant.

    As for VB6, nothing forces you to use variants. that's up to you. Once again, try to take responsibility for your own code and don't blame the tools. Let's not get into the usual ignorant flame wars. Fighting ignorance is fun sometimes, but it gets old after a while.

    So there's really no good reason to use it in VB6? I'm genuinely curious to hear if there is one.

  • m03 (unregistered) in reply to VGR
    VGR:
    I wonder what goes through the mind of someone when they choose to use iCount as a variable name instead of slashCount or numSlashes. (Not that using good variable names would redeem this code.)

    Based on the other variable names, I'd say they used it to denote that this is an integer.

  • (cs) in reply to zip

    A variant in VB6/VBA is kind of like Object in C#/Java/VB.NET. It is used when different types of data need to be returned. Thus, you will notice that an ADO Field object's value property returns a Variant, which can then be "cast" to the correct datatype, since the fields in the recordset can of course be different types. So, it is much like object in that regard.

    So, just like object, it exists for a purpose, but it can be abused. You could just declare all of your variables as "variant" (or use Option Explicit Off which has the same effect, only even worse!) and that certainly would be a bad idea, but it is not something that VB "forces" you to do.

    In all truthfulness, VB<=6 is not a great language; it has many, many flaws, almost all because it is dervied from BASIC after all ! But that language was last updated in about 1999. The current VB, VB.NET is a HUGE improvement over VB6 and addresses almost all of its shortcomings, and uses the "Object" datatype instead of variants exactly the same as C# and Java and others.

  • (cs) in reply to VGR
    VGR:
    I wonder what goes through the mind of someone when they choose to use iCount as a variable name instead of slashCount or numSlashes. (Not that using good variable names would redeem this code.)

    In scripting languages where you cannot declare a variable's type explicitly, it is often useful to prefix the "hidden" type in the variable name somehow. One of the few cases in which I think hungarian notation is acceptable and even helpful, IMHO.

  • Bill (unregistered) in reply to zip
    zip:
    Jeff S:
    Jojosh_the_Pi:
    MaW:
    I like my languages with lots of type information in the syntax. The very thought of a function which doesn't have an explicit return type is quite awful, which doesn't help me out when I'm writing Perl.

    Hooray for the Variant type!

    As a young programmer, for about 2 weeks, I thought that was a pretty cool feature of VB6. Never touched Variants again.

    Maybe someone who's used VB more could tell of a good reason to use it. (JeffS?)

    You called? First off, note that this is VBScript. It is a SCRIPTING language, like javascript, and like javascript, EVERYTHING is a variant.

    As for VB6, nothing forces you to use variants. that's up to you. Once again, try to take responsibility for your own code and don't blame the tools. Let's not get into the usual ignorant flame wars. Fighting ignorance is fun sometimes, but it gets old after a while.

    So there's really no good reason to use it in VB6? I'm genuinely curious to hear if there is one.

    It's just a lazy way for a function not need overrides. If all you were going to do with a variable was store it in a string, variant (now object) allows them to pass anything and the programmer could ToString it and store it.

    Captcha: Darwin - he did away with variants

  • Shaun (unregistered) in reply to Jojosh_the_Pi
    Jojosh_the_Pi:
    MaW:
    I like my languages with lots of type information in the syntax. The very thought of a function which doesn't have an explicit return type is quite awful, which doesn't help me out when I'm writing Perl.

    Hooray for the Variant type!

    As a young programmer, for about 2 weeks, I thought that was a pretty cool feature of VB6. Never touched Variants again.

    Maybe someone who's used VB more could tell of a good reason to use it. (JeffS?)

    There is NEVER a good reason to use variants. Okay, so everything in Classic ASP is a variant, but that is why I will never touch it again (unless there is major $ involved.)

  • HealthManiac (unregistered) in reply to Shinobu

    All - This story has anonymization baked right into it.

    The scripts in question were originally developed in Perl/CGI which made system calls out to some horrible Java 1.1 code.

    Now that's enterprisey!

  • (cs) in reply to Shaun
    Shaun:
    Jojosh_the_Pi:
    MaW:
    I like my languages with lots of type information in the syntax. The very thought of a function which doesn't have an explicit return type is quite awful, which doesn't help me out when I'm writing Perl.

    Hooray for the Variant type!

    As a young programmer, for about 2 weeks, I thought that was a pretty cool feature of VB6. Never touched Variants again.

    Maybe someone who's used VB more could tell of a good reason to use it. (JeffS?)

    There is NEVER a good reason to use variants. Okay, so everything in Classic ASP is a variant, but that is why I will never touch it again (unless there is major $ involved.)

    You must completely avoid all scripting languages then, right?

    It might help you to read my previous post. There's lots of good reasons to use and/or return variants in your code, just as there are to use Objects in other languages. And like anything, there are ways to use them properly and ways to abuse them.

  • Bert (unregistered)

    A few observations:

    1. IIS supports multiple IPs, multiple web sites, multiple "apps" per website, multiple virtual directories per website, etc. It gives you the ability to configure these however you need.

    2. If a developer is not given the privileges to exploit these features, then you wind up with scenarios like this WTF. Here is a sample email to elucidate.

    From: IIS Admin To: Jane Developer Subj: IIS request

    Jane, I setup your area on the dev server as requested; you can access it as follows:

    file system: \devserver\jane browser: http://devserver/dev/jane

    Remember production looks like this: browser: http://prodserver

    Good luck! IIS Admin P.S. Hopefully, we will have a QA server soon that looks like http://qaserver where you will be able to test your changes before they go production.

    1. The IIS admin (and or development policy) should really be forcing the developers to code to the site level.

    2. I think a prevous poster made an allusion to the fact that you could use a "Global" variable at an IIS "app" level to try to solve this, but I hate globals. A better approach would be a DNS entry, and an IIS host header entry. file system: \devserver\jane browser: http://devjane

    3. I really peeved our IIS admin when I showed her how easy it was to use the host header to support thousands of web sites on one IIS server. (She was physically shaking) Yeah for HTTP 1.1! After 5 years they finally let me tweak the DEV server, but a network admin is needed tweak the DNS. (Many times I will skip the DNS and just use the local system32/drivers/etc/hosts)

  • Borat (unregistered) in reply to Freddy Bob

    No, it's not recursing.

  • to be a sr dev is to stop learning (unregistered)

    As a jr. developer, it's easy to catch yourself listening to the wrong people. People who know nothing about what they are talking about! People who don't read all the comments of a post! As Jeff S. stated earlier, in classic ASP, you use VBScript. VBScript != VB6. Everything is a variant. No explicit type declaration allowed. With that said, all you "gurus" bashing other languages, need to step off! All languages, just like coders, have thier good and bad points. It's those points that determine when and what language someone uses, if they have a choice in the matter at all.

    captcha "ewww". I think someone caused a stink?

  • (cs) in reply to Anonymous
    Anonymous:
    Okay, we get it. VB programmers always write basic string functions from scratch using Mid(), and they always get it wrong.

    I swear, if i see For...Mid...InStr one more time...

    To be fair, VB didn't have any decent string manipulation functions when it started out. I could go through and replace about a dozen for..next loops with Replace()... except that there's usually some side effect that some calling function requires. I ought to find something particularly egregious and post it -- shouldn't be hard to find one.

    As for Variants, I'll tell you when you use Variants. You use them because the programmer before you coded the common routine (the one that you don't dare touch because it barely works anyway) like this:

    Public Function EssentialFoo(File, Name As String)

    ... which not only returns a Variant by default, but also has the first of the two parameters ("File") defined as a Variant by default. In effect, it's really declared like this:

    Public Function EssentialFoo(File As Variant, Name As String) As Variant

    Passing a non-variant to the function results in the dreaded Type Mismatch... sometimes. Variants are teh ev1l.

  • Phineas Balmer (unregistered)

    Basically, the purpose is to create a relative path to the root folder (of the web application) based on the current folder (where the web page being executed resides.) This may or may not be the document root for the configured website.

    In my experience, we usually use a configuration and store it in the application cache (global variables for ASP). This only needs to be loaded once when the web application starts and you would make a reference to this in your ASP code with something like:

    <img src=<%= Application("SiteRoot") %>/images/...

    You could also define a shorter variable in the site-wide configuration file to save typing. For instance:

    cfgRoot = Application("SiteRoot")

  • ben (unregistered) in reply to Phineas Balmer

    Is there something wrong with "/" that I'm missing?

    And, OK, if your site root is something wacky for whatever reason, isn't that what apache conf (or equivalent) is for?

    I can't see any reason for needing to store the site root in a variable at all. If you really must, it's not hard, but why?

  • mike5 (unregistered)

    Well, no sense in jumping directly to root. All those folder in between might feel a little bit left out....

  • Holli (unregistered) in reply to sir_flexalot

    ... I wish I didn't know that.

    LOL! Boy you just made my day.

  • (cs) in reply to Jeff S
    Jeff S:
    VGR:
    I wonder what goes through the mind of someone when they choose to use iCount as a variable name instead of slashCount or numSlashes. (Not that using good variable names would redeem this code.)

    In scripting languages where you cannot declare a variable's type explicitly, it is often useful to prefix the "hidden" type in the variable name somehow. One of the few cases in which I think hungarian notation is acceptable and even helpful, IMHO.

    I don't understand why people dislike hungarian in a well typed language?

    So when you are reading the code, in this well typed language, and you see a variable "foo." What type is it?

  • Anonymous coward! (unregistered) in reply to Bert
    Bert:
    A few observations:
    1. IIS supports multiple IPs, multiple web sites, multiple "apps" per website, multiple virtual directories per website, etc. It gives you the ability to configure these however you need.

    Not on XP, it doesn't. WinXP limits you to one active web site. Under that, have all the fun with all the virdirs you want, but you can only have on active web site.

    So if this were running on XP, it could hose you.

Leave a comment on “Back That URL Up”

Log In or post as a guest

Replying to comment #:

« Return to Article