Jump to content
Sign in to follow this  
ioliver

Trouble with Array's

Recommended Posts

ioliver

Ok, here's my code:

While 2
  $strEngTitle = WinGetTitle("")
  $arrayEngTitle = StringSplit($strEngTitle, chr(32))
  For $x = 1 to UBound($arrayEngTitle)
    Call("Translate")
  Next
  For $x = 1 to UBound($arrayEngTitle)
    $strSpaTitle = $strSpaTitle & $arrayEngTitle[$x] & " "
  Next
  WinSetTitle($strEngTitle, "", $strSpaTitle)
Wend

Func Translate()
  StringLower($arrayEngTitle)
  Select
    Case $arrayEngTitle[$x] = "windows"
      $arrayEngTitle[$x] = "ventanas"
    Case $arrayEngTitle[$x] = "notepad"
      $arrayEngTitle[$x] = "nota tableta"
  EndSelect
EndFunc

I get an error message (dimension range exceeded) when I run this script. I'm sure the problem is using the $arrayEngTitle[$x] in the Function. But I don't know what the problem could be. Any suggestions would be great.

Thanks again for all your help,

Ian

Edited by ioliver

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites
Jos

Ok, here's my code:

StringLower($arrayEngTitle)

<{POST_SNAPBACK}>

This doesn't look right.

Its missing the [.] and the result goes no where...

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Jos

For $x = 0 to (UBound($arrayEngTitle) - 1)

<{POST_SNAPBACK}>

I guess with stringsplit it should be:

For $x = 1 to (UBound($arrayEngTitle) - 1)

or

For $x = 1 to $arrayEngTitle[0]


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
ioliver

Thanks, here's the new code:

While 2
  $strEngTitle = WinGetTitle("")
  $arrayEngTitle = StringSplit($strEngTitle, chr(32))
  For $x = 0 to (UBound($arrayEngTitle) - 1)
    Call("Translate")
  Next
  For $x = 0 to (UBound($arrayEngTitle) - 1)
    $strSpaTitle = $strSpaTitle & $arrayEngTitle[$x] & " "
  Next
  WinSetTitle($strEngTitle, "", $strSpaTitle)
Wend

Func Translate()
  $arrayEngTitle1 = StringLower($arrayEngTitle[$x])
  Select
    Case $arrayEngTitle1 = "windows"
      $arrayEngTitle[$x] = "ventanas"
    Case $arrayEngTitle1 = "notepad"
      $arrayEngTitle[$x] = "nota tableta"
  EndSelect
EndFunc

I added you suggestions and the Script doesn't blow up anymore, but it also doesn't work the way I intended it to.

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites
ioliver

Thanks Larry...

It's not an important script anyway. I'm just trying to kill time, and improve my AutoIt skills.

Ian

Edit: Added, and improve my AutoIt skills...

Plus, it is stupid question day anyway...

Edited by ioliver

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites
Jos

Thanks Larry... 

It's not an important script anyway.  I'm just trying to kill time, and improve my AutoIt skills.

Ian

Edit: Added, and improve my AutoIt skills...

Plus, it is stupid question day anyway...

<{POST_SNAPBACK}>

- stupid question day was yesterday.... :)

- believe he's trying to make a point here.. like what did you do to debug it?


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
ioliver

- stupid question day was yesterday....    :)

- believe he's trying to make a point here..  like what did you do to debug it?

<{POST_SNAPBACK}>

You're right... I haven't done anything, I guess I was just looking for a handout. I'll look into is some more.

Thanks again,

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites
scriptkitty

Just a bit of FYI:

$arrayEngTitle = StringSplit($strEngTitle, chr(32))
 For $x = 1 to UBound($arrayEngTitle)

Stringsplit automatically gives the ammount of elements -1 to [0]

so you can also use this as well as removing 1 from the ubound:

$arrayEngTitle = StringSplit($strEngTitle, chr(32))
 For $x = 1 to $arrayEngTitle[0]

Dim $Array[2] has two elements

$Array[0]

$Array[1]

that is why Ubound($Array)=2

and for $x=1 to Ubound($Array) would cause you problems in that part.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites
scriptkitty

Well since it seems these days to be unknown, I cheat. There is a very highly secretive little place where all this info and more are held. We Gurus in the field make sure that this kind of information never gets out to the public. The way we do that is to hide it in a "help file" or as others call it, a "Manual." The thought of reading anything called a Manual that might offer help is strickly forbidden in many cultures and cliques. The best place to hide something is in plain sight, so we have hidden all this and more where no one would ever dare to look.....

on a side note though, many obvious things are often missed by very smart people. This is the "can't see the forest because of all the trees" symptom. And cleaning up code, alternate approaches, and a new way of looking at solving a problem are things I really enjoy.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites
ioliver

Thanks scriptkitty. With you suggestions, it's working a little better. I'm going to keep working with it. Of course, I'll need a better English to Spanish Dictionary :)

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

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  

×