Struggling With Dialog In a Loop

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
NickD
Pro Scripter
Posts: 58
Joined: Fri Sep 23, 2016 2:17 pm

Struggling With Dialog In a Loop

Post by NickD » Wed Aug 16, 2017 8:40 pm

I have a script which parses a row from a csv file containing a url for an image, then displays the image in a dialog with fields allowing me to tag the images color and write a description for the image, this info is saved to another csv file and them the script Loops and pulls the next row.

The problem I have is that after the first image has been tagged Macro scheduler throws an error telling me that dialog1 alread exists, if anyone can help me solve this problem it would be greatly appreciated. I have just starting using dialogs and dont really understand why this dialog is remaining open between loops.

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1


Label>Loop
Wait>1
// Choose Form Data Row

ReadIniFile>C:\imageparsing.ini,FormData,CurrentRow,CurrentContentRow


GoSub>GetFormData

Let>ImageURL=%fields_1%
Let>Color=%fields_2%
Let>Description=%fields_3%

// Build Custom HTML
Let>MockPage=<!doctype html><html><head><title>Image Tagger</title></head><body><center><img src="%ImageURL%" /></center></body></html>


// Dialog Form

Dialog>Dialog1
object Dialog1: TForm
  Left = 231
  Top = 127
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Image Tagger'
  ClientHeight = 800
  ClientWidth = 1000
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSHTMLViewer1: tMSHTMLViewer
    Left = -5
    Top = -2
    Width = 1078
    Height = 451
    TabOrder = 0
    BorderStyle = htFocused
    DefFontName = 'Times New Roman'
    DefPreFontName = 'Courier New'
    HistoryMaxCount = 0
    NoSelect = False
    PrintMarginBottom = 2.000000000000000000
    PrintMarginLeft = 2.000000000000000000
    PrintMarginRight = 2.000000000000000000
    PrintMarginTop = 2.000000000000000000
    PrintScale = 1.000000000000000000
  end
  object Label1: Tlabel
  Left =10
  Top = 450
  Width = 200
  Height = 13
  Caption = 'Color:'
  end
  object ColorField: TEdit
    Left = 10
    Top = 467
    Width = 975
    Height = 110
    TabOrder = 1
  end
  object Label2: Tlabel
  Left =10
  Top = 535
  Width = 200
  Height = 13
  Caption = 'Description:'
  end
  object DescriptionField: TEdit
    Left = 8
    Top = 552
    Width = 977
    Height = 110
    TabOrder = 2
  end
  object MSButton1: tMSButton
    Left = 50
    Top = 720
    Width = 430
    Height = 50
    Caption = 'OK'
    ModalResult = 1
    TabOrder = 4
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 520
    Top = 720
    Width = 430
    Height = 50
    Caption = 'Cancel'
    ModalResult = 2
    TabOrder = 5
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,DoClose

// Display Custom HTML
SetDialogProperty>Dialog1,MSHTMLViewer1,html,MockPage
Show>Dialog1,ImageModal


// Dialog Buttons

If>ImageModal=1
  GetDialogProperty>Dialog1,ColorField,Text,Color
  GetDialogProperty>Dialog1,DescriptionField,Text,Description
  Let>result=%CurrentContentRow%
  Let>LineToWrite=%ImageURL%,%Color%,%Description%
  WriteLn>C:\imageparsing-results.csv,result,LineToWrite
Endif

If>ImageModal=2
  // Cancel Button
Endif


Let>CurrentContentRow=%CurrentContentRow%+1
EditIniFile>C:\imageparsing.ini,FormData,CurrentRow,%CurrentContentRow%


Goto>Loop

      
SRT>GetFormData
 Let>Seperator=;
 ReadFile>C:\imageparsing-datafile.csv,TheFileData
 Separate>TheFileData,CRLF,Lines
 Let>CurrentLine=Lines_%CurrentContentRow%
 //extract each field
 Separate>CurrentLine,Seperator,fields
END>GetFormData

SRT>DoClose
 Let>Terminated=TRUE
End>DoClose

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Struggling With Dialog In a Loop

Post by JRL » Wed Aug 16, 2017 9:20 pm

Once a dialog block has been called, the dialog exists until the script ends. Take the Dialog block out of the loop. Put it somewhere near the top of the script. only run that portion of the script one time. You can Show>Dialog1 and CloseDialog>Dialog1 as many time as you like but you can only define a dialog once.

NickD
Pro Scripter
Posts: 58
Joined: Fri Sep 23, 2016 2:17 pm

Re: Struggling With Dialog In a Loop

Post by NickD » Wed Aug 16, 2017 9:38 pm

Thanks JRL, that was driving me crazy lol.
Great support as always :D

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