Jump to content

Issue With Being Stuck In Loop


Recommended Posts

I have a bit of code in a script that I need to loop x number of times based on what number is entered into a specific input box. The number that is put in that input box also determines how many times I need to replace a string of characters in a specific input box as well.

I'm trying to replace a sting in this fashion:

"input box NumberofProjects"= 7 Projects

"input box Project Name= Testing-01A-Q01-2013

so in this scenario I would need it to be when you click "nextprojectbutton" the first time it would rename the data in the project name box to "Testing-01B-Q01-2013" and C the next time and D the next time etc. The issue is at the moment i'm getting stuck in a loop and its not incrementing past 1. I think its because the first letter is A that its searching for and when it does increment the next letter to B that it doesn't know that the string to replace is B instead of A. Please let me know if anyone has any questions.

Case $RDCNextProjectButton

Local $ProjectNameRead = GUICtrlRead ($ProjectNameInputBox)
$RDCNumberOfProjectsRead = GUICtrlRead ($RDCNumberOfProjectsInput)
For $I = $RDCNumberOfProjectsInput to 1 Step -1
$sFirst = "A"
$iASCII = Asc($sFirst)
$iASCII += 1
$sNext = Chr($iASCII)
Local $sinput = $ProjectNameRead
Local $soutput =StringRegExpReplace($sinput, "\-01A-" & "Q", "-01"& $sNext &"-Q")
guictrlsetdata ($ProjectNameInputBox,$soutput)
_GUICtrlComboBox_SetCurSel($RDCRouterNameCombo, 0)
_GUICtrlComboBox_SetCurSel($RDCOtherRouterNameCombo, 0)
guictrlsetdata ($ASideFPCInstallInput,"")
guictrlsetdata ($ZSideFPCInstallInput,"")
guictrlsetdata ($RDCASideOpticsInstall,"")
guictrlsetdata ($RDCZSideOpticsInstall,"")
Next
Link to comment
Share on other sites

You need to move the line "$sFirst = "A"" outside of the loop, as it gets reset every time the loop restarts.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks, I moved it out, and I am still getting the result of "01A" being changed to "01B" but when "3" is put in the number of projects, it should increment the "01B" to "01C" and that still isn't happening. Do I need to have $sin first go through the whole alphabit in order for it to know the next letter to increment from.

Link to comment
Share on other sites

I changed the code to below to see if this would solve my issue. Unfortunately, it doesn't appear to be reading the $sreplacevariable in the string.

Case $RDCNextProjectButton


Local $ProjectNameRead = GUICtrlRead ($ProjectNameInputBox)
$RDCNumberOfProjectsRead = GUICtrlRead ($RDCNumberOfProjectsInput)
$sreplacevariable = "-01A|-01B|-01C|-01D|-01E|-01F|-01G|-01H|-01I|-01J|-01K|-01L|-01M|-01N|-01O|-01P|-01R|-01S|-01T|-01U|-01V|-01W|-01X|-01Y|-01Z"
$sFirst= "A"
Local $SitesArray = StringSplit($sFirst, '|')
For $I = $RDCNumberOfProjectsInput to 1 Step -1

$iASCII = Asc($sFirst)
$iASCII += 1
$sNext = Chr($iASCII)
Local $sinput = $ProjectNameRead
Local $soutput =StringRegExpReplace($sinput, $sreplacevariable & "Q", "-01"& $sNext &"-Q")
guictrlsetdata ($ProjectNameInputBox,$soutput)
_GUICtrlComboBox_SetCurSel($RDCRouterNameCombo, 0)
_GUICtrlComboBox_SetCurSel($RDCOtherRouterNameCombo, 0)
guictrlsetdata ($ASideFPCInstallInput,"")
guictrlsetdata ($ZSideFPCInstallInput,"")
guictrlsetdata ($RDCASideOpticsInstall,"")
guictrlsetdata ($RDCZSideOpticsInstall,"")
Next
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...