This is my first attempt of contributing to the community so please beer (intentionally) with me. I have made this example to show how it's possible to use text fields to have queues and stacks of files counted on the fly. The first snippet of code is the main code that monitor the folders. The second snippet is a script to fire txt-files into those monitored folders. Please remember to save the script before trying to test it (or else the script dir will not point in any direction).
I'm a noob so my code is not that well managed I think. I've only done this for 4 weeks...
Please rip my code apart and give me feedback.
Thanks!
MAIN CODE
Code: Select all
//Paths
Let>path_blue=%SCRIPT_DIR%\Blue
Let>path_red=%SCRIPT_DIR%\Red
Let>path_yellow=%SCRIPT_DIR%\Yellow
//Max level meter
Let>max_blue=10
Let>max_red=10
Let>max_yellow=10
//Time in seconds
Let>time_check=5
Let>time_popup=5
//Colors
RGB>45,66,117,Blue
RGB>183,190,223,BlueLight
RGB>95,95,95,GreyDark
RGB>210,210,210,GreyLight
RGB>150,0,50,Red
RGB>255,215,0,Yellow
RGB>140,230,180,Green
RGB>220,190,230,Purple
RGB>0,0,0,FontBlack
RGB>255,255,255,FontWhite
Dialog>Monitor
object Monitor: TForm
Left = 255
Top = 104
HelpContext = 5000
BorderIcons = [biSystemMenu]
BorderStyle = bsToolWindow
Caption = 'Monitor'
ClientHeight = 177
ClientWidth = 131
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object Label3: TLabel
Left = 12
Top = 7
Width = 27
Height = 102
AutoSize = False
Color = clGray
ParentColor = False
Transparent = False
end
object Background_Blue: TLabel
Left = 13
Top = 8
Width = 25
Height = 100
Hint = 'Blue category'
AutoSize = False
Color = 7684653
ParentColor = False
Transparent = False
end
object Height_Blue: TLabel
Left = 13
Top = 8
Width = 25
Height = 90
Hint = 'Blue category'
AutoSize = False
Color = clWhite
ParentColor = False
Transparent = False
end
object Label_Blue: TLabel
Left = 21
Top = 112
Width = 7
Height = 13
Alignment = taCenter
Caption = 'B'
end
object Label2: TLabel
Left = 52
Top = 7
Width = 27
Height = 102
AutoSize = False
Color = clGray
ParentColor = False
Transparent = False
end
object Background_Red: TLabel
Left = 53
Top = 8
Width = 25
Height = 100
Hint = 'Red category'
AutoSize = False
Color = 3276950
ParentColor = False
Transparent = False
end
object Height_Red: TLabel
Left = 53
Top = 8
Width = 25
Height = 90
Hint = 'Red category'
AutoSize = False
Color = clWhite
ParentColor = False
Transparent = False
end
object Label_Red: TLabel
Left = 61
Top = 112
Width = 8
Height = 13
Alignment = taCenter
Caption = 'R'
end
object Label5: TLabel
Left = 92
Top = 7
Width = 27
Height = 102
AutoSize = False
Color = clGray
ParentColor = False
Transparent = False
end
object Background_Yellow: TLabel
Left = 93
Top = 8
Width = 25
Height = 100
Hint = 'Yellow category'
AutoSize = False
Color = 55295
ParentColor = False
Transparent = False
end
object Height_Yellow: TLabel
Left = 93
Top = 8
Width = 25
Height = 90
Hint = 'Yellow category'
AutoSize = False
Color = clWhite
ParentColor = False
Transparent = False
end
object Label_Yellow: TLabel
Left = 102
Top = 112
Width = 7
Height = 13
Alignment = taCenter
Caption = 'Y'
end
object Mark_Popup: TCheckBox
Left = 45
Top = 151
Width = 52
Height = 17
Caption = 'Popup'
Checked = True
State = cbChecked
TabOrder = 0
end
end
EndDialog>Monitor
Dialog>NewJob
object NewJob: TForm
Left = 255
Top = 104
HelpContext = 5000
BorderIcons = []
BorderStyle = bsToolWindow
Caption = 'New message'
ClientHeight = 42
ClientWidth = 300
Color = clWhite
UseDockManager = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
DesignSize = (
300
42)
PixelsPerInch = 96
TextHeight = 13
object Label_JobName: TLabel
Left = 2
Top = 2
Width = 286
Height = 37
Margins.Left = 1
Margins.Top = 1
Margins.Right = 1
Margins.Bottom = 1
Alignment = taCenter
Anchors = [akLeft, akTop, akRight, akBottom]
AutoSize = False
Caption = 'JobName'
Font.Charset = DEFAULT_CHARSET
Font.Color = clOlive
Font.Height = -21
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
Transparent = False
Layout = tlCenter
WordWrap = True
ExplicitWidth = 391
ExplicitHeight = 183
end
end
EndDialog>NewJob
//Handle exit
AddDialogHandler>Monitor,,OnClose,EXIT
//Get Screen and correct windows to lower right corner.
GetScreenRes>Screen_X,Screen_Y
Let>Screen_X_Monitor=%Screen_X%-150
Let>Screen_Y_Monitor=%Screen_Y%-255
SetDialogProperty>Monitor,,Left,%Screen_X_Monitor%
SetDialogProperty>Monitor,,Top,%Screen_Y_Monitor%
Let>Screen_X_NewJob=%Screen_X%-318
Let>Screen_Y_NewJob=%Screen_Y%-118
SetDialogProperty>NewJob,,Left,%Screen_X_NewJob%
SetDialogProperty>NewJob,,Top,%Screen_Y_NewJob%
GetTime>Time_START
Label>START
//Count Blue
Let>Counting=%path_blue%
Let>Max=%max_blue%
Let>Chart=Height_Blue
Let>Caption_chart=B
Let>Label_chart=Label_Blue
GoSub>COUNT_FILES
//Count Red
Let>Counting=%path_red%
Let>Max=%max_red%
Let>Chart=Height_red
Let>Caption_chart=R
Let>Label_chart=Label_Red
GoSub>COUNT_FILES
//Count Yellow
Let>Counting=%path_yellow%
Let>Max=%max_yellow%
Let>Chart=Height_Yellow
Let>Caption_chart=Y
Let>Label_chart=Label_Yellow
GoSub>COUNT_FILES
//Kick dialog into action
Show>Monitor
//Look if popup is wanted.
GetDialogProperty>Monitor,Mark_Popup,Checked,Mark_Popup_State
If>Mark_Popup_State=True,POPUP
//Just to get time of last check
GetTime>Time_START
Wait>%time_check%
Goto>START
//End of main code, below sub rutines
SRT>POPUP
Let>Delay_popup=0
//Check Blue
SetDialogProperty>NewJob,,Caption,Blue Category
SetDialogObjectFont>NewJob,Label_JobName,Helvetica,21,0,%FontWhite%
SetDialogObjectColor>NewJob,,%Blue%
GetFileList>%path_blue%\*.txt,Fillist,;
If>Fillist<GoSub>CHECK_FILES
EndIf>
//Check Red
SetDialogProperty>NewJob,,Caption,Red Category
SetDialogObjectFont>NewJob,Label_JobName,Helvetica,21,0,%FontWhite%
SetDialogObjectColor>NewJob,,%Red%
GetFileList>%path_red%\*.txt,Fillist,;
If>Fillist<GoSub>CHECK_FILES
EndIf>
//Check Yellow
SetDialogProperty>NewJob,,Caption,Yellow Category
SetDialogObjectFont>NewJob,Label_JobName,Helvetica,21,0,%FontBlack%
SetDialogObjectColor>NewJob,,%Yellow%
GetFileList>%path_yellow%\*.txt,Fillist,;
If>Fillist<GoSub>CHECK_FILES
EndIf>
END>POPUP
SRT>CHECK_FILES
Separate>Fillist,;,Fillist_array
Let>k=0
Repeat>k
Let>k=k+1
GetTime>Time1
Let>TimeAdd=%Delay_popup%
TimeAdd>Time1,S,%TimeAdd%,Time1
//Look for time of file
FileTime>Fillist_array_%k%,Time2
MidStr>Time2,0,2,Time2_HH
MidStr>Time2,3,2,Time2_MM
MidStr>Time2,5,2,Time2_SS
//Put together the time in correct format (not sure if this is correct for everyone)
Let>Time2=%Time2_HH%:%Time2_MM%:%Time2_SS%
//Compare time2 and time1
TimeDiff>Time1,Time_START,S,Time_diff_START
TimeDiff>Time2,Time_START,S,Time_diff
//Debug message below:
//ExtractFileName>Fillist_array_%k%,Name_file
//MessageModal>%Name_file%%CRLF%%Time1% Time1 diff: %Time_diff_START%%CRLF%%Time2% Time2 diff: %Time_diff%
If>Time_diff<Time_diff_START>Delay_popup=%Delay_popup%+%time_popup%
ExtractFileName>Fillist_array_%k%,JobName
Length>JobName,Length_JobName
Let>Length_JobName=%Length_JobName%-4
MidStr>JobName,0,%Length_JobName%,JobName
SetDialogProperty>NewJob,Label_JobName,Caption,%JobName%
Show>NewJob
Wait>%time_popup%
CloseDialog>NewJob
Endif
Until>k,Fillist_array_count
Let>Fillist=
END>CHECK_FILES
SRT>COUNT_FILES
CountFiles>%Counting%\*.txt,NoFiles,0
If>NoFiles>%Max%
Let>Chart_height=%Max%
Else>
Let>Chart_height=%NoFiles%
Endif>
Let>Chart_height={100-%Chart_height%/%Max%*100}
Let>PropName=Height
SetDialogProperty>Monitor,%Chart%,%PropName%,%Chart_height%
SetDialogProperty>Monitor,%Label_chart%,Caption,%Caption_chart%%CRLF%(%NoFiles%)
END>COUNT_FILES
SRT>EXIT
Exit>0
END>EXIT
HELP CODE TO TEST THE SCRIPT
Code: Select all
//Paths
Let>path_blue=%SCRIPT_DIR%\Blue
Let>path_red=%SCRIPT_DIR%\Red
Let>path_yellow=%SCRIPT_DIR%\Yellow
Dialog>Create_Files
object Create_Files: TForm
Left = 255
Top = 104
HelpContext = 5000
BorderIcons = [biSystemMenu]
BorderStyle = bsSizeToolWin
Caption = 'BRY'
ClientHeight = 118
ClientWidth = 116
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object Button_Blue: tMSButton
Left = 22
Top = 17
Width = 75
Height = 25
Caption = 'Blue'
TabOrder = 0
DoBrowse = False
BrowseStyle = fbOpen
end
object Button_Red: tMSButton
Left = 22
Top = 49
Width = 75
Height = 25
Caption = 'Red'
TabOrder = 1
DoBrowse = False
BrowseStyle = fbOpen
end
object Button_Yellow: tMSButton
Left = 22
Top = 81
Width = 75
Height = 25
Caption = 'Yellow'
TabOrder = 2
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Create_Files
//Handle exit
AddDialogHandler>Create_Files,,OnClose,EXIT
AddDialogHandler>Create_Files,Button_Blue,OnClick,BLUE
AddDialogHandler>Create_Files,Button_Red,OnClick,RED
AddDialogHandler>Create_Files,Button_Yellow,OnClick,YELLOW
//Get Screen and correct windows to lower right corner.
GetScreenRes>Screen_X,Screen_Y
Let>Screen_X=%Screen_X%-500
Let>Screen_Y=%Screen_Y%-255
SetDialogProperty>Create_Files,,Left,%Screen_X%
SetDialogProperty>Create_Files,,Top,%Screen_Y%
Show>Create_Files,r
SRT>BLUE
Let>FileNameTXT=Blue
Let>FilePathTXT=%path_blue%
Gosub>CREATE_FILE
END>BLUE
SRT>RED
Let>FileNameTXT=Red
Let>FilePathTXT=%path_red%
Gosub>CREATE_FILE
END>RED
SRT>YELLOW
Let>FileNameTXT=Yellow
Let>FilePathTXT=%path_yellow%
Gosub>CREATE_FILE
END>YELLOW
SRT>CREATE_FILE
Hour>Prefix_hour
Min>Prefix_minutes
Sec>Prefix_seconds
Let>Prefix=%Prefix_hour%%Prefix_minutes%%Prefix_seconds%
CreateDir>%FilePathTXT%
WriteLn>%FilePathTXT%\%FileNameTXT%-%Prefix%.txt,r,%Prefix%
END>CREATE_FILE
SRT>EXIT
Exit>0
END>EXIT