Sign in to follow this  
Followers 0
GodForsakenSoul

emptying array [solved][i am an idiot]

10 posts in this topic

#1 ·  Posted (edited)

Func PKANSCORE()
    $pkanscore1=IniRead("OPT.INI","ANSWERS","SCORE","0")
    $pkanscore2=StringSplit($pkanscore1,"")
    GUICreate("Japanese basic training: Kana training",300,250)
    Opt("GuiCoordMode",0)
    GUICtrlCreatePic("Data\Graphics\MGO1.bmp",25,25,250,100)
    GUICtrlCreateLabel("Congratulations! Your score is...",0,120,250,20)
    GUICtrlCreatePic("Data\Graphics\MGN"&$pkanscore2[5]&".bmp",0,150,50,50)
    GUICtrlCreatePic("Data\Graphics\MGN"&$pkanscore2[4]&".bmp",25,0,50,50)
    GUICtrlCreatePic("Data\Graphics\MGN"&$pkanscore2[3]&".bmp",25,0,50,50)
    GUICtrlCreatePic("Data\Graphics\MGN"&$pkanscore2[2]&".bmp",25,0,50,50)
    GUICtrlCreatePic("Data\Graphics\MGN"&$pkanscore2[1]&".bmp",25,0,50,50)
    GUISetState()

    While 1=1
        $pkansc=GUIGetMsg()
        Select
            case $pkansc=$GUI_EVENT_CLOSE
                GUIDelete()
                GUIMainGui()
        EndSelect
        Sleep(5000)
        GUIDelete()
        GUIMainGui()
    WEnd
EndFunc

in this piece of code i need $pkanscore[1] to $pkanscore[5] (or infinity) be 0'ed in advance so they could show MGN0.bmp

i can't do it myself. i tried. help?

Edited by GodForsakenSoul

Share this post


Link to post
Share on other sites



For $iCount = 1 to UBound($pkanscore,1)
 $pkanscore[$iCount1] = 0
Next


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It's good practice to use a for loop to assign any value to multiple elements in an array.

It's quicker, looks nicer, and uses less code.

Share this post


Link to post
Share on other sites

but won't it just sit there till it's done putting zeroes in $pkanscore[infinity]?

Share this post


Link to post
Share on other sites

In AutoIt you set the size of an array when you define it

Global $Array[10]

When you don't know how many elements the array will have at the end then use

ReDim $Array[Ubound($Array,1)+1]

to extend the array every time you add an element.

How do you want to fill your array?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

my array is supposed to have 5 elements (not including [0]) tops, assuming some weirdo DOES get to 99999.

i'm using stringsplit to split the numbers to show a nice combo of pics instead of a fugly label.

however, i'm testing it (atm) on 10. so that's only two places filled. i want to have the other three filled with zeroes, 00010 <-like so.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This should work. It extends the array to 5 elements and fills the "new" elements with "0".

#include <array.au3>

$pkanscore1 = 123
$pkanscore2=StringSplit($pkanscore1,"")
ReDim $pkanscore2[6]
If $pkanscore2[0] < 5 Then
    For $iCount1 = $pkanscore2[0]+1 To 5
        $pkanscore2[$iCount1] = 0
    Next
    $pkanscore2[0] = 5
EndIf
_ArrayDisplay($pkanscore2)
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

thanks! works like a charm. now i have a new problem. the numbers don't show.

i AM working on solving the problem, however, if anyone find the problem before me, please report ;)

ok! (retarded) idea #1: check if $pkanscore[1] has anything in it. if not, set it as 0.

problem is that i don't know how to say

if $pkanscore[1]=NOTHING then

Edited by GodForsakenSoul

Share this post


Link to post
Share on other sites
if $pkanscore[1]="" then ?

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

if $pkanscore[1]="" then ?

thank you good sir, i am now going to headdesk for 45 minutes, as i clearly saw this coming. ;)

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