- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
If only there was a command for that...
O wait is it not the '?'
Admin
Admin
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...
Admin
Or /dir///dir/
Admin
Admin
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
Admin
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...
Admin
'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.
Admin
Admin
Admin
Admin
this is why I like ASP.NET...
works sooo much better!Admin
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.
Admin
No, in VB you set the return value by assigning to the name of the function.
Admin
Admin
Admin
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.
Admin
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.
Admin
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.
Admin
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).
Admin
Continuing on the vb oddities... What is the inital value of the return value, before initialized ? Because the first
uses an uninited RootLevel
Admin
I'd guess at the empty string, since it's clearly a string variable, but that might be too sensible for VB.
Admin
I want to see the database code! (pseudo code, because I don't know what crazy moon language this is)
Admin
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.
Admin
VBScript auto-initializes variables to an empty variant. This stringizes to "".
Admin
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?)
Admin
Nope. In VB(A/6), that's how you assign a return value to a function. Used to be that way in Pascal, too.
Admin
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.
Admin
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.
Admin
Looks like someone's taken the term "path" a little too literally. --RA
Admin
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 =)
Admin
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.)
Admin
So there's really no good reason to use it in VB6? I'm genuinely curious to hear if there is one.
Admin
Based on the other variable names, I'd say they used it to denote that this is an integer.
Admin
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.
Admin
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.
Admin
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
Admin
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.)
Admin
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!
Admin
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.
Admin
A few observations:
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.
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.
The IIS admin (and or development policy) should really be forcing the developers to code to the site level.
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
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)
Admin
No, it's not recursing.
Admin
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?
Admin
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:
... 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:
Passing a non-variant to the function results in the dreaded Type Mismatch... sometimes. Variants are teh ev1l.
Admin
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")
Admin
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?
Admin
Well, no sense in jumping directly to root. All those folder in between might feel a little bit left out....
Admin
... I wish I didn't know that.
LOL! Boy you just made my day.
Admin
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?
Admin
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.