| | #1 (permalink) | |
| Resident Slayer | What does this code do? Have you ever been wading through someone else's code and run across something that you had no idea what it did and you were too lazy to work it out? That's what this thread is for. So to get things going, what does this code do? Obviously its in VisualBasic and the input string is a URL. The obscure we see eventually. The completely obvious, it seems, takes longer, ![]() Buffy ---------------- "If you do not agree with anything I say, I'll not only retract it, but deny under oath that I ever said it!" __________________________________________________ ______________-- Tom Lehrer "The shrinks diagnosed me a sociopath with paranoid delusions. But they’re just out to get me cause I threatened to kill them." Forum Administrator Hypography Science Forums - Science for Boys and Girls! Its not for nothing that we hang out here. | |
| ||
| | #2 (permalink) | |
| Exhausted Gondolier | Re: What does this code do? Gosh Buffy years ago I worked at a place where hoards of improvised VB6 devs had done the most imaginative things you could think of, but I've no idea what InStr returns if you tell it to search for the empty string in the midst of the first argument. By reason it ought to occur just befor the start and just after the end as well as between consecutive characters, should it return sem-integer values? Anyway it strikes me Mid is missing an argument but I suppose the result will just run to the end and I suppose, more seriously, that the call to Instr will return 0 or maybe -1 so you should just get the initial value of the string. Could it be that originally there was a string expression, later replaced by "" instead of removing or commenting out the lines? Obviously this would have sought the reversal of the expression and removed it if found, but they could have just reversed the expression instead. ![]() ---------------- Who's afraid of the Big Black Hole????? Go Black Hole! W the Black Hole! ![]() ![]() ![]() Hasta que el agujero negro nos traga, siempre! Hypography Forum PITA...... er, Administrator. | |
| ||
| | #3 (permalink) | |||||
| Resident Slayer | Re: What does this code do? Quote:
Results in lots of "junk DNA" being created! ![]() Quote:
Quote:
No seriousity necessary! ![]() Instr returns -1 if not found, but is the empty string found? Quote:
BTW: yes, this code snippet has been sitting in a piece of commercial code--on an active code path--for over 5 years... In San Francisco, Haloween is redundant, ![]() Buffy ---------------- "If you do not agree with anything I say, I'll not only retract it, but deny under oath that I ever said it!" __________________________________________________ ______________-- Tom Lehrer "The shrinks diagnosed me a sociopath with paranoid delusions. But they’re just out to get me cause I threatened to kill them." Forum Administrator Hypography Science Forums - Science for Boys and Girls! Its not for nothing that we hang out here. | |||||
| ||||||
| | #4 (permalink) | |
| Doing the Impossible | Re: What does this code do? When performing an InStr function for an empty string the function will return the start position of the search. Since the start position is omitted the search begins at the start of the string. InStr Function It appears to me that the code simply strips the last character off of the string, but it does it by running twice around the house. It reverses it It finds he first position It finds the substring from the second position to the end It reverses the substring that it found I would guess that doing a ValURL = Mid(VarURL,1,Len(VarURL)-1) would do the same thing. ---------------- aka TheBigDog - Hypography Full Freaking Moderator Become a Hypography sponsor! The truth is incontravertible; malice may attack it, ignorance may deride it, but in the end there it is. - Winston Churchill TheBigDog's recommended reading: The Science of Success - Charles G. Koch A neutron goes into a bar and asks the bartender, "How much for a beer?" The bartender replies, "For you, no charge." Last edited by TheBigDog; 10-09-2008 at 08:12 PM. | |
| ||
| | #5 (permalink) | ||||||
| Exhausted Gondolier | Re: What does this code do? Quote:
![]() Quote:
!!!!! Garsh, you're right!!!!Now I get it!!!! ![]() Quote:
I thought I had already semi-answered that yesterday, although more or less seriously.... A doggone mathematician as I strive to be would say there are as many of them as you like, before and after each character of any string! Quote:
If you hadn't said Quote:
Gee, this is fun, let's see what TBD says now... ---------------- Who's afraid of the Big Black Hole????? Go Black Hole! W the Black Hole! ![]() ![]() ![]() Hasta que el agujero negro nos traga, siempre! Hypography Forum PITA...... er, Administrator. | ||||||
| |||||||
| | #6 (permalink) | |
| Resident USSRian | Re: What does this code do? Agree with TBD, actually read his comment after coming to the same conclusion the code first reverses the string returns the start of the string (dumb, if you ask me) then rereads the string from the middle, in this case ommiting the first character in the reversed string then reverses the string again to get the result without the last character. this will also strip spaces, if i'm not mistaken, that's the reason to find the start of the string i changed the TBD's code a little, to compensate for spaces: ValURL = Left(RTrim(VarURL),Len(RTrim(VarURL))-1) ---------------- And remember that great question that Pierre-Simon Laplace and Sir Isaac Newton, Andrei Markov and David Hilbert, Richard Feynman and Enrico Fermi, Albert Einstein and Edmund Halley did not come to ask throughout all of their dedication and work: "Who the hell is IMing me?" This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License. ![]() Last edited by alexander; 10-10-2008 at 06:09 AM. | |
| ||
| | #7 (permalink) | |
| Resident USSRian | Re: What does this code do? oh just had a stroke of genius to save you more ticks ValURL = Left(VarURL,Len(RTrim(VarURL))-1) ---------------- And remember that great question that Pierre-Simon Laplace and Sir Isaac Newton, Andrei Markov and David Hilbert, Richard Feynman and Enrico Fermi, Albert Einstein and Edmund Halley did not come to ask throughout all of their dedication and work: "Who the hell is IMing me?" This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License. ![]() | |
| ||
| | #8 (permalink) | ||
| Doing the Impossible | Re: What does this code do? Quote:
ValURL = Left(Trim(VarURL),Len(Trim(VarURL))-1) But the code shown doesn't concern itself with blank spaces. Bill ---------------- aka TheBigDog - Hypography Full Freaking Moderator Become a Hypography sponsor! The truth is incontravertible; malice may attack it, ignorance may deride it, but in the end there it is. - Winston Churchill TheBigDog's recommended reading: The Science of Success - Charles G. Koch A neutron goes into a bar and asks the bartender, "How much for a beer?" The bartender replies, "For you, no charge." | ||
| |||
| | #9 (permalink) | |
| Resident USSRian | Re: What does this code do? no, no, i have been thinking about that problem all day, too, and i think its because of a combination of factors, they had more then 6 hours of sleep and were really sober.... Maybe the person never heard of the string functions? btw i thought of making it so it trims both right and left hand spaces, the faster way of doing that would be to split that into two lines that would save some ticks.... ValURL=Trim(ValURL) and then ValURL=Left(ValURL,Len(ValURL)-1) but no, i was thinking that the only function that could potentially strip spaces in their code would be the inStr function, so i thought, well, maybe, as a side effect it stripped spaces... ? ---------------- And remember that great question that Pierre-Simon Laplace and Sir Isaac Newton, Andrei Markov and David Hilbert, Richard Feynman and Enrico Fermi, Albert Einstein and Edmund Halley did not come to ask throughout all of their dedication and work: "Who the hell is IMing me?" This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License. ![]() | |
| ||
| | #10 (permalink) | |
| Doing the Impossible | Re: What does this code do? I am not sure they were stripping spaces at all, but just arbitrarily removing whatever the last character is. I suppose that the text this was handling has something like a carriage return (chr(13)) as the last space and this was the way they chose to remove it. Bill ---------------- aka TheBigDog - Hypography Full Freaking Moderator Become a Hypography sponsor! The truth is incontravertible; malice may attack it, ignorance may deride it, but in the end there it is. - Winston Churchill TheBigDog's recommended reading: The Science of Success - Charles G. Koch A neutron goes into a bar and asks the bartender, "How much for a beer?" The bartender replies, "For you, no charge." | |
| ||
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How would you code this? | sanctus | Computer Science | 4 | 03-05-2008 07:06 AM |
| the da vinci code | plain_heropt1 | Books, movies, games | 8 | 01-09-2008 09:57 PM |
| New code discovered in DNA | C1ay | News in Brief | 1 | 07-25-2006 03:44 PM |
| Break the code! | ronthepon | Watercooler | 25 | 07-21-2006 02:12 AM |
| URL code tag test | Turtle | Test forum | 7 | 07-15-2006 02:21 PM |
All times are GMT -8. The time now is 02:50 PM.


















would say there are as many of them as you like, before and after each character of any string! 






