Symbol counter

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Symbol counter

Post by Identis » Tue Jan 17, 2023 10:50 am

Hello,

is it possible to make in dialog window symbol counter? I want to make field where can type max 160 symbols (sms) and counter how many symbols left.

Thanks in advance.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Symbol counter

Post by Dorian (MJT support) » Tue Jan 17, 2023 4:14 pm

I would have thought so, simply by comparing the existence of a symbol in user input to a list of variables. It would get quite complicated if you didn't want to allow duplicates though.

What kind of symbols?
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Symbol counter

Post by Dorian (MJT support) » Tue Jan 17, 2023 4:50 pm

These two articles will help you learn the basics of Dialogs :

Article 1.
Article 2.

Once you've digested those, here's something very basic to get you started, but typing one single character as a proof of concept :

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = 1073
  Top = 214
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 417
  ClientWidth = 1170
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -28
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 240
  TextHeight = 32
  object Label1: TLabel
    Left = 24
    Top = 216
    Width = 114
    Height = 32
    Caption = 'Symbols'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -27
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Label2: TLabel
    Left = 24
    Top = 264
    Width = 120
    Height = 32
    Caption = 'CountLeft'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -27
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Label3: TLabel
    Left = 24
    Top = 88
    Width = 427
    Height = 32
    Caption = 'Type a symbol then click "check"'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -27
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Edit1: TEdit
    Left = 21
    Top = 144
    Width = 242
    Height = 40
    TabOrder = 0
    Text = '@'
  end
  object MSButton1: tMSButton
    Left = 285
    Top = 136
    Width = 150
    Height = 50
    Caption = 'Check'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1


AddDialogHandler>Dialog1,MSButton1,OnClick,DoClick
Let>TheString=!"£$%^&*()_@><;:'
Len>TheString,LenString

SetDialogProperty>Dialog1,Label1,Caption,TheString
SetDialogProperty>Dialog1,Label2,Caption,%LenString% left

Show>Dialog1,res

 
SRT>DoClick
  GetDialogProperty>Dialog1,Edit1,Text,TheTxt
  StringReplace>TheString,TheTxt,,TheString
  SetDialogProperty>Dialog1,Label1,Caption,TheString
  Len>TheString,LenString
  SetDialogProperty>Dialog1,Label2,Caption,%LenString% left
End>DoClick
 

Yes, we have a Custom Scripting Service. Message me or go here

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Symbol counter

Post by Identis » Wed Jan 18, 2023 5:14 am

Dorian (MJT support) wrote:
Tue Jan 17, 2023 4:14 pm
I would have thought so, simply by comparing the existence of a symbol in user input to a list of variables. It would get quite complicated if you didn't want to allow duplicates though.

What kind of symbols?
I didn't mentioned something about dublicates. They can type everything they want.
symbols I can get with Length> ,but I don't know how to show counter and update it on every symbol (numbers, letters and etc.) typed.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Symbol counter

Post by Dorian (MJT support) » Wed Jan 18, 2023 10:02 am

I've adjusted it to allow duplicates, and to continuously watch the input with no button clicks required. For this example I just used abcde... instead of symbols just so it was clearer to see. You'll see at the beginning where I've edited out the symbols line. You should be able to replace that with your list of symbols.

This uses regex to find the match, and then removes the matched characters from the original string. I'm not a regex expert and acquired that from online sources - so if you need to edit the regex to something more impressive (particularly if any of your symbols need to be escaped) I won't be able to help there.

But with regards to the Dialog and it's functionality, I think this does what you're looking for.

Always happy for others here to improve upon my suggestions :

Code: Select all

//Character Match String
Let>TheString=abcdefghijklmnopqrstuvwxyz1234567890
//Let>TheString=!"£$%^&*()_@><;:'
Len>TheString,LenString

Dialog>Dialog1
object Dialog1: TForm
  Left = 1073
  Top = 214
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 417
  ClientWidth = 1170
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -28
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 240
  TextHeight = 32
  object Label1: TLabel
    Left = 24
    Top = 216
    Width = 162
    Height = 46
    Caption = 'Symbols'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -40
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Label2: TLabel
    Left = 24
    Top = 264
    Width = 120
    Height = 32
    Caption = 'CountLeft'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -27
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Label3: TLabel
    Left = 24
    Top = 88
    Width = 484
    Height = 32
    Caption = 'Type your symbols from the list below'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -27
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Edit1: TEdit
    Left = 21
    Top = 144
    Width = 242
    Height = 40
    TabOrder = 0
  end
end
EndDialog>Dialog1


SetDialogProperty>Dialog1,Label1,Caption,TheString
SetDialogProperty>Dialog1,Label2,Caption,%LenString% left

Show>Dialog1

 
label>mainloop
GetDialogProperty>Dialog1,Edit1,Text,TheTxt

regex>[%TheTxt%],TheString,0,matches,nm,0,0,0
if>nm>0
let>adjustloop=0
repeat>adjustloop
  let>adjustloop=adjustloop+1
  StringReplace>TheString,matches_%adjustloop%,,TheString
  Len>TheString,LenString
until>adjustloop,nm
  SetDialogProperty>Dialog1,Label1,Caption,TheString
  SetDialogProperty>Dialog1,Label2,Caption,%LenString% left
endif
goto>mainloop
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts