Jump to content

Trouble with Array's


ioliver
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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]

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Developers

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?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

- 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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...