mIRC Home    About    Download    Register    News    Help

Print Thread
Worder Count script. #118592 26/04/05 10:01 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Hey guys. So I was asked by alhammer to make him a Word Count script that counts his words (On Input) not everyone elses (On Text). And it works pretty good, but I need 3rd party perspective to see how it can be improved (touched up) or possibly shortened. I've just thought of a couple of things, saying how many entries in the dialog, the choice to clear all entries and I forgot to add a On Start event to make the hash table and load in (wordcount.dat) but other than that anything else?

Here's the code:

Code:
dialog wordcount {
  title "Word Count"
  size -1 -1 190 145
  option dbu
  list 1, 8 13 86 117, size
  list 2, 95 13 86 117, size
  text "        Words                                          Number Of Words", 3, 29 3 148 8
  button "Close",4, 7 133 175 10
}

on 1:dialog:wordcount:init:*: {
  var %x = $hget(wordcount,0).item
  while (%x) {
    if ($dialog(wordcount)) {
      did -a wordcount 1 $str($chr(160),20) $hget(wordcount,%x).item
      did -a wordcount 2 $str($chr(160),25) $hget(wordcount,%x).data
    }
    dec %x
  }
}

On *:dialog:wordcount:sclick:4: { dialog -x $dname $dname }

On *:dialog:wordcount:close:0: { hsave -i wordcount wordcount.dat }

On *:input:*: {
  if ($left($1,1) == /) { return $1- }
  else {
    if (!$hget(wordcount)) hmake wordcount 1000
    var %x = $numtok($1-,32)
    while (%x) {
      if ($hget(wordcount,$gettok($1-,%x,32))) { hadd wordcount $gettok($1-,%x,32) $calc($hget(wordcount,$gettok($1-,%x,32)) + 1) }
      if (!$hget(wordcount,$gettok($1-,%x,32))) { hadd wordcount $gettok($1-,%x,32) 1 }
      dec %x
    }
  }
}

alias wordcount {
  if (!$1) && (!$dialog(wordcount)) dialog -dm wordcount wordcount 
  if ($hget(wordcount,$1)) { echo -a * /count: You have said $1 $hget(wordcount,$1) time(s) }
}

Re: Worder Count script. #118593 26/04/05 10:04 PM
Joined: Feb 2005
Posts: 194
A
alhammer Offline
Vogon poet
Offline
Vogon poet
A
Joined: Feb 2005
Posts: 194
grin

[EDIT]
We need a way to scroll both lists at the same time so that they are lined up always. If not, there is no way to tell which word belongs to which number. Any ideas?

Last edited by alhammer; 26/04/05 10:08 PM.

"God sometimes puts us in the dark for us to see the light"
Re: Worder Count script. #118594 26/04/05 10:21 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Code:
On *:dialog:wordcount:sclick:1: { did -c wordcount 2 $did($dname,1).sel }
On *:dialog:wordcount:sclick:2: { did -c wordcount 1 $did($dname,2).sel }


* Clicking an item in the listbox selects it's matching line.

Clicking line 1 of the first listbox selects line 1 of the second listbox. And same if you are clicking in the second.

Re: Worder Count script. #118595 26/04/05 10:23 PM
Joined: Dec 2002
Posts: 1,922
O
Online Offline
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Assuming you create the table on START, the on INPUT event can be reduced to

Code:
On *:input:*:{
  if /* iswm $1 { return }
  hinc wordcount $*
}

Re: Worder Count script. #118596 26/04/05 11:16 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Hehe yeah that seems to work. I added a menu to free the hash table and remove the file (clean slate kinda thing) so I had to add a bit more to your On Input event.

Code:
On *:Start: {
  hmake wordcount 1000
  if ($isfile(wordcount.dat)) hload -o wordcount wordcount.dat 
}

dialog wordcount {
  title "Word Count"
  size -1 -1 190 155
  option dbu
  list 1, 8 13 86 117, size
  list 2, 95 13 86 117, size
  text "        Words                                          Number Of Words", 3, 29 3 148 8
  text "",4, 70 132 100 10
  menu "&File", 7
  menu "&Options",8,7
  item "Remove selected line", 9,8
  item "Remove Hash File",10,8
  item "Clear Dialog Data",11,8
  item break, 12,7
  item "&Close", 13,7
  button "Close",5, 7 140 175 10
}

on 1:dialog:wordcount:menu:9: { 
  if ($did($dname,1).sel) { 
    did -d wordcount 1 $did($dname,1).sel 
    did -d wordcount 2 $did($dname,2).sel 
  }
}

on 1:dialog:wordcount:menu:10: { 
  if ($isfile(wordcount.dat)) { 
    echo -a *** Word count set to 0 
    hfree wordcount 
    .remove wordcount.hsh
    dialog -x wordcount wordcount 
  }
}

on 1:dialog:wordcount:menu:11: { did -r wordcount 1,2 }

on 1:dialog:wordcount:init:*: {
  var %x = $hget(wordcount,0).item
  did -a wordcount 4 $ctr(160),100) Number of words: %x
  while (%x) {
    if ($dialog(wordcount)) {
      did -a wordcount 1 $str($chr(160),20) $hget(wordcount,%x).item
      did -a wordcount 2 $str($chr(160),25) $hget(wordcount,%x).data
    }
    dec %x
  }
}

On *:dialog:wordcount:sclick:1: { did -c wordcount 2 $did($dname,1).sel }
On *:dialog:wordcount:sclick:2: { did -c wordcount 1 $did($dname,2).sel }

On *:dialog:wordcount:close:0: { hsave -o wordcount wordcount.dat }

On *:dialog:wordcount:sclick:5: { dialog -x $dname $dname }


On *:input:*:{
  if (/* iswm $1) { return $1- }
[color:red]  if (!$hget(wordcount)) { hmake wordcount 1000 }[/color]
  hinc wordcount $*
}

alias wordcount {
  if (!$1) && (!$dialog(wordcount)) dialog -dm wordcount wordcount 
  if ($hget(wordcount,$1)) {  echo -a * /count: You have said $1 $hget(wordcount,$1) time(s) }
}



Cheers mate, you've been a great help. smile

Re: Worder Count script. #118597 26/04/05 11:47 PM
Joined: Feb 2005
Posts: 194
A
alhammer Offline
Vogon poet
Offline
Vogon poet
A
Joined: Feb 2005
Posts: 194
Thanks Andy! By the way, i'm trying to improve the dialog a little by using MDX.dll's ListView. How do I make a list have 2 colums? Also, how do i specify which column to add text to?

EDIT
Nevermind. I searched the foums for a while and eventually found my answer. : cool


"God sometimes puts us in the dark for us to see the light"
Re: Worder Count script. #118598 27/04/05 04:10 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Hey dude, I've been working on that ListView for you and eventually came up with this.



The message sequences I used for the above was...

[*]Testing...
[*]Testing again...
[*]Testing one more time..

Code:

Code:
On *:Start: {
  hmake wordcount 1000
  if ($isfile(wordcount.hsh)) hload -o wordcount wordcount.hsh 
}

alias -l dmdx return $findfile($mircdir,dialog.mdx,1)    
alias -l vmdx return $findfile($mircdir,views.mdx,1) 
alias -l bmdx return $findfile($mircdir,bars.mdx,1) 
alias -l gmdx return $findfile($mircdir,ctl_gen.mdx,1)
alias -l udll return $findfile($mircdir,mdx.dll,1)

alias -l mdx {
  if  ($isid)  dll $udll $1-
  elseif ( $2- == $null ) return $dll($udll,$1,.)
  return $dll($udll,$1,$2-)
}

dialog wordcount {
  title "Word Count"
  size -1 -1 214 107
  option dbu
  list 1,3 3 206 88,size
  button "OK", 2, 89 94 36 10, ok
  text "",3, 5 96 60 10
  menu "&File", 4
  menu "&Options",5,4
  item "Remove selected line", 6,5
  item "Remove Hash File",7,5
  item "Clear Dialog Data",8,5
  item "Save without closing",11,5
  item break, 9,4
  item "&Close", 10,4
}

on 1:dialog:wordcount:menu:6: { 
  if ($did($dname,1).sel) did -d wordcount 1 $did($dname,1).sel
}

on 1:dialog:wordcount:menu:7: {
  var %aysywtp = $input(Are you sure you want to proceed $+ $chr(44) $+ $crlf $+ and start your count from scratch?,wd,Caution data will be lost!)
  if (%aysywtp == $true) { 
    echo -a *** Word count set to 0.
    if ($hget(wordcount)) hfree wordcount 
    if ($isfile(wordcount.hsh))  .remove wordcount.hsh
    dialog -x wordcount wordcount 
  }
}

on 1:dialog:wordcount:menu:8: { did -r wordcount 1 }

on 1:dialog:wordcount:menu:10: { dialog -x $dname $dname }

on *:dialog:wordcount:menu:11: { hsave -o wordcount wordcount.hsh }

on *:dialog:wordcount:close:0: { hsave -o wordcount wordcount.hsh }

on *:dialog:wordcount:init:0: {
  mdx SetMircVersion $version 
  mdx MarkDialog $dname
  mdx SetControlMDX $dname 1 Listview  grid report > $vmdx
  did -i $dname 1 1 headerdims 290 100
  did -i $dname 1 1 headertext Word List $chr(9) Number of words
  did -a $dname 3 Number of words: $hget(wordcount,0).item 
  var %x = $hget(wordcount,0).item
  while (%x) {
    did -a $dname 1 1 0  $hget(wordcount,%x).item $+ $chr(9) $+ + 0 0 0 $str($chr(160),13) $hget(wordcount,%x).data
    dec %x
  }
}

on *:dialog:wordcount:dclick:1:{
  echo -a Word: $gettok($gettok($gettok($gettok($did($dname,$did,$did($dname,$did).sel),2-,32),1,9),2-,32),4,32)
  echo -a Word number: $calc($did($dname,$did).sel - 1)
}

On *:input:*:{
  if (/* iswm $1) { return $1- }
  if (!$hget(wordcount)) { hmake wordcount 1000 }
  hinc wordcount $*
}

alias wordcount {
  if (!$1) && (!$dialog(wordcount)) dialog -dm wordcount wordcount 
  if ($hget(wordcount,$1)) {  echo -a * /count: You have said $1 $hget(wordcount,$1) time(s) }
}

Re: Worder Count script. #118599 27/04/05 12:40 PM
Joined: Feb 2005
Posts: 194
A
alhammer Offline
Vogon poet
Offline
Vogon poet
A
Joined: Feb 2005
Posts: 194
shocked I was working on one myself and had just finished when I saw your post. hehehe. Normally, I would have asked for how to do listview in the first place, but for some reason, I had an unusual determination to figure this out myself. shocked Mine works exactly like yours, just the dialog is a slightly different size. However, I think i'll change my size to be more liek yours, I like it wider. Thanks dude! cool



"God sometimes puts us in the dark for us to see the light"