| « Prev | Page 1 | Next » |
|
[probably gonna get flamed for defending this but here goes]
I dont think this is so bad... it IS pre ASP.Net after all... at least its not littered with obscure variable names :-/ |
|
It is not as bad as the other function. There are other ways to do this, but hey it isn't that bad after all. The if else statements are used to select the current choice.
(It would have been nicer to build up the complete string with some sort of inline if else statement though, know strings are double in the function) |
|
Sweet! Nothing like some else branches never effect the output - ever! How about some 'Do Nothings while we're at it?
|
|
[Not trying to get flamed here either]
Notice that a lot of these submissions are in VB? |
|
"Notice that a lot of these submissions are in VB?"
Most of this is IMO the "fault" of MS Office. Some Office gimp hacks together a few macros, finds out that this is called "Programming" and then assumes that he's an uber-leet programmer. A quick move into another job and us decent programmers who just happen to dislike squiggles and curly brackets get a load of unwelcome morons associated with us. Anyway, back onto the topic, since there's no "Maybe" option, surely anything that's not a Yes/Y/1 is going to be No/N/0? Fool. Talking of which, there's no input validation either. Oh, and maybe not so "bad", but since this is just rendering HTML that no human will directly see, why waste bandwidth with all those unrendered carriage returns and tabs? |
|
The whitespace is for the developer debugging the generated HTML. _IF_ you get it right you can save yourself from copy-pasteing it into Front Page. I mean back before IE and FireFox had stuff like the DOM inspector.
|
|
If No then No
Else No ????? Are we not expecting a Yes?? |
|
"Most of this is IMO the "fault" of MS Office. Some Office gimp hacks together a few macros, finds out that this is called "Programming" and then assumes that he's an uber-leet programmer. A quick move into another job and us decent programmers who just happen to dislike squiggles and curly brackets get a load of unwelcome morons associated with us."
WTF? The fault doesn't lie with Office, but rather the IT Managers and HR departments that hire the "uber-leet" programmers. |
|
Verve, thats how the code is supposed to work, nothing wrong with that part.
|
|
Weird that no one mentioned checkboxes yet... :)
|
|
Seeing all this code from where Tim Cartwright works really gives me a finer appreation for the code I have to look at where I work.
Thanks Tim, and I feel your pain. :) |
|
Yeah this code is not that bad. All he/she is doing is printing the HTML for a dropdown list where either Yes is selected by default or No is. Here's how I would have written it:
Function YesNoCombo(sname, strTemp) Dim strCbo, delim delim = vbCrLf & vbTab & vbTab & vbTab & vbTab strCbo = delim & "<select name='" & sname & "' class='rtpfieldsmall' >" & delim If strTemp = "Y" Then strCbo = strCbo & "<option value=N>NO</option>" & delim strCbo = strCbo & "<option selected value=Y>YES</option> & delim Else strCbo = strCbo & "<option selected value=N>NO</option>" & delim strCbo = strCbo & "<option value=Y>YES</option> & delim End If YesNoCombo = strCbo End Function So basically they used one extra If test. Big deal--I've seen much worse things (as a C TA) such as this: if (x == 3) 3 = 0; |
|
MrGenericComment: "Where's the spec?"
I think you mean ... "Do any of you bitches have the spec?" |
|
I have to stop reading this site while I'm eating my lunch.
|
|
MUAHAHAHAHAHA Hexy, found this the other day :
If Email = "" Then Email = "" End If |
|
The sad part is how it leads you on and then just dumps you in front of the entire office. I'm like, okay, okay, okay, okay, HEY WTF. Subtle and tricky this one begins!
That said, obviously a two-dimensional array, with tokens and titles, should be used if one wasn't absolutely sure it would never be extended, then called internally with various convenience functions. No duplication, more than two options, and cleaner code. Just because I'm a C fag I'd use combobox = combobox & "<option " & iif(selected,"selected ","") & " value='" & key & "'>...</option>" |
|
How abour removing an Else part and adding a loop?
Function YesNoCombo(sname, strTemp) Dim strCbo, delim Dim Values[2], Labels[2] Dim i delim = vbCrLf & vbTab & vbTab & vbTab & vbTab strCbo = delim & "<select name='" & sname & "' class='rtpfieldsmall' >" & delim Values[1] = "Y" Values[2] = "N" Labels[1] = "YES" Labels[2] = "NO" for i = 1 to 2 strCbo = strCbo & "<option value=" & Values[i] if strTemp = Values[i] then strCbo = strCbo & " selected " strCbo = strCbo & ">" & Labels[i] & "</option>" & delim Next YesNoCombo = strCbo End Function |
|
Nope - I'm far too polite!
|
|
This isn't bad.
Context switches in classic are bad. Inline code that's impossible to maintain is bad. A handful of helper functions that basically emulate ASP.NET WebControls are *not* bad. Instead of NIH, it seems some people have a severe case of NIBABC (Not Invented By A Big Company). Obviously a Select Box that accepts a RecordSet, and optional Default value would be more useful. And when it remembers it's own viewstate is always nice. But the basic premise is solid, higher performance, easier to maintain, and results in less code. Makes one wonder what people would've said had they seen a .NET WebControl before they were common place... Can you refactor inline class ASP to a COM component with a minimum of fuss? No? Well you can with a global helper function. Now it's been awhile since I've done much with classic, but... <code> ' Example: <%=ToDropDown(Users, "Name", "Id", 1, "NoCssClass", 0, true)%> ' No, "NoCssClass" is not an actual CSS Class, I just hate empty quotes you have to refer back to the function for to decipher. Function ToDropDown(rs, textField, valueField, size, cssClass, selectedValue, rsClose) HtmlWriter = "<!-- BEGIN: ToDropDown Function Call -->" & vbNewLine _ & vbTab & "<select name=""tdd_" & valueField & """ id=""tdd_" & valueField & """ class=""" _ & cssClass & """ size=""" & size & """>" & vbNewLine While Not rs.EOF If Request.Form("tdd_" & valueField) = rs.Fields(valueField).Value or Request.Form("tdd_" & valueField) = null and selectedValue = rs.Fields(valueField).Value Then HtmlWriter = HtmlWriter & vbTab & vbTab & "<option value=""" & rs.Fields(valueField).Value _ & """ selected=""selected"">" & rs.Fields(textField).Value & "</option>" & vbNewLine Else HtmlWriter = HtmlWriter & vbTab & vbTab & "<option value=""" & rs.Fields(valueField).Value _ & """>" & rs.Fields(textField).Value & "</option>" & vbNewLine End If rs.MoveNext() Wend If rsClose = true Then rs.Close() End If HtmlWriter = HtmlWriter & vbTab & "</select>" & vbNewLine _ & "<!-- END: ToDropDown Function Call -->" & vbNewLine ToDropDown = HtmlWriter End Function </code> It's not perfect, but it's a helluva lot better than inline spaghetti code. |
|
I hope ALL the code examples that people have been providing in this thread are supposed to be humorous. I couldn't imagine writing ANY of them in good conscience.
|
That's a good one. You never get flamed here for attacking VB, only for defending it. Sort of like if a group of guys are beating up a hobo, and someone stops and says, "Is this right?" It kind of spoils the mood. |
| « Prev | Page 1 | Next » |