Simon Tite 15 Light Poster

You're quite right, Simon: your single line

var len = fn.value.length + fn.value.match(/\//g).length;

does precisely what my awkward two lines did.

While this counts perfectly once a '/' enters the textbox, it unfortunately does no counting till it sees one.

Since the original line

var len = fn.value.length;

by itself counts perfectly when the box has no '/' (i.e. it doesn't know to double for the forward slash), it makes me wonder if an if - else statement might work? Something (that I am clueless how to properly write) sort of like this:

var str= value  // This needs to be whatever's in the text box
var pos=str.IndexOf("\/")
if (pos>=0)
{
var len = fn.value.length + fn.value.match(/\//g).length;
} 
else 
{
var len = fn.value.length
}

Could something like this possibly work? If so, my problem is to get it to read whatever is entered in the box into str. Users will often enter text that has no URL or, most often, a URL at the very end, so they'll want the counter to be keeping a tally from the start even if it doesn't see a slash.

Ok, this looks like it might be that the match(...) actually returns a null value if no match is found, and the length of a null is probably a null, and adding a null to the original length might give a null or zero, which could explain the problem.

So, your latest approach looks promising, however the slash in the IndexOf shouldn't need escaping, …

Simon Tite 15 Light Poster

Just seen the latest version of your script -

// fieldname, warningname, remainingname, maxchars
function CheckFieldLength(fn,wn,rn,mc) {
 var len = fn.value.length;
 var len = len + fn.value.match(/\//g).length;


  if (len > mc) {
    fn.value = fn.value;
    len = len;
  }
  document.getElementById(wn).innerHTML = len;
  document.getElementById(rn).innerHTML = mc - len;

I don' quite know what the if clause in the middle is doing (nothing?), and I don't know whether re-declaring "var len" twice might be causing a problem, but maybe the script should be simplified to

// fieldname, warningname, remainingname, maxchars
function CheckFieldLength(fn,wn,rn,mc) {

 var len = fn.value.length + fn.value.match(/\//g).length;

  document.getElementById(wn).innerHTML = len;
  document.getElementById(rn).innerHTML = mc - len;
}
Simon Tite 15 Light Poster

You've not just mis-read it have you?

If F is a forward slash, and B is a backward slash, then the line is: len = len + fn.value.match(FBFFg).length; I tested this out by hacking a W3Schools example, which you can find at http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_match_regexp

Just go there, change the lines

var patt1=/ain/gi;
document.write(str.match(patt1));

to

var patt1=/\//g;
document.write(str.match(patt1).length);

..then the example should count the number of slashes in the text line above.

If the example works, and your changed code doesn't, then I'm stuck too. Maybe it's something to do with some other part of the software changing the slash, perhaps also escaping it with a backslash before your subroutine sees it. Maybe, that would explain why a slash counts as two characters?

Guessing wildly here, perhaps if you tried counting occurences of \/ , or using the F B notation as above, for easier reading, try: len = len + fn.value.match(FBBBFFg).length that is F for the regexp opening delimiter, BB for an escaped backslash, BF for an escaped forward slash, F for the regexp closing delimiter, g for global search of the whole string.

Don't you just hate regular expressions?

Simon Tite 15 Light Poster

This is the section of JS code which returns the count:

// fieldname, warningname, remainingname, maxchars
function CheckFieldLength(fn,wn,rn,mc) {
  var len = fn.value.length;
  if (len > mc) {
    fn.value = fn.value;
    len = len;
  }
  document.getElementById(wn).innerHTML = len;
  document.getElementById(rn).innerHTML = mc - len;
}

Here is some code which should add 1 to the length of text for every "/" character found, that is each / character will then be counted twice.

// fieldname, warningname, remainingname, maxchars
function CheckFieldLength(fn,wn,rn,mc) {
  var len = fn.value.length;
////////// Add this line ////////////
  len = len + fn.value.match(/\//g).length;
/////////////////////////////////////
 if (len > mc) {
    fn.value = fn.value;
    len = len;
  }
  document.getElementById(wn).innerHTML = len;
  document.getElementById(rn).innerHTML = mc - len;
}

The code is in the file http://faculty.kutztown.edu/rjensen/js/charCount.js.

Simon Tite 15 Light Poster

This should work (I haven't actually tried it yet though)

SELECT file_id, 
	sum(if (status = 0,1,0)) sum0,
	sum(if (status = 1,1,0)) sum1,
	sum(if (status = 2,1,0)) sum2,	
FROM pl_statements
GROUP BY file_id

You don't say which database you are using, the example above should work in MySql, but IF statements are not very standardized between databases. (One other, maybe Oracle or maybe Access, maybe uses IIF instead)

diafol commented: Big hand! Thanks +5
Simon Tite 15 Light Poster
$arr = array_fill_keys(range(1,4), "rambow");
$arr[3] = "popcorn";
Simon Tite 15 Light Poster

Now, I'm not sure how to answer your question about the SQL engine. I'm using VB6 with Access97 database if that helps.

That's the answer!

Now it's quite a few years since I used the Access database, but I seem to remember that perhaps it doesn't like doing ORDER BY after GROUP BY. The specification of the SQL language used to be simply: SELECT ... FROM ... ORDER BY ... GROUP BY ... HAVING ... - and this means that you will have to use a subquery to get the results you want.

Firstly, maybe you should get the VB6 crap out of the way and just type your queries direct into the Access application. Anyway, that's up to you, but I'll just give you my suggestions as straight SQL statements to save typing all those quotes and underscord!

If you can get to a working query which outputs the correct results, but not sorted by the total points, this is a good starting point. I guess it should look something like this:

SELECT pt.PoolTeamID AS teamid, pt.TeamName AS teamname, Sum(ps.Points) as pts
FROM PlayerStats ps, PoolTeams pt
WHERE ps.Weeknumber = 10
AND ps.Status = 'True'
AND ps.PoolTeamID = pt.PoolTeamID
ORDER BY pt.PoolTeamId, pt.TeamName
GROUP BY pt.PoolTeamId, pt.TeamName

This should give you one line per teamid, with the correct total points for that team. The ORDER BY is required here, because the GROUP BY subtotalling works on change of …

navaidstech commented: Excellent suggestion solved my dilemma +1
Simon Tite 15 Light Poster

You don't say which programming language you are using to compose your sql statement, but as a first shot I would suggest you program something like this:-

If the search term contains one word:

SELECT * FROM descriptions
WHERE desc LIKE '%firstword%'

If the search term contains two words:

SELECT * FROM descriptions
WHERE desc LIKE '%firstword%'
AND desc LIKE '%secondword%'

and so on, one extra AND clause for each word.

However, (although I've never tried this), there are features in mySql that allow you to create indexes on tables which support "natural language searching", so if you want a more sophisticated search ability check out this part of the mySql manual:

http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html

---
Sorry, posted this before I saw Darkagn's reply!

darkagn commented: Excellent suggestion and citation. Polite and helpful answer to the OP's question. +3
Simon Tite 15 Light Poster

How about having to use punch cards to do programming? Our CS teacher reminded us that when he was working on the ARPANET, they did not have compilers with syntax check and auto completion which I think creates a lazy programmer.

Yeah, in CS we had to write the programs out by hand, on paper with a little box for each character, then post this into a pigeon hole. Next working day (D+1) (if you were lucky) you'd get back a stack of punched cards, and a printout of their contents, for checking. After correcting the errors (with a red biro) , you'd get the corrected cards back the next day (D+2), hopefully without errors, and hand them back for processing. The next day (D+3/4), you'd get the results, which would normally be syntax errors or typos you'd missed. Red biro, da de dah, D+4 the results of the compiled program. Basically, one working week to enter, compile and run a 200 line program. And another week to fix the logical errors.

But we wuz grateful for it, guv!

Ancient Dragon commented: You made me glad to not have been programming then :) +0
Simon Tite 15 Light Poster

You could just use grep without the find. Use grep -l -r -i

That's quite true, there are many ways to skin a cat!

Personally, though, I usually use find in cases like this, because of its greater flexibility in selecting files - such as by date accessed, date last updated, stay within the current volume, only recurse 2 levels deep, only give me files I have permission to write to, etc.

You pays your money and you gets your choice, as they say.

sknake commented: :) +6
Simon Tite 15 Light Poster

...when you remember bootstrapping the computer by its front panel switches, installing operating system patches with an octal editor, and writing programs on a teletype (thats like a big typewriter with fanfold paper instead of a screen, for you youngsters). Oh, and using telex to supply patches (sometimes even small programs) to clients (beats dictating over the telephone, although the character set was limited, you had to spell out some of the punctuation marks).

Sigh! Those were the days my friends!

Simon Tite 15 Light Poster

Francis, Read these notes, it may solve your problem:
http://ubuntuforums.org/showthread.php?t=1321107&highlight=wubi

Note that grub thinks you are using a US-ASCII QWERTY standard keyboard, so if you don't use that in your country, then you might want to print a keyboard map (it's tricky for me, using a Belgian AZERTY keyboard, particularly the parentheses and the comma, which are in different positions).

Also note that when the notes say (hdX,Y) , what they mean is you need to find out your disk drive number (X, starts at 0) and the partition number on that disk (Y, also starts at 0). Luckily, grub supports a kind of auto-complete feature: if you press <tab> after a partial command it will give you a list of possible alternatives. So, typing ls (hd<tab> will give you a list of available disks (you probably only have one, in which case you want hd0), and typing ls hd0,<tab> will give you a list of partitions on hd0. Reading the notes, it seems that you will probably want to use (hd0,1) - but if you are not sure, you can try all the possibilities, it won't hurt if you get it wrong.

Similarly, when selecting the kernel to boot, the notes say linux /boot/vmlinuzxxxxxxxxx ...... , don't enter xxxxxxx, use tab to find the list of files starting with vmlinuz, and pick the one with the highest version number.

Hope this helps, let me know if you still have a problem....

francisgan9 commented: trying his best +0