Sign in to follow this  
Followers 0
Celeri

Merging arrays

3 posts in this topic

I'm working on a multi-language program that will read the program text from an .INI file in different languages. And both elements on an INI line are useful to me; the first part would be for the Message Box title and the other for the content.

Now my problem is that in order for my script and .INI to be nice and clear it would be nice to have one section per language ... ie. [English] ... [Français] and so on.

But ReadIniSection only reads a section at a time. And for this to work I need one single array containing all the languages. In other words, I need to merge these 2 dimensional arrays together.

Now I've searched for a while and have yet to find anything. Am I to understand there is no simple way of merging multi-dimentional arrays together (even if they are identical in characteristics)? [Meaning: I have to program it myself?]

Obi Wan Celeri

Here's a sample code that I might use if there's no other way ...

Dim $A[20][2]; Make A$ extra big
Dim $B[10][2]; B$ is obviously smaller ...

$A=IniReadSection("MyIni.ini","English"); Read 1st language
$B=IniReadSection("MyIni.ini","Francais"); Read 2nd Language

$Length_A = Ubound($A); What's the size of $A now?
$Length_B = Ubound($B); And how about $B's size?
For $i = 1 to $Length_B; Loop through the whole $B ...
     $A[$Length_A+$i][0]=$B[$i][0]; Copy first part of array
     $A[$Length_A+$i][1]=$B[$i][1]; Copy second part of array
Next

$B=0; Flush value (recuperate memory)

I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites



I've actually fixed the sample program and made it work OK.

Harder than expected since all the functions in _Array.AU3 seem to apply only to 1 dimension arrays :)

Anyways I'll post the code tonight or tomorrow early so if anyone is interested they'll just have to cut and paste :evil:

Oh and if anyone has a better (and constructive!) idea, I'm all for it :D

Be seeing you

Obi


I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

Ok here it is :)

If anyone can make this better I'd be delighted!

; Requires an INI file called MyFile.ini and containing two sections;
; one called English and the other called Francais.

; Initialisation
$ini="MyInifile.ini"; Change the INI file name if necessary

; Read the information
$A=IniReadSection($ini,"English"); Read 1st language
$B=IniReadSection($ini,"Francais"); Read 2nd Language
_ArrayDisplay_2D($A); show contents (can be removed)
_ArrayDisplay_2D($B);  show contents (can be removed)

; Re-dimension principal array
$Length_A = Ubound($A); What's the size of $A now?
$Length_B = Ubound($B); And how about $B's size?
ReDim $A[$Length_A+$Length_B][2]; Resize to fit both $A and $B

; Transfer from one array to the other
For $i = 1 to $Length_B-1; Loop through the whole $B ...
     $A[$Length_A+$i][0]=$B[$i][0]; Copy first part of array : [n][0]
     $A[$Length_A+$i][1]=$B[$i][1]; Copy second part of array : [n][1]
Next

$B=0; Flush value (recuperate memory)

; Now show the end result
_ArrayDisplay_2D($A); Show final merged array

Exit

Func _ArrayDisplay_2D (ByRef $Array_name); Adapted from _ArrayDisplay
     $sMsg = ""
      For $iCounter = 0 To UBound($Array_name) - 1 
          $sMsg = $sMsg & "[" & $iCounter & "]  = " & StringStripCR($Array_name[$iCounter][0]) & " " & StringStripCR($Array_name[$iCounter][1]) & @CR
     Next
     MsgBox(262144,"",$sMsg); 
EndFunc

So now instead of making a MsgBox per language (!!!) a typical line (with preceding variables) would look like this

$Section_length = 9; Number of entries per section
$Language = 0; Language, from 0 to n, in our case English = 0, Francais = 1
$Current_message = 5; I'm displaying message #5 out of 9

MsgBox(262144,$A[(Section_length*Language)+Current_Message][0],$A[(Section_length*Language)+Current_Message][1])

Hope there's no typos! :evil:


I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

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