Sign in to follow this  
Followers 0
meisandy

Arrays being strange with a method

9 posts in this topic

Hi all

My minds boggling at the minute, I'm stuck with a really strange problem.

First of all - I'm using the bellow script to find matches in a 2D array and replace them (You'll see what I mean):

$pos = 1
$result = ""
While 1
    For $i = 0 To UBound($Fdic)-1
        $len = StringLen($Fdic[$i][0])
        ToolTip($Fdic[$i][0], 0, 0)

        If StringMid($translateMe, $pos, $len) = $Fdic[$i][0] Then
            $result &= $Fdic[$i][1]
            $pos += $len
            ExitLoop
        EndIf
    Next

    If $pos >= StringLen($translateMe) Then
        ExitLoop
    EndIf
WEnd


ConsoleWrite($result & @CRLF)

I DO NOT Want to change this because it works brilliantly! But only when I declare the values of the array like this:

Dim $Fdic[7][2] = [["pedant que", "while"], ["Pedant", "yyyyyyyyyy"], ["que", "xxxx"], ["Lol", "Laugh out Loud"], ["WUU2", "What you up to" ], ["Bonjour hola", "Hi (SP ET FR)"], [" ", " "]]

Therefore if I declare the elements of the array like bellow which is how I need to because the data will be a varible, or any other way it doesn't work!

Dim $Fdic[7][2]
$Fdic[0][0] = "pedant que"
$Fdic[0][1] = "while"
$Fdic[1][0] = "Pedant"
$Fdic[1][1] = "yyyyyyyyyyy"
$Fdic[2][0] = "que"
$Fdic[2][1] = "xxxx"
$Fdic[3][0] = "Lol"
$Fdic[3][1] = "Laugh out Loud"
$Fdic[4][0] = "WUU2"
$Fdic[4][1] = "What you up to"
$Fdic[5][0] = "Bonjour hola"
$Fdic[5][1] = "Hi (SP ET FR)"
$Fdic[6][0] = ""
$Fdic[6][1] = ""

So, any idea's

- Thanks in advance

Share this post


Link to post
Share on other sites



I don't see that you are correct, unless you can tell me what the difference is between the two results.

Dim $Fdic[7][2] = [["pedant que", "while"], ["Pedant", "yyyyyyyyyy"], ["que", "xxxx"], ["Lol", "Laugh out Loud"], ["WUU2", "What you up to" ], ["Bonjour hola", "Hi (SP ET FR)"], [" ", " "]]
for $n=0 to 6
    ConsoleWrite($Fdic[$n][0] & ', ' & $fdic[$n][1] & @CRLF)
Next
ConsoleWrite('---------------------- Try second way--------' & @CRLF)
Dim $Fdic[7][2]
$Fdic[0][0] = "pedant que"
$Fdic[0][1] = "while"
$Fdic[1][0] = "Pedant"
$Fdic[1][1] = "yyyyyyyyyyy"
$Fdic[2][0] = "que"
$Fdic[2][1] = "xxxx"
$Fdic[3][0] = "Lol"
$Fdic[3][1] = "Laugh out Loud"
$Fdic[4][0] = "WUU2"
$Fdic[4][1] = "What you up to"
$Fdic[5][0] = "Bonjour hola"
$Fdic[5][1] = "Hi (SP ET FR)"
$Fdic[6][0] = ""
$Fdic[6][1] = ""

for $n=0 to 6
    ConsoleWrite($Fdic[$n][0] & ', ' & $fdic[$n][1] & @CRLF)
Next

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Martin,

If you read my post thoroughly, I'm sure my problem was when I used in the code that I first showed you.

I realize that it makes no difference to how it looks!

Any more help?

EDIT: The difference in the results is that StringMid doesn't match any strings and so just keeps looping and never stops!

Edited by DjATUit

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Martin,

If you read my post thoroughly, I'm sure my problem was when I used in the code that I first showed you.

I realize that it makes no difference to how it looks!

Any more help?

You could have made it clearer in your initial post and provide a script that demonstrates your issue.

Jos

Edited by Jos

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

Share this post


Link to post
Share on other sites

Sorry, if I'm un clear,

Just in case here is a script with all the required info:

Dim $Fdic[7][2] = [["pedant que", "while"], ["Pedant", "yyyyyyyyyy"], ["que", "xxxx"], ["Lol", "Laugh out Loud"], ["WUU2", "What you up to" ], ["Bonjour hola", "Hi (SP ET FR)"], [" ", " "]]
;-----------The Above will work - but if you declare it....--------------------
;~ Dim $Fdic[7][2]
;~ $Fdic[0][0] = "pedant que"
;~ $Fdic[0][1] = "while"
;~ $Fdic[1][0] = "Pedant"
;~ $Fdic[1][1] = "yyyyyyyyyyy"
;~ $Fdic[2][0] = "que"
;~ $Fdic[2][1] = "xxxx"
;~ $Fdic[3][0] = "Lol"
;~ $Fdic[3][1] = "Laugh out Loud"
;~ $Fdic[4][0] = "WUU2"
;~ $Fdic[4][1] = "What you up to"
;~ $Fdic[5][0] = "Bonjour hola"
;~ $Fdic[5][1] = "Hi (SP ET FR)"
;~ $Fdic[6][0] = ""
;~ $Fdic[6][1] = ""
;--------------Like that - it doesn't work in the method bellow-----------------
Dim $translateMe = "pedant que pedant que pedant pedant que que que pedant bonjour hola"
$pos = 1
$result = ""
While 1
    For $i = 0 To UBound($Fdic)-1
        $len = StringLen($Fdic[$i][0])
        ToolTip($Fdic[$i][0], 0, 0)

        If StringMid($translateMe, $pos, $len) = $Fdic[$i][0] Then
            $result &= $Fdic[$i][1]
            $pos += $len
            ExitLoop
        EndIf
    Next

    If $pos >= StringLen($translateMe) Then
        ExitLoop
    EndIf
WEnd


ConsoleWrite($result & @CRLF)
;=====================================

So, any help please....

???

Share this post


Link to post
Share on other sites

Debugging revealed that you set the last value differently and should be:

$Fdic[6][0] = " "
$Fdic[6][1] = " "

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

Share this post


Link to post
Share on other sites

HaHa, FANTASTIC, it's amazing how picky things like that are!

Thanks

PS How do you debug - is it by setting a varible to True or something? I can't really remember!

Share this post


Link to post
Share on other sites

HaHa, FANTASTIC, it's amazing how picky things like that are!

Thanks

PS How do you debug - is it by setting a varible to True or something? I can't really remember!

Make sure you have the full SciTE4AutoIt3 installed and used Alt+D after selecting the Variables you want to see during the process.

This will generate consolewrite() lines in your script displaying this info in teh Outputpane of SciTE.

Jos


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

Share this post


Link to post
Share on other sites

Make sure you have the full SciTE4AutoIt3 installed and used Alt+D after selecting the Variables you want to see during the process.

This will generate consolewrite() lines in your script displaying this info in teh Outputpane of SciTE.

Jos

Oh thank you Jos

Much appriciated

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