Sign in to follow this  
Followers 0
Bert

letter counting in a array

9 posts in this topic

In the first part of the script, you will see where I make a array. The array is for each letter in the Alphabet. Is there a way to make the array in a loop, so I have fewer lines of code?

#include <GuiConstants.au3>
dim $Checkbox_[27]
dim $l[27], $C[27]
DIM $ini = @ScriptDir & "/PCT_tool.ini"
$l[1]="A"
$l[2]="B"
$l[3]="C"
$l[4]="D"
$l[5]="E"
$l[6]="F"
$l[7]="G"
$l[8]="H"
$l[9]="I"
$l[10]="J"
$l[11]="K"
$l[12]="L"
$l[13]="M"
$l[14]="N"
$l[15]="O"
$l[16]="P"
$l[17]="Q"
$l[18]="R"
$l[19]="S"
$l[20]="T"
$l[21]="U"
$l[22]="V"
$l[23]="W"
$l[24]="X"
$l[25]="Y"
$l[26]="Z"
GuiCreate("Drive Letter Filter", 190, 320,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$iniD = IniReadSection($ini, "2") 
if @error = 1 Then
    $sData = "1=1" & @LF & "2=1" & @LF & "3=1"& @LF & "4=4" & @LF & "5=4"& @LF & "6=4" & @LF _
    & "7=4"& @LF & "8=4" & @LF & "9=4"& @LF & "10=4" & @LF & "11=4" &@LF _
    & "12=4" & @LF & "13=4"& @LF & "14=4" & @LF & "15=4"& @LF & "16=4" & @LF & "17=4"& @LF _
    & "18=4" & @LF & "19=4"& @LF & "20=4" & @LF & "21=4"& @LF & "22=4" & @LF _
    & "23=4"& @LF & "24=4" & @LF & "25=4"& @LF & "26=4" 
    IniWriteSection($ini, "2", $sData)
EndIf
$iniD = IniReadSection($ini, "2")
$x=1
$x1=20
$x2=5
do 
    if $x=14 then 
        $x1= 130
        $x2= 5
    endif   
    $Checkbox_[$x] = GuiCtrlCreateCheckbox($l[$x]&":\", $x1, $x2, 50, 20)
    if $iniD[$x][1] = 1 then GUICtrlSetState($Checkbox_[$x], $GUI_CHECKED)
    $x=$x+1
    $x2=$x2+20
Until $x=27
$x=1
$button_D1 = GUICtrlCreateButton("OK", 20, 280, 70, 30)
$button_D2 = GUICtrlCreateButton("Cancel", 100, 280, 70, 30)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE or $msg = $button_D2
        ExitLoop
    Case $msg = $button_D1      
        $x=1
        Do
            $C[$x] = GUICtrlRead($Checkbox_[$x])
            $x=$x+1
        Until $x=27
        $sData = "1="&$C[1]& @LF & "2="&$C[2]& @LF & "3="&$C[3]& @LF & "4=" &$C[4]& @LF & "5="&$C[5]& @LF & "6=" &$C[6]& @LF _
        & "7=" &$C[7]&  @LF & "8="  &$C[8]&  @LF & "9=" &$C[9]&  @LF & "10=" &$C[10]& @LF & "11=" &$C[11]& @LF & "12=" &$C[12]& @LF _
        & "13="&$C[13]& @LF & "14=" &$C[14]& @LF & "15="&$C[15]& @LF & "16=" &$C[16]& @LF & "17=" &$C[17]& @LF & "18=" &$C[18]& @LF _
        & "19="&$C[19]& @LF & "20=" &$C[20]& @LF & "21="&$C[21]& @LF & "22=" &$C[22]& @LF & "23=" &$C[23]& @LF & "24=" &$C[24]& @LF _
        & "25="&$C[25]& @LF & "26=" &$C[26] 
        IniWriteSection($ini,"2", $sData)
        exit
    Case Else
        ;;;
    EndSelect
WEnd
Exit

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$l = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "")oÝ÷ Øí«b²Ú(y«2jëh×6dim $l[27]
$element = 1
For $X = 65 to 90
    $l[$element] = Chr($X)
    $element += 1
Next

Edited by weaponx

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

...Is there a way to make the array in a loop, so I have fewer lines of code?...

Make up your mind - do you want a loop or fewer lines of code :-)

Since weaponx beat me to the code that I was going to post - here is a loop:

Dim $l[27]
For $c = 65 To 90
    $l[$c - 64] = Chr($c)
Next

Edit: sure... post the loop too in an edit :-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Sorry, I didn't want to make a new post.

Share this post


Link to post
Share on other sites

Sorry, I didn't want to make a new post.

Oh it was just funny that I wrote a reply, then checked the thread via "Preview Post" only to find that you beat me to it... so I change my post to the loop and checked again only to find that you beat me to that too :-)

...but my loop was a bit different so I posted it and then decided to comment on your beating me again. :-)

I should have listened to my typing teacher.

I should have listened to my typing teacher.

I should have listened to my typing teacher.

I should have listened to my typing teacher.

... who knew 'puters were coming?


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

I've never taken typing class, and only use 3 fingers on each hand to type. I have interns type for me.

Share this post


Link to post
Share on other sites

I've never taken typing class, and only use 3 fingers on each hand to type. I have interns type for me.

I use the Columbus method of typing:

Discover a key and land on it!


[size="1"][font="Arial"].[u].[/u][/font][/size]

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