simple way to add results to memobox

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
krash2501
Newbie
Posts: 15
Joined: Thu Jul 21, 2016 7:04 pm

simple way to add results to memobox

Post by krash2501 » Tue Mar 07, 2017 6:58 pm

I have a dialog box where when you scan a Serial Number I want it to add the serial number result into a memobox in the dialog.

Right now I am doing the following but I think there has to be a better way.

Code: Select all

 GetDialogProperty>Dialog1,Edit3,Text,vStr1
WriteLn>filename,results,vStr1
let>x=x+1
    Let>Y=0
        Repeat>Y
        let>y=y+1
            ReadLn>filename,Y,LN%Y%
        Until>Y,X
        if>x=1
            Let>MEMO#=%LN1%
        endif
        if>x=2
            Let>MEMO#=%LN1%%CRLF%%LN2%
        endif
        if>x=3
            Let>MEMO#=%LN1%%CRLF%%LN2%%CRLF%%LN3%
        endif
        if>x=4
            Let>MEMO#=%LN1%%CRLF%%LN2%%CRLF%%LN3%%CRLF%%LN4%
        endif
  setDialogProperty>Dialog1,MSMemo1,Text,MEMO#

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Re: simple way to add results to memobox

Post by zabros2020 » Fri Mar 10, 2017 6:46 am

Hi...you could do something like this:

Code: Select all

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

Dialog>Dialog1
object Dialog1: TForm
  Left = 358
  Top = 147
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 410
  ClientWidth = 301
  Color = clBtnFace
  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 Label1: TLabel
    Left = 11
    Top = 8
    Width = 102
    Height = 13
    Caption = 'Press '#39'Enter'#39' to trigger'
  end
  object txtText: TEdit
    Left = 9
    Top = 22
    Width = 121
    Height = 21
    TabOrder = 0
    Text = '#12344123412341234123#'
  end
  object btnExit: tMSButton
    Left = 12
    Top = 364
    Width = 75
    Height = 25
    Caption = 'Exit'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object memText: tMSMemo
    Left = 8
    Top = 50
    Width = 283
    Height = 308
    TabOrder = 2
  end
end
EndDialog>Dialog1

'define dir
Let>filesDir=C:\Temp
GoSub>LoadHandlers
Show>Dialog1,

SRT>LoadHandlers
  AddDialogHandler>Dialog1,txtText,OnChange,GetText(0)
  AddDialogHandler>Dialog1,txtText,OnKeyPress,GetText(1)
  AddDialogHandler>Dialog1,btnExit,OnClick,Exit
END>LoadHandlers

SRT>GetText
  'get the text from the text box
  GetDialogProperty>Dialog1,txtText,Text,sText
  'When a user presses a key, determine if it is Enter key(13)
  If>GetText_Var_1=1
    'When enter is pressed do what needs to be done
    If>GetText_Key=13
      GoSub>WriteFile,%sText%
      GoSub>ReadSFile
      Let>GetText_Var_1=0
      Let>GetText_Key=
    EndIf
  EndIf
END>GetText

SRT>Exit
  Exit>
END>Exit

SRT>WriteFile
  'define file name
  Let>fileNameS=%filesDir%\serialTest.txt
  WriteLn>%fileNameS%,res,%WriteFile_Var_1%
END>WriteFile

SRT>ReadSFile
  Let>memoTxt=
  Let>n=0
  Let>i=0
  Repeat>i
    Add>i,1
    ReadLn>%fileNameS%,%i%,lVal
    If>lVal=##EOF##
      Let>n=%i%
    Else
      ConCat>memoTxt,%lVal%%CRLF%
    EndIf
  Until>i=%n%
  SetDialogProperty>Dialog1,memText,Text,%memoTxt%
END>ReadSFile
Loving MS's Capabilities!!!

krash2501
Newbie
Posts: 15
Joined: Thu Jul 21, 2016 7:04 pm

Re: simple way to add results to memobox

Post by krash2501 » Fri Mar 10, 2017 5:02 pm

Thanks I will plug this in.

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