Yew cannot be serious! Cockerel hedge that was village landmark for 110 years is chopped down and replaced with gargoyle
Horror as man dies after 300kg of glass falls onto him in Dural
Horrific scenes in Mayfair as female driver ploughs her car into 'influencer' and other pedestrians near nightclub at 4.30am as shocked crowd looks on
Former Army National Guardsman who killed EIGHT kids in horror Louisiana rampage was father to some of the victims
'Invisible mouse' made a mess of PC rebuild
Who, Me? Welcome to yet another Monday, and therefore to this week's edition of Who, Me? For those unfamiliar, it's The Register's reader-contributed column that shares your stories of workplace messes, and how you tried to clean them up without dirtying your career prospects.…
Meet Mr Rosamund Pike: The VERY upper class, twice-divorced eccentric ex-heroin addict 20 years her senior who almost nobody knew existed until she name-checked him at the Oliviers
Meet Mr Rosamund Pike: The VERY upper class, twice-divorced eccentric ex-heroin addict 20 years her senior who almost nobody knew existed until she name-checked him at the Oliviers
CodeSOD: Good Etiquette
"Here, you're a programmer, take this over. It's business critical."
That's what Felicity's boss told her when he pointed her to a network drive containing an Excel spreadsheet. The Excel spreadsheet contained a pile of macros. The person who wrote it had left, and nobody knew how to make it work, but the macros in question were absolutely business vital.
Also, it's in French.
We'll take this one in chunks. The indentation is as in the original.
Public Sub ExporToutVersBaseDonnées(ClasseurEnCours As Workbook) Call AffectionVariables(ToutesLesCellulesNommées) Call AffectationBaseDonnées(BaseDonnées) BaseDonnées.ActivateThe procedures AffectionVariables and AffectationBaseDonnées populate a pile of global variables. "base de données" is French for database, but don't let the name fool you- anything referencing "base de données" is referencing another Excel file located on a shared server. There are, in total, four Excel files that must live on a shared server, and two more which must be in a hard-coded path on the user's computer.
Oh, and the shared server is referenced not by a hostname, but by IP address- which is why the macros were breaking on everyone's computer; the IP address changed.
Let's continue.
'Vérifier si la ligne existe déjà. If ClasseurEnCours.Sheets("DATA").Range("Num_Fichier") = 0 Then Num_Fichier = BaseDonnées.Sheets(1).Range("Dernier_Fichier").Value + 1 Insérer_Ligne: '(étiquette Goto) insérer une ligne Application.GoTo Reference:="Dernière_Ligne" Selection.EntireRow.Insert 'Copie les cellules (colonne A à colonne FI) de la ligne au-dessus de la ligne insérée. With ActiveCell .Offset(-1, 0).Range("A1:FM1").Copy 'Colle le format de la cellule précédemment copiée à la cellule active puis libère les données du presse papier .PasteSpecial .Range("A1:FM1").Value = "" 'Se repositionne au début de la ligne insérée. .Range("A1").Select End With Application.CutCopyMode = FalseUh oh, Insérer_Ligne is a label for a Goto target. Not to be confused by the Application.GoTo call on the next line- that just selects a range in the spreadsheet.
After that little landmine, we copy/paste some data around in the sheet.
That's the If side of the conditional, let's look at the else clause:
Else Cherche_Numéro_Fichier: ' Chercher la ligne ou le numéro de fichier est égale à NumFichier. While ActiveCell.Value <> Num_Fichier If ActiveCell.Row = Range("Etiquettes").Row Then GoTo Insérer_Ligne End If ActiveCell.Offset(-1, 0).Range("a1:a1").Select Wend 'Vérifier le numéro d'indice de la ligne active. If Cells(ActiveCell.Row, 165).Value <> ClasseurEnCours.Sheets("DATA").Range("Dernier_Indice") Then ActiveCell.Offset(-1, 0).Range("A1:A1").Select GoTo Cherche_Numéro_Fichier End If ActiveCell.Offset(0, 0).Range("A1:FM1").Value = "" End IfWe start with another label, and… then we have a Goto. A Goto which jumps us back into the If side of the conditional. A Goto inside of a while loop, a while loop that's marching around the spreadsheet to search for certain values in the cell.
After the loop, we have another Goto which will possibly jump us up to the start of the else block.
The procedure ends with some cleanup:
'----- ' Do some stuff on the active cell and the following cells on the column .----- BaseDonnées.Close True Set BaseDonnées = Nothing End SubI do not know what this function does, and the fact that the code is largely in a language I don't speak isn't the obstacle. I have no idea what the loops and the gotos are trying to do. I'm not even a "never use Goto ever ever ever" person; in a language like VBA, it's sometimes the best way to handle errors. But this bizarre time-traveling flow control boggles me.
"Etiquettes" is French for "labels", and it may be bad etiquette but I've got some four letter labels for this code.
Martin Clunes shuts down claims of a Men Behaving Badly return as he sets his sights on more Hollywood roles after Wuthering Heights acclaim
Man dies in single-car crash as woman arrested
Why am I suddenly being hit with £600 extra in tax a month on my pensions? STEVE WEBB replies
Fire crews and air ambulance attend collision on Essex road
Fire crews and air ambulance attend collision on Essex road
Keir Starmer missed TWO chances to reveal Peter Mandelson vetting failure to the Commons... so why DID the PM wait so long to tell MPs?
NASA working on ‘Big Bang’ upgrade to keep the Voyagers alive for longer
NASA has revealed it’s working on a plan called “The Big Bang” that it hopes will extend the working lives of the Voyager probes.…