Sign in to follow this  
Followers 0
atnextc

Issues with array being delcared as variable

10 posts in this topic

#1 ·  Posted (edited)

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

1. Name of Project should be in the naming scheme of "Testing-01A-Q1-2013"

The bolded part above is the important part. Essentially this will be one of the following:

01($i)-Q1

02($i)-Q2

03($i)-Q3

04($i)-Q4

This is our naming scheme for projects depending on which quarter of the year we are in. For now I am just trying to get it to work with Q1 projects.

The issue is that if you set the project name to be "Testing-01A-Q1-2013" for example and the number of projects is 3 for example it will increment the next project name to be "Testing-01B-Q1-2013" as expected. BUT if you click next project again it should increment to "Testing-01C-Q1-2013" but that is not happening and i'm not sure why. What is happening is the project name is not incrementing.

Code is below. Any help would be appreciated.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1_1 = GUICreate("Test", 615, 438, 215, 170)
$RDCNextProjectButton = GUICtrlCreateButton("Next Project", 183, 241, 99, 33)
GUICtrlSetState(-1, $GUI_DISABLE)
$ProjectNameInputBox = GUICtrlCreateInput("", 35, 104, 193, 21)
$ProjectNameLabel = GUICtrlCreateLabel("Please Input Your Project Name", 27, 80, 200, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$NumberOfProjectsLabel = GUICtrlCreateLabel("Please Input The Number Of Projects You Have Of This Kind", 19, 160, 364, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$RDCNumberOfProjectsInput = GUICtrlCreateInput("", 49, 198, 193, 21)
$Submit = GUICtrlCreateButton("Submit", 72, 240, 99, 33)
GUICtrlSetState(-1, $GUI_ENABLE)
$RDCNumberOfProjectsRead = GUICtrlRead ($RDCNumberOfProjectsInput)

$I = $RDCNumberOfProjectsRead;<-------------------------------------------------------This will read the number that you entered into the "number of projects" inputbox.
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Dim $alphabit[26]
$alphabit[0]="A"
$alphabit[1]="B"
$alphabit[2]="C"
$alphabit[3]="D"
$alphabit[4]="E"
$alphabit[5]="F"
$alphabit[6]="G"
$alphabit[7]="H"
$alphabit[8]="I"
$alphabit[9]="J"
$alphabit[10]="K"
$alphabit[11]="L"
$alphabit[12]="M"
$alphabit[13]="N"
$alphabit[14]="O"
$alphabit[15]="P"
$alphabit[16]="Q"
$alphabit[17]="R"
$alphabit[18]="S"
$alphabit[19]="T"
$alphabit[20]="U"
$alphabit[21]="V"
$alphabit[22]="W"
$alphabit[23]="X"
$alphabit[24]="Y"
$alphabit[25]="Z"

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $RDCNumberOfProjectsInput
$RDCNumberOfProjectsRead = GUICtrlRead ($RDCNumberOfProjectsInput)
If ($RDCNumberOfProjectsRead) > 1 Then;<------------------------------------------------------If the number of projects entered is more than 1 then it will enable the next ;project button and disable the submit button.
GUICtrlSetState ($RDCNextProjectButton, $GUI_ENABLE)
GUICtrlSetState($Submit, $GUI_DISABLE)
ElseIf ($RDCNumberOfProjectsRead) <= 1 Then;<----------------------------------------------If the number of projects entered is 1 then it will keep the next project button ;disabled
GUICtrlSetState ($RDCNextProjectButton, $GUI_DISABLE)
GUICtrlSetState($Submit, $GUI_ENABLE)
EndIf
$CapacityInput = ($RDCNumberOfProjectsRead * 10)

Case $RDCNextProjectButton


Local $ProjectNameRead = GUICtrlRead ($ProjectNameInputBox)
$RDCNumberOfProjectsRead = GUICtrlRead ($RDCNumberOfProjectsInput)

$sFirst= $alphabit[1]

For $I = $RDCNumberOfProjectsRead To 1 Step - 1

$iASCII = Asc($sFirst)
$iASCII += 1
$sNext = Chr($iASCII)
Local $sinput = $ProjectNameRead
If $sinput = $ProjectNameRead Then
local $soutput =StringRegExpReplace($sinput, "\-01A-" & $alphabit & "Q", "-01"& $sNext &"-Q");<------Read the project name and if exist then rename "01A-" to "01B" which would be the next letter, and it should continue in this fashion based on the number of projects entered..
guictrlsetdata ($ProjectNameInputBox,$soutput)
MsgBox(0,"", "Testing Countdown Loop " & $i)
MsgBox(0,"","The total of capacity is " & $CapacityInput & "GB")
MsgBox(0,"","The next project name should be " & $soutput)

EndIf

Next
GUICtrlSetState ($RDCNextProjectButton, $GUI_DISABLE)
GUICtrlSetState($Submit, $GUI_ENABLE)
Case $Submit
MsgBox(0,"","End of Script","")
Exit

EndSwitch
WEnd
Edited by atnextc

Share this post


Link to post
Share on other sites



I'm lost, but I can point out a few things.

This will populate your array, more easily:

Dim $alphabit[26]
$iStart = 65
For $i = 0 To UBound($alphabit) - 1
 $alphabit[$i] = Chr($iStart + $i)
Next
_ArrayDisplay($alphabit)

And you are using the above array as a string inside the stringregexpreplace...you need to specify an array level

Local $soutput = StringRegExpReplace($sinput, "-01A-" & $alphabit[somevariablehere] & "Q", "-01" & $sNext & "-Q")


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@jdelaney

not exactly sure how/where that would be inserted in my existing script

Dim $alphabit[26]
$iStart = 65
For $i = 0 To UBound($alphabit) - 1
$alphabit[$i] = Chr($iStart + $i)
Next
_ArrayDisplay($alphabit)
Edited by atnextc

Share this post


Link to post
Share on other sites

Is that the behavior you want?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\users\tcovert\desktop\test.kxf
$Form1_1 = GUICreate("Test", 615, 438, 215, 170)
$RDCNextProjectButton = GUICtrlCreateButton("Next Project", 183, 241, 99, 33)
GUICtrlSetState(-1, $GUI_DISABLE)
$ProjectNameInputBox = GUICtrlCreateInput("", 35, 104, 193, 21)
$ProjectNameLabel = GUICtrlCreateLabel("Please Input Your Project Name", 27, 80, 200, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$NumberOfProjectsLabel = GUICtrlCreateLabel("Please Input The Number Of Projects You Have Of This Kind", 19, 160, 364, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$RDCNumberOfProjectsInput = GUICtrlCreateInput("", 49, 198, 193, 21)
$Submit = GUICtrlCreateButton("Submit", 72, 240, 99, 33)
GUICtrlSetState(-1, $GUI_ENABLE)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $RDCNumberOfProjectsInput
            $RDCNumberOfProjectsRead = GUICtrlRead($RDCNumberOfProjectsInput)
            If $RDCNumberOfProjectsRead > 1 Then
                GUICtrlSetState($RDCNextProjectButton, $GUI_ENABLE)
                GUICtrlSetState($Submit, $GUI_DISABLE)
            ElseIf $RDCNumberOfProjectsRead <= 1 Then
                GUICtrlSetState($RDCNextProjectButton, $GUI_DISABLE)
                GUICtrlSetState($Submit, $GUI_ENABLE)
            EndIf
            $CapacityInput = ($RDCNumberOfProjectsRead * 10)

        Case $RDCNextProjectButton
            Local $ProjectNameRead = GUICtrlRead($ProjectNameInputBox)
            $RDCNumberOfProjectsRead = GUICtrlRead($RDCNumberOfProjectsInput)

            For $I = 1 To $RDCNumberOfProjectsRead - 1
                Local $soutput = Execute("'" & StringRegExpReplace($ProjectNameRead, "(?<=-\d{2})([A-Z])(?=-Q)", "' & Chr(Asc('$1') + $I) & '") & "'")
                GUICtrlSetData($ProjectNameInputBox, $soutput)
                MsgBox(0, "", "Testing Countup Loop " & $I)
                MsgBox(0, "", "The total of capacity is " & $CapacityInput & "GB")
                MsgBox(0, "", "The next project name should be " & $soutput)
            Next
            GUICtrlSetState($RDCNextProjectButton, $GUI_DISABLE)
            GUICtrlSetState($Submit, $GUI_ENABLE)
        Case $Submit
            MsgBox(0, "", "End of Script", "")
            Exit

    EndSwitch
WEnd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Yes thank you that is exactly what I was looking for.

can you explain what changes that you made? I mean I see what you did but don't really understand it.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I've removed a lot of useless lines, but the main trick is to streamline the progression from A and up (or from any starting letter as long as the last project doesn't exceed Z).

The less cryptic way to do that is to chop down the project name first, isolate the letter then run the loop incrementing the letter and concatenating the project's name parts again.

I'm a bit lazy so I regularly use this kind of compound instruction as if regular expressions callback feature was available.

EDIT: maybe you'd like a breakdown explanation of the regexp and execute part?

(?<=-d{2}) is a lookbehind assertion requiring that what comes next is precedeed by a dash and 2 digits

([A-Z]) is the capturing pattern to match the letter we're interessed in

(?=-Q) is a lookahead assertion requiring that after the pattern we find another dash and the letter Q

The replacement part concatenates the AutoIt instruction to convert the captured letter (as $1) into its ASCII value, increment that by the loop variable $i and convert back the result into an ASCII letter. To execute all that stuff, we need to enclose everything inside parenthesis. This is the though part: distinct pair of quotes ' and " help avoid confusion but I confess it's often hard to code this right the first time...

Before the Execute line, run the code with this line inserted:

ConsoleWrite("'" & StringRegExpReplace($ProjectNameRead, "(?<=-\d{2})([A-Z])(?=-Q)", "' & Chr(Asc('$1') + $I) & '") & "'" & @LF)

You'll then see how the various parts fit together.

Edited by jchd
1 person likes this

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

yes thank you again, I was looking for a breakdown of what you did so I would be able to understand it and uses it going forward in future scripts.

Share this post


Link to post
Share on other sites

I edited my previous post. Is that clearer?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

yea it is thats why i had replied earlier stating that.

Share this post


Link to post
Share on other sites

ok i have everything working on this first part except for one minor thing.

I have all of this writing to a file "rdc.txt" and I need the following to be "replaced"

Example:

TESTING-01A-Q1-2013.....let's say we had 4 projects....that would make the last project name TESTING-01E-Q1-2013....i need a string replace or add or something to have the end result looking like this:

TESTING-01A-01E-Q1-2013 I have tried a few things but am failing.

as always any help would be appreciated.

[/font][/color]
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>

#include <File.au3>
local $gui010       =   GUICreate('Project Manager',500,500)

$RDCSubmitButton    =   GUICtrlCreateButton("Submit",20, 400, 460, 30)
                GUICtrlCreateLabel("Please Input Your Project Name",20,20,190,20)
                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$ProjectNameInputBox    =   GUICtrlCreateInput("", 210,17,250,20)
                GUICtrlCreateLabel("Please Input The Number Of Projects You Have Of This Kind", 20, 50, 370, 20)
                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$RDCNumberOfProjectsInput =     GUICtrlCreateInput("", 390, 47, 70, 20)
                guictrlcreatelabel('Site Name',20,80,100,20)
                guictrlsetfont(-1,8,800,-1,'ms sans serif')
$site       =   GUICtrlCreateInput("", 210,80,250,20)
                guictrlcreatelabel('Status',20,445,50,20)
                guictrlsetfont(-1,8.5,800)

$status         =   guictrlcreatelabel('',20,460,460,20,$ss_sunken)
                guictrlsetfont(-1,9,800)
                guictrlsetcolor(-1,0xff0000)
                guictrlsetstate($ProjectNameInputBox,$gui_focus)
                GUISetState(@SW_SHOW)
$ProjectNameRead = GUICtrlRead($ProjectNameInputBox)
                guictrlsetdata($ProjectNameInputBox,'TESTING-01A-Q1-2013')  ; <--- for testing
guictrlsetstyle($RDCSubmitButton,$BS_DEFPUSHBUTTON)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ;shellexecute(@scriptdir & '\testing.txt')
            Exit
        Case $RDCSubmitButton
$CapacityInput = ($RDCNumberOfProjectsInput * 10)

            If guictrlread($RDCNumberOfProjectsInput) = '' then
                MsgBox(0,"Error", 'Number of projects required')
                guictrlsetstate($RDCNumberOfProjectsInput,$gui_focus)
                continueloop
            endif

            If not stringisdigit(guictrlread($RDCNumberOfProjectsInput)) then
                MsgBox(0,"Error",'Number of projects must be numeric')
                guictrlsetstate($RDCNumberOfProjectsInput,$gui_focus)
                continueloop
            endif
            If guictrlread($ProjectNameInputBox) = '' then
                MsgBox(0,"Error",'Project name required')
                guictrlsetstate($ProjectNameInputBox,$gui_focus)
                continueloop
            endif
            if guictrlread($site) = '' then
                MsgBox(0,"Error",'Site name required')
                guictrlsetstate($site,$gui_focus)
                continueloop
            EndIf


            local $hfl = FileOpen(@scriptdir & '\testing.txt', 1)
            filewrite($hfl,guictrlread($site)& "," & @CRLF)
FileWrite($hfl, @CRLF & @CRLF)
FileWrite($hfl,"We recently have launched the below C4 projects for your system. We need on site assistance to perform the maintenance. Please let us know who the POC for this activity will be so we can set up a call to plan this work." & @CRLF & @CRLF & "Details for C4 Projects:")
FileWrite($hfl," Project ")
filewrite($hfl,guictrlread($ProjectNameInputBox)& @CRLF)
            FileWrite($hfl, @CRLF & @CRLF)
FileWrite($hfl,"The purpose of this project is to add an additional ")
FileWrite($hfl, $CapacityInput)
FileWrite($hfl, "GB of capacity between ")
filewrite($hfl,guictrlread($RDCNumberOfProjectsInput) & @CRLF)
            FileWrite($hfl, @CRLF)
fileclose($hfl)

            if guictrlread($RDCNumberOfProjectsInput) = 1 then
                guictrlsetdata($ProjectNameInputBox,'')
                guictrlsetdata($RDCNumberOfProjectsInput,'')
                guictrlsetdata($site,'')
                guictrlsetstate($ProjectNameInputBox,$gui_focus)
            endif
            if guictrlread($RDCNumberOfProjectsInput) > 1 then

                $aprojincr = stringregexp(guictrlread($ProjectNameInputBox),"(?<=-\d{2})([A-Z])(?=-Q)",3)
                 $incr_char = chr(asc($aprojincr[0])+guictrlread($RDCNumberOfProjectsInput))
                guictrlsetdata($ProjectNameInputBox,StringRegExpReplace(guictrlread($ProjectNameInputBox), _
                "(?<=-\d{2}A)(-\d{2}[A-Z])(?=-Q)", $incr_char))
                msgbox(0,"test1", $aprojincr)
msgbox(0,"test1", $incr_char)
;guictrlsetdata($RDCNumberOfProjectsInput,guictrlread($RDCNumberOfProjectsInput) - 1)
                guictrlsetdata($site,'')
                guictrlsetstate($site,$gui_focus)
            endif
 $find = $aprojincr
 $replace =$incr_char
_ReplaceStringInFile("rdc.txt", $find, $replace,0,0)
if guictrlread($RDCNumberOfProjectsInput) < 1 then
FileOpen(@scriptdir & '\testing.txt', 1)
Exit

EndIf
EndSwitch
WEnd

Share this post


Link to post
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
Sign in to follow this  
Followers 0