ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Finished Programs

DONE: Generate sequential serial numbers

<< < (3/7) > >>

mouser:
I dont know AHK but i can see clearly what it's doing:

SubStr is common name for a function that extracts part of a string (characters at start, end, or middle).

-5 is used by some SubStr implementation to mean the last 5 characters.

So it looks like this is creating a string that starts with "000000" followed by the serial number string (like "12"), to yield something like "00000012",
and then grabbing the string made up of the last 5 characters, e.g. "00012".

In other words it's generating a 6 digit serial number string, padded on the left with 0s.

MilesAhead:
I don´t know if AHK cares about it, but it´s good practice in programming and other languages would not accept such an implicit conversion. ;)
-Ruffnekk (June 21, 2012, 05:18 AM)
--- End quote ---

The "I don't know" part above is the salient phrase. Goolge COM and Variant. As for the bit about SubStr(), such sarcasm is weak.  That's all you can come up with?  Read the help for SubStr() and analyze it on here. Then maybe I'll ask when something befuddles me.

If you can analyze this run-on paragraph, I'd appreciate it

================================================================

SubStr(String, StartingPos [, Length]) [v1.0.46+]: Copies a substring from String starting at StartingPos and proceeding rightward to include at most Length characters (if Length is omitted, it defaults to "all characters"). For StartingPos, specify 1 to start at the first character, 2 to start at the second, and so on (if StartingPos is beyond String's length, an empty string is returned). If StartingPos is less than 1, it is considered to be an offset from the end of the string. For example, 0 extracts the last character and -1 extracts the two last characters (but if StartingPos tries to go beyond the left end of the string, the extraction starts at the first character). Length is the maximum number of characters to retrieve (fewer than the maximum are retrieved whenever the remaining part of the string is too short). Specify a negative Length to omit that many characters from the end of the returned string (an empty string is returned if all or too many characters are omitted). Related items: RegExMatch(), StringMid, StringLeft/Right, StringTrimLeft/Right.

================================================================


Ruffnekk:
No sarcasm intented. Just saying that when you use...


--- Code: Autohotkey ---mySerial := SubStr("000000" . mySerial, -5)
...you are trying to put a string into an integer variable. Even when using var in languages like C#, the moment you declared mySerial := 1 it is an integer.

Even when AHK would allow this and store the string in mySerial, then the statement mySerial += myFactor would fail or give unexpected results.

4wd:
... in languages like C#, ...-Ruffnekk (June 22, 2012, 01:31 AM)
--- End quote ---

But it's not C# - each language has it's own set of rules and restrictions.

AutoHK allows typeless variables, as does AutoIt and REXX.

Whether or not a variable is reused for a type other than what it started with comes down to readability and if it works.

Why create more variables than you need?

Ruffnekk:
Like I said, I was just trying to give a tip on good practice in coding.

Please explain to me how the code would work correctly, even if variable data types are allowed. What is the outcome of mySerial += myFactor when mySerial is something like "000001" (a string). I would be very surprised if you claimed it would equal 3 (integer).

Anyway, I wasn´t trying to step on any one´s toes here. Keep up the bad practice if you like!  :Thmbsup:

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version