15,997,860 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by jsc42 (Top 41 by date)
jsc42
29-Mar-23 6:34am
View
OP says Oracle, not SQL SERVER; Oracle does not have a DATEADD function. https://stackoverflow.com/questions/4957224/getting-last-day-of-previous-month-in-oracle-function says use LAST_DAY(ADD_MONTHS(sysdate, -1))
jsc42
23-Mar-23 6:04am
View
I am guessing that your problem may be with the lines 'if (ItemsDataGridView.Rows.Count % 2 == 1) { pdfTable.AddCell(" "); }' which only add a cell if there are an odd number of rows. I suspect that you are looking for more than 2 rows e.g. 'if (ItemsDataGridView.Rows.Count > 2) { /* etc */}'. But, as I do not know anything about the PdfTable object, I could be completely wrong.
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
jsc42
3-Sep-21 6:13am
View
Thanks!
jsc42
2-Sep-21 12:58pm
View
I'm not a Python expert but ...
Doesn't d.remove(a) remove the item in position 'a', not the item with value 'a'?
So, if you have [4, 3, 1, 3, 4]
First Iteration: a = 4 (max n); d.index(a) == 0 and d.index(a) also == len(d) - 1; so you do d.remove(a) meaning remove item 4 which (using zero based subscripts) just coincidentally is one of the items that has a value of 4.
Second Iteration: a = 4 (because there were 2 '4's in the original list); d.index(a) == 0 but not == len(d) - 1; d.remove(a) once again tried to remove item 4, but your list now only has indicies 0 to 3 so the remove will fail.
If I understand the task, then I think the simplest way to implement want you need is to split the tests for d.index(a) into two 'if' branches and when one is true, remove it using the found index (which will be 0 or len(d) - 1)
jsc42
7-Jul-21 12:14pm
View
This is definitely true for HyperText Markup Applications and used to be true for embedded web in forms, but I do not know if it is still true for Windows forms ...
Web browsers in forms run using an old HTML DLL which equates to MS-IE7 (HTML3 + CSS2 + JavaScript1.3).
jsc42
29-Jun-21 12:40pm
View
What do you mean by 'partial word'? Do you, for example, mean that if a user enter a search word of 'leapfrog', you would match 'leap' or 'frog'; or do you mean that the search word just has to appear in the text being searched?
jsc42
28-May-21 17:43pm
View
What is the value in RecordID when the query is created? What creates it / updates it?
Have you tried stepping through the code and looking at the contents of the variables?
jsc42
31-Mar-21 16:57pm
View
Your code is incomplete. You need to add
ENVIRONMENT DIVISION.
* add your environment here
One of the few things I remember from doing COBOL is that the order of the divisions is I(dentification) E(nvironment) D(ata) P(rocessing) which creates the mnemonic i.e. DP, said as "That is Data Processing"
jsc42
18-Mar-21 13:06pm
View
Should 'f(i, ref j);' be 'f(i, out j);'?
jsc42
11-Mar-21 5:16am
View
Are you trying to create a string with "&Hxx" texts in it, as per your description; or an array of bytes as per your sample code?
If it is the string, then you can do a simple text conversion e.g. Dim byteString As String = "&H" & inputString.Replace("-", ", &H")
If it is the array of bytes, then I'll let someone else reply as the technique is slightly harder and will need something in a 'Solution' section rather that a 'Comment' section.
jsc42
1-Feb-21 15:18pm
View
I have not looked at how you are following the nodes, but there is a problem with your RegEx expressions.
1) You are enclosing your URLs in '[' and ']'. Those delimiters mean 'match any character in the list' s, for example, [www.digikala.com/camera] would match a single character the is any of w, d, i, g, k, a, l, ., c, o, m, /, or r (I've dropped duplicated characters). To match the URL as a string, drop the '[' and ']'. You can keep the '(' and ')' if you want to use subgroups.
2) As you are not using '^' and '$' to anchor at the start and end of the texts, some of the tests will not givemn what you expect e.g. your regex9 will catch anything that also matches regex10 through to regex15 as it contains a subset of all of them.
Also, your 'if' statements are wrong. 'if (res1=true)' will assign the value true to res1 and then the 'if' will see if res1 is true. Ir will always be true as you have just assigned it the value of true. To compare, use '==' e.g. 'if (res1==true)', but since 'if' is comparing the expression for truth anyway, all that you will really need is 'if (res1)'. Ditto for all of the other 'if (resn=true)' when n = 2 to 14.
jsc42
6-Jan-21 10:15am
View
Try changing your
File.WriteAllText(Path.Combine("Results" + myDate, "Bad.txt"), "listBox1.Text");
to
File.WriteAllText(Path.Combine("Results" + myDate, "Bad.txt"), listBox1.Text);
i.e. getting the text from lstBox1 rather than writing the literal string "listBox1.Text"
jsc42
3-Dec-20 9:33am
View
I'd be very wary of hooking into standard DLLs. You cannot know how it might affect other applications and there may be issues if the DLL changes. My only thought re Chrome / Edge etc is that most browsers have a print option to not print the background of a web page. Is it possible that some of the call(s) that you are intercepting to create your watermark are for generating the web page backgrounds that the browser option is then discarding?
jsc42
26-Nov-20 13:12pm
View
I cannot answer your question, but there is redundant code in your sample. The 'if (Request.IsAuthenticated && empId != null && Id != null)' leads into a block that includes 'if (Id == null)'. If it gets to the 2nd 'if', then the 2nd 'if' then Id must not be null, so the 2nd 'if' is always false.
jsc42
16-Jun-20 4:26am
View
You cannot enter an infinite number of numbers - it would take the whole of eternity to do it. Do you mean that you can type more numbers than you want? Does it find the solution for every number that you type or just the first one that you are searching for? My guess is that it will only search for the first one and the rest will be ignored. This is because you are just filling in data into a scan buffer and your program is consuming data from the scan buffer. Data not relevant to the program (e.g. your infinite set of numbers) just sit there waiting in the buffer in case any code wants to scan them. However, if you are entering multiple numbers and each is being searched in turn, please verify that the code that you have posted is what you are running and that there isn't another loop somewhere that is picking up the other numbers.
jsc42
18-May-20 12:40pm
View
As is, the query would find rows where column 'column' does not have any letters in the range A to Z. I guess the OP is looking for rows where column 'column' only contains the letters A through Z, which is a lot trickier. Even if the correct LIKE is used, it wouldn't eliminate anything, it just wouldn't select specific rows to be returned in the query
jsc42
4-Jan-20 12:33pm
View
Also check the size of the field in the database that the data is being saved into. A large image will need a large amount of storage and (as has already been mentioned) converting to Base64 inflates the size by 1/3. If the resultant size is bigger than the max size that the field can hold then the database update will fail.500Kb will need a field that can hold 682668 bytes.
jsc42
28-Oct-19 7:35am
View
I've learnt something new today, having looked at your SQL. I did not know that the ELSE clause in a CASE was optional. I've looked it up and the docs say it defaults to ELSE NULL. I think that I'll still always put an explicit ELSE in my code just to confirm that I've at least considered the possibility; but that is the exciting thing about reading other people's code - there is always new things to discover or new ways of doing old things.
jsc42
28-Feb-19 6:28am
View
You say "in the designer radiobutton is empty". This is to be expected. The Form Designer shows the design of the form, not what happens at runtime.
jsc42
15-Jan-19 4:17am
View
Even if you can connect, you must be aware that there are many SQL Dialects and versions; so you would have to code variants for different systems.
jsc42
2-Jan-19 16:56pm
View
Capture the actual error code from the 'write' and include it in your error message. Then look up the code - that should give you a clue as to what the error is.
e.g.
int errcode;
if ((errcode = write(sockfd, sendline, strlen(sendline) + 1)) < 0)
printf("The write function returned %d\n", errcode);
Also, I suspect that you might need an '&' before the recvline argument in the read function (happy to be corrected if I am wrong).
jsc42
28-Nov-18 3:43am
View
Look closely at your transliteration, you've missed something (clue: it is in the 'while' clause).
jsc42
15-Nov-18 5:31am
View
Multi-threading is the correct way to go, but as a quick hack you can (often, but not always) get away with Application.DoEvents. If you do go down this slightly risky route, disable the Save button when pressed and reenable it when saving is completed; otherwise impatient users will keep pressing it.
jsc42
8-Nov-18 16:56pm
View
The PNG has a formula like
sum = x + (x^2)/2! + (x^3)/3! + . . . + (x^N)/N!
(where I am using ^ as the exponentiation operator)
You need to understand the ! (factorial) operator and the fact that this is an infinite sequence (the N represents a sufficiently large number). Any reasonable Computer Science text book will tell you how to handle infinite sequences. Hint: Do not blithely get the terms and add them; you will need to think about the pattern between the adjacent terms. If you think about what the parts in the terms are doing, you will see why.
jsc42
26-Oct-18 5:21am
View
I think that the OP knows what is the problem with the code. His / her qn was how solutions to the problem submitted by examinees can be tested safely.
jsc42
25-Oct-18 3:56am
View
This is known as a Pivot Table. Google it - there are a lot of possible solutions for SQLServer as that does not support them out of the box. However, the solutions are not easy.
jsc42
25-Oct-18 3:52am
View
I am not sure what you are trying to achieve. Are you trying to truncate numbers at 4 dec places or to display them with 4 dec places. Please tell us the expected output and the actual output.
I have tried your code in SQLServer and your 2nd col produces zeros for all values except for 18.26 which gives 2.91038304567337E-11 which is almost zero - this will be a rounding error. Float will always give inexact values as the binary value is only an approximation of the decimal value which is something you must be aware of when working with float values (in any language, not just SQL). All of the values will have rounding errors but some will be too small to display so they are shown as 0.
jsc42
10-Oct-18 8:06am
View
As @CHill60 says, What error?
There are a million and one possible error each with different causes.
My wide guess is that you have fields EMP_NO and / or group_name present in multiple tables so Oracle doesn't know which one to use. Try using qualified names, e.g. em.EMP_NO and gi.group_name (if they are in emp_master and groupinfo respectively, otherwise adjust as required).
Or is EMP_NO numeric? In which case you may need to cast / convert to text if gi.group_members and v.DIR_EMP_NO are texts; otherwise if they are all numbers, convert the concatenated string expressions to arithmetic expressions (exact formula depends on whether EMP_NO has a constant no of digits excluding leading zeros or not).
In summary ... please supply more information as we cannot guess exactly what you arte trying to do.
I'll leave it to someone else to comment on using expressions rather than simple column names in join clauses.
jsc42
10-Oct-18 7:53am
View
How are you invoking the page? If you have it locally and are double-clicking its filename from Windows Explorer or right-clicking and using 'Run Using ...', it will load with a 'file:' protocol. This does not seem to be honoured in Edge but is honoured in Chrome. I do not know if it works in IE11 - it used to work in earlier versions of IE. If you are running it through a web server, then I cannot help.
jsc42
6-Oct-18 11:52am
View
If you are only concerned about the first two chars, why are you comparing the whole strings? Wouldn't it be easier just to check the first 2 chars if that is all you want, e.g. if (temp1[0] == str[0] && temp1[1] == str[1]) printf("same\n"); else printf("different\n"); ?
jsc42
12-Sep-18 8:40am
View
Minor Typo: in the list of 2 digit combinations, the values should be
12, 21, 15, 55, 59, 98
jsc42
16-Aug-18 7:39am
View
@OriginalGriff's solution checks the whole field in one go, so change the #().keypress to #().change (I'm not a jQuery expert) and test the field value rather than the event keystroke.
jsc42
24-Jul-18 8:16am
View
Why are you manually counting no of rows returned? You don't use the fields, so it would be better to do
SELECT COUNT(*) AS nRecs FROM prrr1 WHERE username = @Username AND pic = @Image
(this is assuming you use Nathan Minier's advice to parameterise your expression) and then just get the count directly
jsc42
7-Feb-12 10:04am
View
Deleted
My trusty "JavaScript - The Definitive Guide" (1998 - 3rd Edition) agrees with your basic premis that '.' is "Any character except newline, equivalent to [^\n]". So, [.\n] is adequate; you are correct in omitting the '|' - that was my bad! I suppose that [.\s] would be belt-and-braces just in case you were generating text on a Windows system and processing it on a Unix system and that the RegExp coders had forgotten that Windows uses \r\n instead of \n.
jsc42
3-Jan-12 7:11am
View
Deleted
For ordering ascending, try changing
AND cte.[Rank] < cte.[Count]
to
AND cte.[Rank] > cte.[Count]
or try changing
, Models + N' , ' + Model
to
, Model + N' , ' + Models
I don't have SQL Server, so I cannot test either of these two possible solutions. I would be interested to know if either / both work.
jsc42
25-May-11 12:56pm
View
Many style gurus suggest comparing strings against variables, instead of comparing variables against strings just so that compilers would catch the mistaken use of '=' instead of '=='. Viz:
if ("Manager" == UsernameTextBox.Text && "Maintenance" == PasswordTextBox.Text)
which is valid whereas
if ("Manager" = UsernameTextBox.Text && "Maintenance" = PasswordTextBox.Text)
is invalid.
Personnaly, I think it looks clunky and awkward. Anyone who uses that construct is already aware of the issue of confusing '==' and '=', and hence probably does not need this backward construct. Conversely, people who are likely to fall foul of '=' instead of '==' are unlikely to be ones who would use the backwards construct. But I am sure there must be a set of people somewhere that would benefit fropm this backwards construct.
Show More