Jump to content
Sign in to follow this  
Blackstar

Array Element [0]

Recommended Posts

Im trying to update the element[0] count to 18 when there is one new element added to the array...how do I do that? Check the pics below:

Posted Image Posted Image

Share this post


Link to post
Share on other sites

It would be easier for people to help you if you showed some code but here is what I can say without code.

Just set its value like you would any array element,

Dim $Array[5]
$Array[0] = 4
MsgBox(0, "", $Array[0])oÝ÷ Úî±å¢éݶ®¶¶'%ÊÇ­zW¦z{t¶azè¥êì7ºÚ"µÍ[H ÌÍÐ^VÍWBÌÍÐ^VÌHHPÝ[
    ÌÍÐ^JHHBÙÐÞ
    ][ÝÉ][ÝË    ÌÍÐ^VÌJ
Edited by SolidSnake

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Heres the code if it helps.

#include <Array.au3>
#include <File.au3>
Dim $s_Path, $names

$s_Path = @ScriptDir & "\names.txt"
If Not FileExists($s_Path) Then
    MsgBox(4096, "Error!", "names.txt does not exist.")
    Exit
EndIf

_FileReadToArray($s_Path, $names)
_ArrayDisplay($names, "Names ")

_ArrayAdd($names, "Troy Phillips")
_ArrayDisplay($names, "New addition")

$namestring = "Troy Phillips"
if _CheckNames($namestring, $names) then 
    MsgBox(4096, "Found!", "This name " & $namestring & " has been found in array.")
Else
    MsgBox(4096, "Not Found!", "This name " & $namestring & " has NOT been found in array.")
EndIf

Func _CheckNames($s_string, $namesarray)
    For $j = 1 To $namesarray[0]
        $search = $namesarray[$j]
        If Not @error Then
            $result = StringInStr($s_string, $search)
            If $result Then Return True
        EndIf
    Next
EndFunc
Edited by Blackstar

Share this post


Link to post
Share on other sites

and where in this code do you need to resize your array?

Edit: o wait maybe you mean-

#include <Array.au3>
#include <File.au3>
Dim $s_Path, $names

$s_Path = @ScriptDir & "\names.txt"
If Not FileExists($s_Path) Then
    MsgBox(4096, "Error!", "names.txt does not exist.")
    Exit
EndIf

_FileReadToArray($s_Path, $names)
_ArrayDisplay($names, "Names ")

_ArrayAdd($names, "Troy Phillips")
$names[0]=ubound($names)-1
_ArrayDisplay($names, "New addition")

$namestring = "Troy Phillips"
if _CheckNames($namestring, $names) then 
    MsgBox(4096, "Found!", "This name " & $namestring & " has been found in array.")
Else
    MsgBox(4096, "Not Found!", "This name " & $namestring & " has NOT been found in array.")
EndIf

Func _CheckNames($s_string, $namesarray)
    For $j = 1 To $namesarray[0]
        $search = $namesarray[$j]
        If Not @error Then
            $result = StringInStr($s_string, $search)
            If $result Then Return True
        EndIf
    Next
EndFunc
Edited by evilertoaster

Share this post


Link to post
Share on other sites

Hi,

why ReDim?

#include <Array.au3>
#include <File.au3>
Dim $s_Path, $names

$s_Path = @ScriptDir & "\names.txt"
If Not FileExists($s_Path) Then
    MsgBox(4096, "Error!", "names.txt does not exist.")
    Exit
EndIf

_FileReadToArray($s_Path, $names)
_ArrayDisplay($names, "Names ")

_ArrayAdd($names, "Troy Phillips")
$names[0] = UBound($names) - 1
_ArrayDisplay($names, "New addition")

$namestring = "Troy Phillips"
if _CheckNames($namestring, $names) then
    MsgBox(4096, "Found!", "This name " & $namestring & " has been found in array.")
Else
    MsgBox(4096, "Not Found!", "This name " & $namestring & " has NOT been found in array.")
EndIf

Func _CheckNames($s_string, $namesarray)
    For $j = 1 To UBound($namesarray)-1
        $search = $namesarray[$j]
        If Not @error Then
            $result = StringInStr($s_string, $search)
            If $result Then Return True
        EndIf
    Next
EndFunc

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

There is little reason to "build your own" UDF when _AddArray is already built/tested/proven. It has all of the error checking you'll need.

The OP asked how to add to an array and that is what ReDim does. "Resize an existing array"

I saw the OP, I posted the AutoIt function.

Just use the _ArrayAdd UDF like evilertoaster suggested.

The heart of the _ArrayAdd UDF is:

ReDim $avArray[UBound($avArray) + 1]

I did not mean to imply that you needed to change anything - I was just attempting to acknowledge that evilertoaster gave you a better answer than I did.

...sorry for any confusion...


[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  

×
×
  • Create New...