Click here to Skip to main content
15,510,483 members

Comments by jsc42 (Top 39 by date)

jsc42 1-May-22 17:37pm View    
That algorithm (plus most others) needs a seed to generate the value. The seed should be randomly chosen, which takes us back to square 1 again unless you have some other pseudo-random number generator to start with (e.g. current time as milliseconds since the epoch mod some large no). Alternatively, see https://xkcd.com/221/ but I doubt that that would be acceptable in the OP's situation.
jsc42 22-Apr-22 12:57pm View    
The settings would have to be User, not Application. But it is the wrong place to save it. You want something that is pan-user, in case a different user uses your application. I assume that the registration details are being saved to a database, so the best place is the save the value in a table in the database.

Also, I note that you are setting StudentNumber as an increment of studentTotal, which you are setting to zero at the start of each run. This is another reason you are restarting the count each time.

Finally, for now, if you have 50 children who attend 200 days a year your counter will roll over from 9999 back to 0000. It would be better if the id number was independent of the year so it can grow as big as it needs.
jsc42 22-Apr-22 12:47pm View    
IE is not completely dead! Somewhat moribund - more like a walking zombie. You can still use CreateObject("InternetExplorer.Application") in a Windows Script File or a Hypertext Application and it starts an IE window. The standard DLL XHTML? is effectively IE7 (so HTML4 + CSS1.0 + JS1.2) but it still works even on Windows 11. ActiveX, therefore, limps along even today.

However, I concur that it has the potential to be a massive security problem and should be avoided like the plague. I only use it for a couple of very old utilities that I wrote for myself years ago, so I know what the safety risks are with them. I would never pick something off the shelf that used ActiveX and have no intention of writing anything using it in the future.

Caveat Emptor!
jsc42 22-Apr-22 8:30am View    
Which browser? Which OS? (ActiveXObject is only supported on MS-Windows)
I use it on *.hta in a script that I wrote for W98 and it still works on W11, but it is generally not regarded as the correct way to do things.
jsc42 4-Oct-21 9:33am View    
@Chris_Copeland's suggest is good!

If, for some reason (and I cannot think of any time that that is true), you cannot get a name that makes sense; or (as sometimes happens) you need to correct someone else's logic because they got the test the wrong way round, put the false test in parentheses e.g.

if (!(somethingFalse)) // Parentheses highlights the fact that something awkward is going on
doFalseAction;

alternatively, it is (just about) acceptable to do

if (condition)
{
// Nothing to do if condition is true
}
else // Condition is false
doFalseAction():

I have often seen

if (!condition)
doFalseAction();
else
doTrueAction();

If you come across that, invert the code to

if (condition)
doTrueAction();
else
doFalseAction();

Do not skimp on comments. If your code, after careful refactoring, is still not readable, alert the next reader that there is a pitfall to aviod e.g.

// Looking for a missing value
if (!(HasValue(thingBeingTested))) // See if thingBeingTested has not got a value
doNoValueAction(); // thingBeingTested has not got a value