If an array is filled by the Split function, subsequent use of ReDim always emties the array, regardless whether it worked befor. Try this test code (Xray has been used because it easily displays the array; if you don't want to install it, use msgbox arr(0) instead, seeing arr(0) empty will be convincing enough). The Xray calls are numbered to fit the output below. sub test dim s as string, arr(1) as string arr(0) = "aa" arr(1) = "bb" Xray arr '[1] ReDim Preserve arr(1) Xray arr '[2] s = "a/b" arr = Split(s, "/") Xray arr '[3] ReDim Preserve arr(1) Xray arr '[4] arr(0) = "aa" arr(1) = "bb" Xray arr '[5] ReDim Preserve arr(1) Xray arr '[6] end sub Executing this macro you will get: [1] after entering data: correct Tabelle : T( 0 To 1 ) As string (0) | string : "aa" (1) | string : "bb" [2] after ReDim Preserve: correct Tabelle : T( 0 To 1 ) As string (0) | string : "aa" (1) | string : "bb" [3] after assigning the values by Split: correct Tabelle : T( 0 To 1 ) As variant (0) | string : "a" (1) | string : "b" [4] after ReDim Preserve: w r o n g Tabelle : T( 0 To 1 ) As empty (0) | <empty> (1) | <empty> [5] after entering new data: still wrong, even though this should be as in [1] Tabelle : T( 0 To 1 ) As empty (0) | <empty> (1) | <empty> [6] after ReDim Preserve: wrong, consequently Tabelle : T( 0 To 1 ) As empty (0) | <empty> (1) | <empty> So it seems that assigning values to the array by Split does something wrong to the array, such that ReDim Preserve cannot find the correct information.
already reproducible with AOO 4.1.5 it will work if the variable "arr" is a variant, e.g. dim arr() as variant or dim arr()
https://opengrok.libreoffice.org/xref/core/basic/source/runtime/methods1.cxx?r=48314f25#1638 https://opengrok.libreoffice.org/xref/core/basic/source/runtime/methods1.cxx?r=48314f25#1644 Changing these SbxVARIANT to SbxSTRING seems to do the trick, but I'm not sure I'm doing things correctly.
Investigating... ================== REM ***** BASIC ***** Option Explicit sub test dim s as string dim arr(1) as Integer s = "a/b" arr = Split(s, "/") Msgbox(arr(0)) ReDim Preserve arr(1) Msgbox(arr(0)) end sub Showing "a" in Msgbox Functions(though arr is declared as an array of Integer)
Hmmm...It seems the new problem I pointed out was not related to Split function Option Explicit Sub Main Dim a(1) As Integer Dim b(1) As String b = a End Sub runs without error.
Andreas Heinisch committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/698e5d54182d96a1fd0c3b864ba0e618f82dd1f1 tdf#123025 - fixed broken tests for cverr method It will be available in 7.1.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Andreas Heinisch committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/d6b7cc3f7c07b98c90194e8b33cf44b94804b525 tdf#123025 - ReDim Preserve fails if array is filled by Split It will be available in 7.1.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Credits go to himajin100000@gmail.com for pointing out the problem as well.