mIRC Home    About    Download    Register    News    Help

Print Thread
#267022 23/03/20 09:56 PM
Joined: Dec 2019
Posts: 45
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 45
or its me

small script to count the number of comma's in a string,

dialog buttons {
title "buttons"
size 880 100 400 150
button "text", 1, 150 10 60 30, ok
edit "", 2, 150 50 200 50, multi rich
edit "result", 3, 150 110 100 30
}

on 1:dialog:buttons:sclick:2:did -ra buttons 3 $count($did(2),$chr(44))

the text entered into dialog ID 2, will be something like " name1, name 2, name 3, name 4, name 5, name 6, name 7", up to name 15, 20, poss more

this will be copied from a web page, and will span multiple lines, so using multi and rich - this is the problem with the on dialog

the problem is (and I have only solved it with a bodge so far of making ID2 edit box very wide), is that $did(2) only appears to operate on the first line of ID2.

when $did(2) acts on $did(name1, name2, name3, name4 string), if ID2 has multiple lines, $did(2) only acts on the first line

am I missing a -switch for " /did -ra buttons $count " ?

quartz #267023 23/03/20 10:43 PM
Joined: Jul 2014
Posts: 308
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jul 2014
Posts: 308
Hi quartz,

Try it this way:
Code
edit "", 2, 150 50 200 80, read multi return


TECO
irc.PTirc.org (Co-Admin)
TECO #267025 24/03/20 06:48 PM
Joined: Dec 2019
Posts: 45
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 45
hi thanks, unfortunately doesn't work

[I believe] it needs the rich because it's pasted from a web page, read means I can't paste the text into the box? return I am not sure what that switch does

quartz #267027 24/03/20 07:28 PM
Joined: Jul 2014
Posts: 34
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Jul 2014
Posts: 34
The sclick event only applies to button, check, radio, list, and combo controls. Therefore, you will never see results of $count. You might want to use edit event or add another button and apply the sclick event to it.

quartz #267028 24/03/20 08:08 PM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
That's normal.

If you want to access all the lines in the editbox, you can use $did(dname,id,N) to access the Nth line (you could make a loop to get them all), you can also use $didtok to get all the lines separated by a given character.

However, it seems like your typical usage is to open your dialog and paste the content of your clipboard into the editbox.

First, you could handle the clipboard when you open your dialog with the 'init' event and with $cb: https://en.wikichip.org/wiki/mirc/identifiers/$cb
That way you wouldn't even have to paste.

But I suggest you look at pre-made dialog that are available with $input and the like, for example you can use something as simple as //echo $count($?,$chr(44)) and paste the clipboard there, no need for a custom dialog really.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
quartz #267029 24/03/20 10:32 PM
Joined: Jul 2014
Posts: 308
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jul 2014
Posts: 308
Originally Posted by quartz
hi thanks, unfortunately doesn't work

[I believe] it needs the rich because it's pasted from a web page, read means I can't paste the text into the box? return I am not sure what that switch does

It's all right.
So there is only one way for us to help you. You have to show us the source code of how the information reaches the dialogue so that we can analyze and explain to us what the final result is that you want.

If it is not too complex I think it will be possible to make the code for you.


TECO
irc.PTirc.org (Co-Admin)
Wims #267031 25/03/20 12:56 AM
Joined: Dec 2019
Posts: 45
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 45
thanks syk/wims

$count does work, it just only [apparently] works on the first line of the multi edit box

yep I could use a loop for the N.....lol

I don't actually want it to work instantly - the dialog actually has a couple of other buttons that I didnt include in the above, so I want to generate the result using a button click. actually initially I was wondering if mIRC had the option of user-added buttons. then I thought "dialog"

-- edit, ah, you're saying that it can count as soon as text is pasted in, rather than the button click
yep, on 1:dialog:buttons:edit:2:did -ra buttons 3 $count($replace($didtok(buttons,2), $chr(44) $chr(44) , $chr(44)),$chr(44)) | did -r buttons 2

did it



yeah previously I was doing /num name1,name2,name3, where /num counted comma's, I wanted to replace '/num' with a button click. less presses. smile

I've actually found a semi official bodge, which fixes the bodge

using $didtok you suggested and $replace($didtok(buttons,4), $chr(44) $chr(44) , $chr(44))

$didtok does return all of the edit box contents, but each line is seperated by "," so I end up with " name1, name2, name3, ,name4, name5, name6, ,name7 "

so I replace ", ," with "," and I get a proper result back

might review the $input method


Last edited by quartz; 25/03/20 01:12 AM.
quartz #267034 25/03/20 10:19 AM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Quote
$count does work, it just only [apparently] works on the first line of the multi edit box
No, $count works on any string you pass it, it's $did() that is only returning the first line, so you're passing only one line to $count, it's not $count that is ditching away the rest.

And no, I was saying you could use on *:dialog:buttons:init:0: to automatically add the clipboard to the editbox, that way you only have to click a button.

You can choose the character separating the lines in $didtok, you don't have to use a comma.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #267036 25/03/20 12:06 PM
Joined: Dec 2019
Posts: 45
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 45
Originally Posted by Wims
Quote
$count does work, it just only [apparently] works on the first line of the multi edit box
No, $count works on any string you pass it, it's $did() that is only returning the first line, so you're passing only one line to $count, it's not $count that is ditching away the rest.


ah..yeah..that was basically what I meant. $did was only returning the first line, $count was operating on that line

vague suggestion but would " $did(4,1-5) " be worth supporting? that returns lines 1 to 5, of ID4 in the dialog box. at the moment 1-5 needs the loop
so apparently $didtok does operate on the entire edit box contents, but $did only works on the first line (or specified line),,unless that could be intentional

Quote
And no, I was saying you could use on *:dialog:buttons:init:0: to automatically add the clipboard to the editbox, that way you only have to click a button.


yeah I'll be having the dialog box hopefully open most of the time because there are other buttons I'll use regularly

as it is using the line below, I just have to have the dialog open, all I need to do is ctrl-v - thats good enough smile

Quote
You can choose the character separating the lines in $didtok, you don't have to use a comma.


on 1:dialog:buttons:edit:2:did -ra buttons 3 $count($didtok(buttons,2,32), $chr(44)) | did -r buttons 2

works even better smile

Teco thanx, it's actually copying and pasting the list of names that are logged into a forum message board, vbulletin software

Last edited by quartz; 25/03/20 12:12 PM.

Link Copied to Clipboard