• Procedural (unregistered) in reply to Code Dependent
    Code Dependent:
    Global search and replace is your friend.

    Global search and replace is your friend too.

  • (cs)

    They didn't even do it well... And they had a LOT of opportunities...

    Function MyMonthName(m)
    	Dim names = Array( _
    		"January", "February", "March", _
    		"April", "May", "June", _
    		"July", "August", "September", _
    		"October", "November", "December")
    	Dim size
    	On Error Resume Next
    	Err.Clear()
    	m = CInt(m) - 1
    	If Err.Number = 0 Then
    		size = UBound(names)
    		If Err.Number = 0 And m > 0 And m < size Then
    			MyMonthName = names(m)
    		End If
    	End If
    	Err.Clear()
    	On Error GoTo 0
    End Function
    Or if you've been working with the language long enough to write all of your appropriate wrappers, you can shorten it down to more like...
    Function MyMonthName(m)
    	Dim names = Array( _
    		"January", "February", "March", _
    		"April", "May", "June", _
    		"July", "August", "September", _
    		"October", "November", "December")
    	m = ToInt(m) - 1
    	If m > 0 And m < ArraySize(names) Then
    		MyMonthName = names(m)
    	End If
    End Function
    (Untested, but you get the idea...)

    This assuming you're unaware of the built-in. :P And it's excusable because when you write VBScript you quickly learn to stop wondering if the wheel is built-in. :P Unfortunately, this can lead to missing the handful of wheels that are...

    Addendum (2009-04-22 11:49): Made a 1-based versus 0-based error while typing it up and refactoring it. :P

    -If Err.Number = 0 And m > 0 And m < size Then
    +If Err.Number = 0 And m >= 0 And m < size Then
    -If m > 0 And m < ArraySize(names) Then
    +If m >= 0 And m < ArraySize(names) Then
  • Happy Customer (unregistered) in reply to Anon Ymous
    Anon Ymous:
    BoBThESeXy:
    It's like trying to recreate wheel. Except the wheel is lumpy, deformed, and irritatingly stupid.
    And also made of jell-o.

    Just wanted to say thanks! The deformed, irrational, stupid, gelatinous wheel you created is exactly what we wanted!

    Excellent work

  • ThatGuy (unregistered) in reply to shadowman
    shadowman:
    ThatGuy:
    What would make this even better is if this was for the National Institute of Health (NIH).

    Why?

    Not Invented Here.

  • (cs) in reply to Ancient_Hacker
    Ancient_Hacker:
    Could be worse.

    I've seen apps that do SQL lookups to get the name of the days of the week. Every time.

    A SQL Lookup isn't a horrible idea if the app is international. Doing it every time is a waste.

  • (cs)

    Jeez, even ZZ-Top repeats themselves...

    I been up, I been down. Take my word, my way 'round. I ain't askin' for much. I said, Lord, take me downtown, I'm just lookin' for some tush. I been bad; I been good, Dallas, Texas, Hollywood. I ain't askin' for much. I said, Lord, take me downtown, I'm just lookin' for some tush. Take me back, way back home, not by myself, not alone. I ain't askin' for much. I said, Lord, take me downtown, I'm just lookin' for some tush.

  • (cs) in reply to Spectre
    Spectre:
    Sanity:
    Can anyone explain to me where "on error resume next" would EVER be a good idea?

    In VBScript. The only other option (which is the default) is "On Error GoTo 0", which makes all errors fatal.

    I'm not a VBScript programmer, but I believe you do this:

    On error resume next DoSomething if err.number <> 0 then msgbox err.description

  • awfwefewa (unregistered)

    Sounds like SAP, where custom tables start with Z.

  • mauhiz (unregistered)

    You lot seriously lack basic risk management skills. What if a function or two happen to be accidentally erased?

    Outstanding programming experience has forcefullymade redundancy become my motto; I always code my functions several times, if possible in several locations; and when I have time, in several programming languages, in case one of them disappears from the face of the earth (I wish VBScript would).

  • IV (unregistered)

    Frist!!1!

    (I know we are going to use this post more than once.)

  • (cs) in reply to Single User

    Well actually, no, it's not for concurrency as in concurrently running threads.

    I'm far of defending this anti pattern, but I do clearly see where it's comming from!

    it's just a bunch of developers distrusting each other.

    "see: I need this function and I clearly see, it's already there. But I'm not gonna use it in my code, because the original developer might change it without note - and my code breaks. so, i just copy-paste the exact code and use it as MY function, so I got control..."

    this isn't really only a problem of the developers, but a sign for very bad governance in said equippe...

  • (cs) in reply to Single User

    Well actually, no, it's not for concurrency as in concurrently running threads.

    I'm far of defending this anti pattern, but I do clearly see where it's comming from!

    it's just a bunch of developers distrusting each other.

    "see: I need this function and I clearly see, it's already there. But I'm not gonna use it in my code, because the original developer might change it without note - and my code breaks. so, i just copy-paste the exact code and use it as MY function, so I got control..."

    this isn't really only a problem of the developers, but a sign for very bad governance in said equippe...

  • Zach Bora (unregistered)

    There is no WTF in redefining the MonthName function!

    The VB function MonthName returns the language specific month name. If they want to have portable data they need to keep the months in english. My current OS is in french and MonthName(2) returned "février".

    As far as I know, there is no built-in function to return the month name in a specific language.

  • NamesAreImportant (unregistered) in reply to Zach Bora
    Zach Bora:
    There is no WTF in redefining the MonthName function!

    The VB function MonthName returns the language specific month name. If they want to have portable data they need to keep the months in english. My current OS is in french and MonthName(2) returned "février".

    As far as I know, there is no built-in function to return the month name in a specific language.

    So there the WTF is a bad name. It it's purpose is to just return English month names then it should ideally be something like EnglishMonthName.

  • (cs) in reply to Salami
    Salami:
    I'm not a VBScript programmer, but I believe you do this:

    On error resume next DoSomething if err.number <> 0 then msgbox err.description

    That's correct. Or test for a particular error and do cleanup:
    On error resume next
    DoSomething
    if err.number <> 0 then
    select case err.number
    case vbFile_not_found
    ' handle file_not_found error
    case vbConnection_not_open
    ' handle connection_not_open error
    case else
    connection.close
    msgbox err.description
    end select
    else
    ' continue execution of routine
    end if

  • who cares (unregistered)

    vbscript is not so bad... bad coders however...

    Blaming vbscript really is becoming redundant. I can show you the same crap code in PHP a thousand times over.

  • Buddy (unregistered) in reply to xtremezone
    xtremezone:
    ... This assuming you're unaware of the built-in. :P And it's excusable because when you write VBScript you quickly learn to stop wondering if the wheel is built-in. :P Unfortunately, this can lead to missing the handful of wheels that are...

    My biggest complaint about VBScript is the lack of include file functionality. You either repeat code in each file, or create some kind of COM object. Otherwise, it's good enough for lots of tasks. Very good garbage collection, certainly better than PHP and others for similar tasks. I've even used it as a wrapper to interface databases for OLAP objects running 24/7!

  • awfwefewa (unregistered) in reply to NamesAreImportant
    NamesAreImportant:
    Zach Bora:
    There is no WTF in redefining the MonthName function!

    The VB function MonthName returns the language specific month name. If they want to have portable data they need to keep the months in english. My current OS is in french and MonthName(2) returned "février".

    As far as I know, there is no built-in function to return the month name in a specific language.

    So there the WTF is a bad name. It it's purpose is to just return English month names then it should ideally be something like EnglishMonthName.

    Yeah, but MonthName is in English, so it's okay.
  • Peter (unregistered) in reply to awfwefewa
    awfwefewa:
    NamesAreImportant:
    Zach Bora:
    As far as I know, there is no built-in function to return the month name in a specific language.
    So there the WTF is a bad name. It it's purpose is to just return English month names then it should ideally be something like EnglishMonthName.
    Yeah, but MonthName is in English, so it's okay.
    So we make the rule that the language used to name the function defines the language that the function uses (MonthName for English, NomDeMois for French, MonatsName for German and so on). And then if we want the function to use whatever the local language may be, we...

    Can I get back to you on this?

  • ur, what? (unregistered) in reply to Buddy
    Buddy:
    xtremezone:
    ... This assuming you're unaware of the built-in. :P And it's excusable because when you write VBScript you quickly learn to stop wondering if the wheel is built-in. :P Unfortunately, this can lead to missing the handful of wheels that are...

    My biggest complaint about VBScript is the lack of include file functionality. You either repeat code in each file, or create some kind of COM object. Otherwise, it's good enough for lots of tasks. Very good garbage collection, certainly better than PHP and others for similar tasks. I've even used it as a wrapper to interface databases for OLAP objects running 24/7!

    lack of include file functionality? in what way? you can include files in classic asp.

  • Iamthebest (unregistered)

    My function is better than your function syndrom :)

  • (cs) in reply to Zach Bora
    Zach Bora:
    There is no WTF in redefining the MonthName function!

    The VB function MonthName returns the language specific month name. If they want to have portable data they need to keep the months in english. My current OS is in french and MonthName(2) returned "février".

    As far as I know, there is no built-in function to return the month name in a specific language.

    The function doesn't directly support a locale parameter, but you can change the thread locale when calling MonthName()

    Const french_lcid = 1036
    SetLocale(french_lcid) 
    WScript.Echo MonthName(1)
    Const en_us_lcid = 1033
    SetLocale(en_us_lcid) 
    WScript.Echo MonthName(1)
    

    Prints: janvier January

    "How To Use GetLocale() and SetLocale() in VBScript" http://support.microsoft.com/kb/232158

  • m0ffx (unregistered) in reply to snoofle
    snoofle:
    Charlie Very Sure:
    By the time Mark got to zzFormatDate4, he just gave up looking. It was going to be a very long maintenance project.
    Yeah, I mean, imagine if you had to add another month to every one of those functions! Kinda like Y2K: miss one and the world falls apart.
    You mean, like for folks that use lunar calendars? Cuz that never happens.

    It's for when we settle Mars, and the code gets taken with the settlers.

  • (cs)

    thanks for that!!! "real programmers" hardly ever bother with vbscript, LOL!!

  • Great link for WTF source material buried in this article (unregistered)

    You are all going to be sorry and come running to this guy for code when the IEEE month naming subcomittee decides to rename one of the months "Colbert-uary" as a consolation prize for the space station naming debacle. Who will have the last laugh then, huh?!?!?!

  • Sanjay Kumar (unregistered)

    Pathetic. Abysmal. The Pits. These offshore programmers. But still higher than onshore ones.

  • (cs) in reply to ih8u

    [quote user="ih8u"][quote user="Marc B"][quote user="Single User"]

    Yeah, but I'm planning on running 10 simultaneous threads, and I'm running out of names:

    Thread 1: MonthName Thread 2: GetMonthName Thread 3: TheMonthName Thread 4: GetTheMonthName Thread 5: MonthsName Thread 6: GetMonthsName Thread 7: TheMonthsName Thread 8: GetTheMonthsName

    What do I do for 9 and 10?!?[/quote]

    ...

    Then you could try using different languages by translating the method name to French, German, Spanish, etc. Just use babelfish.

    ... [/quote] Well, I happen to think that the completely unrelated name is better, but if you ever go to the babelfish option, make sure to make those translation in series, AKA, translate to German the French version, and to Spanish the German version.

    Also, be free to add some eastern languages between western ones. That will make the results less repetitive.

  • (cs)
    I'm not a VBScript programmer, but I believe you do this:

    On error resume next DoSomething if err.number <> 0 then msgbox err.description

    Yeah, if you want your web server to stop processing the request until someone dismisses the message box on the server...

    (What? People use VBScript on the desktop? On purpose???)

  • anon (unregistered) in reply to WayneCollins
    WayneCollins:
    I'm not a VBScript programmer, but I believe you do this:

    On error resume next DoSomething if err.number <> 0 then msgbox err.description

    Yeah, if you want your web server to stop processing the request until someone dismisses the message box on the server...

    (What? People use VBScript on the desktop? On purpose???)

    VBscript works just fine... You just never use msgbox, and you set all desktops to use cscript.exe instead of wscript.exe, so the output is sent to command-line

  • Matt (unregistered) in reply to dpm

    ABSOLUTELY, couldn't agree more. This is one of the biggest reasons provoking me to hari kari every day. I keep a 4 inch blade in my desk just in case.

  • (cs) in reply to Sanity
    Sanity:
    Can anyone explain to me where "on error resume next" would EVER be a good idea?
    Can anyone explain to me where programming in VBScript would EVER be a good idea?

    Fixed.

  • Andreas (unregistered)

    Me, I just love how june and july is abbreviated. A real byte/character-saver.

  • vbscript is srs business (unregistered) in reply to SubSpace
    SubSpace: Can anyone explain to me where programming in VBScript would EVER be a good idea?

    Because it works wonderfully to automate simple tasks in Windows environments? Because I can quickly develop adequate solutions with it in half the time it would take in a higher level language? Because its an easy way to utilize the power of WMI? The people writing the crappy vbscript WTFs on this site would be writing crappy WTFs no matter what language they were using.

  • The Dread Pedant Roberts (unregistered) in reply to Anon
    Anon:
    Marc B:
    Single User:
    Anon:
    I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.
    It's for concurrency. If MonthName is already running in another thread, you can fall back on using GetMonthName. Clear as daylight.

    Yeah, but I'm planning on running 10 simultaneous threads, and I'm running out of names:

    Thread 1: MonthName Thread 2: GetMonthName Thread 3: TheMonthName Thread 4: GetTheMonthName Thread 5: MonthsName Thread 6: GetMonthsName Thread 7: TheMonthsName Thread 8: GetTheMonthsName

    What do I do for 9 and 10?!?

    Thread 9: GetNameOfMonth Thread 10: GetNameOfTheMonth Thread 11: NameOfTheMonth Thread 12: NameOfMonth Thread 13: ...?

    Thread 14: Profit

    Derf.

  • I (unregistered) in reply to monkeyPushButton
    monkeyPushButton:
    Anon:
    I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.
    Well, they probably already had it in their code and this was faster than changing the call in their code. Besides, just this one time...

    Clearly they followed the directive at the start....

    'If you do something more than once, put it in a function here

    They were doing something more than once, and each time they did it (presumably after the first) they made a function for it.

  • (cs)

    The real problem is that nearly everybody who uses VBScript/Classic ASP does it the half-assed moron way and uses On Error Resume Next to have the script not die so they can happily code whatever shit they want, and hey see it works even though I declare this variable after I assign a value to it.

    I mean it's not like we programmers are supposed to be professionals trained to do a job, no siree Bob, any idiot can hack out VBScript that kinda sorta works thanks to On Error Resume Next.

    And, while VBScript is not the WTF, the sheer number of idiots who use(d) it to hack together WTF code give the language a bad name.

  • (cs) in reply to Anon
    Anon:
    Marc B:
    Single User:
    Anon:
    I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.
    It's for concurrency. If MonthName is already running in another thread, you can fall back on using GetMonthName. Clear as daylight.

    Yeah, but I'm planning on running 10 simultaneous threads, and I'm running out of names:

    Thread 1: MonthName Thread 2: GetMonthName Thread 3: TheMonthName Thread 4: GetTheMonthName Thread 5: MonthsName Thread 6: GetMonthsName Thread 7: TheMonthsName Thread 8: GetTheMonthsName

    What do I do for 9 and 10?!?

    Thread 9: GetNameOfMonth Thread 10: GetNameOfTheMonth Thread 11: NameOfTheMonth Thread 12: NameOfMonth Thread 13: ...?

    Thread 14: Profit!

  • Fangdork (unregistered) in reply to ThePants999
    ThePants999:
    Anon:
    Anon: I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.

    I suspect that they copy-pasted it from some crappy website, and then someone else did exactly the same thing.

    That's why I get all my code from quality websites-like this one!

  • ingenium (unregistered) in reply to Anon
    Anon:
    Marc B:
    <snip> What do I do for 9 and 10?!?
    Thread 9: GetNameOfMonth Thread 10: GetNameOfTheMonth Thread 11: NameOfTheMonth Thread 12: NameOfMonth Thread 13: ...?
    Thread 14: Profit!!
  • ingenium (unregistered) in reply to ingenium
    ingenium:
    Thread 14: Profit!!
    Dammit, someone else got there first. Well, great minds think alike...and so do we.
  • (cs) in reply to WayneCollins
    WayneCollins:
    I'm not a VBScript programmer, but I believe you do this:

    On error resume next DoSomething if err.number <> 0 then msgbox err.description

    Yeah, if you want your web server to stop processing the request until someone dismisses the message box on the server...

    (What? People use VBScript on the desktop? On purpose???)

    Your Web Server doesn't have some kind of robot built out of CD-ROM drives that click a mouse to OK message boxes?

  • (cs) in reply to Single User
    Single User:
    Anon:
    I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.
    It's for concurrency. If MonthName is already running in another thread, you can fall back on using GetMonthName. Clear as daylight.
    The funny thing is in VB6, you could have very limited threading. In my experience it would crash if two threads ever called the same function, even not at the same time. So this is actually a possible scenario. (You'd be an idiot to rely on that undefined behaviour for anything more than a quick hack in a hobby app though.)
  • censored (unregistered) in reply to Code Dependent
    Code Dependent:
    Or test for a particular error and do cleanup:
    On error resume next
    DoSomething
    if err.trool <> False then 
     select case err.number
      case vbFile_not_found
       ' handle file_not_found error
      case else
       ' handle true
     end select
    else
     ' continue execution of routine
    end if

    FTFY

  • (cs) in reply to lolwtf
    lolwtf:
    Single User:
    Anon:
    I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.
    It's for concurrency. If MonthName is already running in another thread, you can fall back on using GetMonthName. Clear as daylight.
    The funny thing is in VB6, you could have very limited threading. In my experience it would crash if two threads ever called the same function, even not at the same time. So this is actually a possible scenario. (You'd be an idiot to rely on that undefined behaviour for anything more than a quick hack in a hobby app though.)
    And if you write an ATL component in C++ you can bring the power of multi-threading to VB6 without too many problems.

    BTDTGTTS

  • Anonymous (unregistered)

    F100rst!!1!100!1!

  • Anonymous (unregistered)

    F101rst!!1!101!1!

  • ClaudeSuck.de (unregistered) in reply to Ancient_Hacker
    Ancient_Hacker:
    Could be worse.

    I've seen apps that do SQL lookups to get the name of the days of the week. Every time.

    And they don't use a process to create an XML-file first, then send it to a Webservice which answers in HTML, transform this again to XML, convert it to CSV, put that in a hidden field and then apply logic to extract the month name from the correct hidden field (txtJanuaryName, txtFebruaryName, etc. ? Lame! I could imagine putting the whole into a message queue, just in case...

  • ClaudeSuck.de (unregistered) in reply to ClaudeSuck.de
    ClaudeSuck.de:
    Ancient_Hacker:
    Could be worse.

    I've seen apps that do SQL lookups to get the name of the days of the week. Every time.

    And they don't use a process to create an XML-file first, then send it to a Webservice which answers in HTML, transform this again to XML, convert it to CSV, put that in a hidden field and then apply logic to extract the month name from the correct hidden field (txtJanuaryName, txtFebruaryName, etc. ? Lame! I could imagine putting the whole into a message queue, just in case...

    Aaaarg, I forgot the wooden table somewhere inbetween.

  • Orbstart (unregistered) in reply to mauhiz
    mauhiz:
    Outstanding programming experience has forcefullymade redundancy become my motto; I always code my functions several times, if possible in several locations; and when I have time, in several programming languages, in case one of them disappears from the face of the earth (I wish VBScript would).

    It's also good to have multiple redundant functions in case one of them has a bug in it.

  • Gary B (unregistered)

    ... especially the array and string handling functions. Like English synonyms, there seems to be a plethora of array functions that do almost, but not exactly the same thing.

Leave a comment on “zzGeneralFunctions”

Log In or post as a guest

Replying to comment #:

« Return to Article