tifudi Posted October 21, 2021 Posted October 21, 2021 Hello, I am trying to automatically search and replace some specific variables in TIA V17. The script I wrote does the following: Searching for the name of the variable Cutting the part, which needs to be changed Rearranging the cut part in the correct order Pasting the rearranged part Going back to 1. to search for the next variable The script works fine most of the time, but sometimes it just stops at some random variables, right before pasting the rearranged name and gives me the same error every time: Array variable has incorrect number of subscripts or subscript dimension range exceeded $New = 'HMIScreen_' & $Split[3] &'[' & $Split[2] & ']' $New = 'HMIScreen_' & ^ ERROR _HMIScreenV3.0_TIA17.au3
tifudi Posted October 21, 2021 Author Posted October 21, 2021 expandcollapse popupLocal $Step = 1 Local $NoOfOpendFBs = 1 Local $EndFound = False Local $WinExistsReturn = False Local $PathAndProject = "" Local $NameSearchWindowNotFound_de = "Suchen (0102:000002)" Local $NameSearchWindowFinished_de = "Suchen (0102:000004)" Local $NameVariableDec_de = "Variable definieren" Const $Eins = 1 ; ; Func _WinActivateMsg($title,$text,$TextForMsg="_") If Not WinActive($title,$text) Then WinActivate($title,$text) EndIf If not WinActive($title,$text) Then MsgBox(0,"",$TextForMsg) exit Endif EndFunc Func TIA_SuchenWarten($SuchenNach,$WaitTime,$Enter,$Title1,$Title2,$Text,$TimeToClose) send("{CTRLDOWN}f{CTRLUP}") send($SuchenNach) sleep(200) send("{ENTER}") sleep($WaitTime) If WinExists($Title1,$Text) or WinExists($Title2,$Text) Then $WinExistsReturn = true If $TimeToClose > 0 Then sleep($TimeToClose) send("{ENTER}") EndIf WinWaitClose($Title1,$Text) WinWaitClose($Title2,$Text) Else $WinExistsReturn = False If $Enter Then send("{ENTER}") EndIf EndIf EndFunc Func TIA_PrjEingabe() $PathAndProject = InputBox("Aufgabe", "Pfad und TIA-Projekt eingeben" & @CRLF & @CRLF & "Beispiel:" , "","", _ 1000); If @error > 0 Then MsgBox(0, "", "Abbruch") Exit EndIf EndFunc Func TIA_NoOfOpendFBs() $NoOfOpendFBs = InputBox("Aufgabe", "Anzahl der geöffneten Funktionsbausteine angeben" & @CRLF & @CRLF &"Es dürfen keine weiteren Fenster offen sein!!!", "1","") If @error > 0 Then MsgBox(0, "", "Abbruch") Exit EndIf EndFunc Func TIA_GoTo1Nw() send("{CTRLDOWN}g{CTRLUP}") send("{ENTER}") send("{LEFT}") EndFunc HotKeySet ("{PAUSE}", "Abbruch_Script") Func Abbruch_Script() MsgBox(0, "", "Script wurde abgebrochen") exit; EndFunc #include <MsgBoxConstants.au3> ; ; $Return = MsgBox(64, "", "INFO" & @CRLF & "NICHT VERGESSEN !!!" & @CRLF & "!" & @CRLF & @CRLF & "Funktioniert nur mit deutschen Editor!" & @CRLF & @CRLF & "Script läßt sich mit Pause Abbrechen !!!" ) $Return = MsgBox(64, "", "To Do" & @CRLF & "Im TIA-Portal"& @CRLF & " -Projekt öffnen"& @CRLF & " -Projekt archivieren"& @CRLF & " -Inhalt des Quellpfades kopieren"& @CRLF & " und im folgenden Fenster eintragen"& @CRLF & " nicht vergessen .ap15_1 löschen!" & @CRLF& @CRLF & " - FB's in welchen ersetzt werden soll, alle öffnen" & @CRLF ) TIA_PrjEingabe() ConsoleWrite($PathAndProject& @CRLF) TIA_NoOfOpendFBs() ConsoleWrite($NoOfOpendFBs& @CRLF) _WinActivateMsg($PathAndProject,"","gewähltes Projekt ist nicht geöffnet") Do TIA_GoTo1Nw() sleep(200) Do $EndFound = False TIA_SuchenWarten("HMIScreen",500, False, $NameSearchWindowNotFound_de,$NameSearchWindowFinished_de,"",100) $EndFound = $WinExistsReturn If Not $EndFound Then send("{CTRLDOWN}{SHIFTDOWN}{RIGHT}{SHIFTUP}{CTRLUP}") sleep(100) send("{CTRLDOWN}x {CTRLUP}") sleep(100) Local $sData = ClipGet() $Split = StringSplit($sData ,"_") $New = 'HMIScreen_' & $Split[3] &'[' & $Split[2] & ']' ClipPut ($New) send("{CTRLDOWN}v {CTRLUP}") sleep(100) endIf until $EndFound $Step = $Step + 1 sleep(100) sleep(100) If $Step <= $NoOfOpendFBs Then send("{CTRLDOWN}{F6}{CTRLUP}") EndIf until $Step > $NoOfOpendFBs MsgBox (0, "", "FERTIG!!!!" )
Danp2 Posted October 21, 2021 Posted October 21, 2021 You need to check the results of StringSplit before proceeding. The contents of $Split[0] should indicate the number of strings returned. Your script will fail if this value isn't at least 3. Latest Webdriver UDF Release Webdriver Wiki FAQs
Zedna Posted October 21, 2021 Posted October 21, 2021 As Danp2 said, here is solution: If Not $EndFound Then send("{CTRLDOWN}{SHIFTDOWN}{RIGHT}{SHIFTUP}{CTRLUP}") sleep(100) send("{CTRLDOWN}x {CTRLUP}") sleep(100) Local $sData = ClipGet() $Split = StringSplit($sData ,"_") If $Split[0] > 2 Then ; --> here is fix $New = 'HMIScreen_' & $Split[3] &'[' & $Split[2] & ']' ClipPut ($New) EndIf send("{CTRLDOWN}v {CTRLUP}") sleep(100) endIf Resources UDF ResourcesEx UDF AutoIt Forum Search
tifudi Posted October 21, 2021 Author Posted October 21, 2021 Thanks. The error does not appear anymore, but why does the StringSplit function return less than 3 strings sometimes? All variables, which should be rearranged, are build the same way, e.g. "P01".B.HMIScreen_2_Fault, which should be rearranged to "P01".B.HMIScreen_Fault[2]. I just tested the script multiple times on the same network. The variables, which returned less than 3 strings were different ones every time.
Danp2 Posted October 21, 2021 Posted October 21, 2021 The logical explanation is that the original string contains less that two underscore characters. You can use _ArrayDisplay to examine the contents of the array. Latest Webdriver UDF Release Webdriver Wiki FAQs
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now