Jump to content
Sign in to follow this  
Cherenkov

Array + loop

Recommended Posts

Cherenkov

Hello,

$var1=(1,2,3,4,5,...m)
$var2=(1,2,3,4,5,...,n)
Do
   $var=$var1+$var2
   msgbox(0,"result",$var)
Until(ends after n desired times)

First problem:

I want $var1 & $var2 to change of value every loop.

The first time the operation will be: 1+1 and the msgbox will display 2

The second time 2+2, 4

Etc.

How can the code do that?

Let`s imagine I want the code to stop after n operations (that I determined with an inputbox), what is the condition I have to put inside until()? I imagine it is a counter but I don`t known how to count every loop...

Share this post


Link to post
Share on other sites
Nessie

Seems to be a work for For statement:

For $i = 0 To 10
    MsgBox(0, "Loop number", "Loop Number: " & $i)
Next
MsgBox(0, "", "Blast Off!")

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites
Cherenkov

Sorry, I didn`t mean this.

That would work if the value was between 0 to 10 but in my case the values are not a logical set.

I have 4 digits values.

Forget $var1=(1,2,3,...,n) let`s say $var1=(1134,2254,3463,4345, etc.) same for $var2, four digits with no logical suite.

Edited by Cherenkov

Share this post


Link to post
Share on other sites
Nessie

Maybe it's me and my bad english, but i dont really understand what you want to do :P

Hi!


My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites
BrewManNH

You'd need to use arrays for that, otherwise the value won't change. Put the values for $var1 and $var2 into their own arrays.


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

Share this post


Link to post
Share on other sites
Cherenkov

Like this by example?

Global $var1[3][1] = [ _

[1225], _

[1221], _

[1295] _

]

Global $var2[3][1]=[ _

[3745], _

[5453], _

[5650] _

]

Edited by Cherenkov

Share this post


Link to post
Share on other sites
czardas

Or this?

Global $aVars[5] = [1000,1111,1234,1112,2121]

For $i = 0 To 4
    MsgBox(0, "", $aVars[$i])
    For $j = 0 To 4
        $aVars[$i] *= 2
        MsgBox(0, "", $aVars[$i])
    Next
Next

You were adding the same value to itself in the first post. That's why I used multiplication by 2. I don't get the random numbers part. Are you adding them to themselves or to other values?

I meant to add this to my previous post, but the forum software messed up the script.

Edited by czardas

Share this post


Link to post
Share on other sites
nitekram

Try this?

$var1= '1,2,3,4,5'
$var2= '1,2,3,4,5'
$avar1 = StringSplit($var1, ',')
$avar2 = StringSplit($var2, ',')
For $x = 1 To UBound($avar1) - 1
      $varA = $avar1[$x] + $avar2[$x]
      msgbox(0,"result",$varA)
Next

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
Cherenkov

Or this?

Global $aVars[5] = [1000,1111,1234,1112,2121]

For $i = 0 To 4
MsgBox(0, "", $aVars[$i])
For $j = 0 To 4
$aVars[$i] *= 2
MsgBox(0, "", $aVars[$i])
Next
Next

You were adding the same value to itself in the first post. That's why I used multiplication by 2. I don't get the random numbers part. Are you adding them to themselves or to other values?

I meant to add this to my previous post, but the forum software messed up the script.

You are a genius, seems to be working! :)

Not working as intented in my code but it does now change the variable! I am very very happy, thank you!

Edited by Cherenkov

Share this post


Link to post
Share on other sites
kylomas

Cherenkov,

Example using different size arrays with numbers at varying offesets. Code is rough and needs more error checking but

should be enough to build on.

; *** Start added by AutoIt3Wrapper ***
#include <Constants.au3>
; *** End added by AutoIt3Wrapper ***

#AutoIt3Wrapper_Add_Constants=n

local $var1[100]=[1898,2,3,4,532,'','','',437]
local $var2[9]=[310,2,3,4,111,'','','',8859]

local $stop_num = inputbox('Add Array Offsets','Enter Limit')


for $1 = 0 to ubound($var1) - 1

    if $1 > $stop_num - 1 then ExitLoop                 ; if number of tries exceded then exit
    if stringlen($var1[$1]) < 1 then continueloop       ; if no value in source #1 then try next offset
    if ubound($var2 - 1) < $1 then exitloop             ; if out of range then exitloop
    if stringlen($var2[$1]) < 1 then continueloop       ; if no value in source #2 then try next offset

    msgbox($mb_ok,'Total at Offset ' & $1,$var1[$1] + $var2[$1])

next

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
czardas

Not working as intented in my code but it does now change the variable! I am very very happy, thank you!

I'm glad the code helped you. Once you get an idea how to approach a problem, you're half way towards solving it. :)

Edited by czardas

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  

×