[Gambas-user] String array empty after SUB (Gambas 2)
Rolf-Werner Eilert
eilert-sprachen at ...221...
Thu Feb 23 09:13:04 CET 2012
Am 22.02.2012 20:26, schrieb GMail:
> On Wed, 2012-02-22 at 19:49 +0200, Jussi Lahtinen wrote:
>> Just quick thought... maybe this "felder = feld.Copy()" gives new object
>> reference feld to felder.
>> And because feld is declared locally, the it is null after the sub and so
>> is also felder.
>>
>> Perhaps you need to do "felder = feld.Copy()" manually with for each...
>>
>> Jussi
>>
>>
>>
>>
>> On Wed, Feb 22, 2012 at 18:41, Rolf-Werner Eilert<
>> eilert-sprachen at ...221...> wrote:
>>
>>> Now, this is a strange one :-) and I really have no idea what goes wrong
>>> here.
>>>
>>> I've got a dialog which loads a list of names. I'm keeping such SUBs
>>> that deal with files in a module called ldsv (brief for load-save).
>>>
>>> The dialog's part is simple, "ls" is the listbox:
>>>
>>> PRIVATE felder AS NEW String[]
>>>
>>> PUBLIC SUB ls_Click()
>>>
>>>
>>> Label1.Text = "Nr. "& schlyssel[ls.Index]& ": "& ls[ls.Index].Text
>>> 'here we jump into the SUB:
>>> ldsv.ListeKundeFelder(schlyssel[ls.Index], felder)
>>> 'now we should see the number of fields loaded:
>>> lblTitel.Text = CStr(felder.Count)
>>>
>>> END
>>>
>>>
>>> Now the SUB in module ldsv:
>>>
>>> PUBLIC SUB ListeKundeFelder(schlysselnr AS String, felder AS String[])
>>> DIM t$ AS String
>>> DIM feld AS NEW String[]
>>>
>>> felder.Clear
>>>
>>> t$ = File.Load(pfadKunden&/ schlysselnr& ".kunde")
>>> t$ = Tag2Str(t$)
>>>
>>> feld = Split(t$, Chr$(10))
>>>
>>> IF feld[0] = "#!Stein3.1" THEN
>>> feld.Delete(0, 2) 'das #! und die ID können weg
>>> felder = feld.Copy()
>>> END IF
>>>
>>> END
> Perhaps ... If feld[0]<> "#!Stein3.1" then felder=feld.Copy is never
> executed! Try
>
> IF feld[0] = "#!Stein3.1" THEN
> feld.Delete(0, 2) 'das #! und die ID können weg
> END IF
> felder = feld.Copy()
>
This was my first thought, too. But when I checked the values at the
time of END IF, everything was as expected. Jussi had the right idea:
the problem is the .Copy itself. Maybe we should mention this in the
docs, within the text for .Copy for instance.
Rolf
More information about the User
mailing list