Array confusion

  1. 5 weeks ago

    Tim K

    Dec 12 Pre-Release Testers, Xojo Pro
    Edited 5 weeks ago
    dim s() As  String
    s= array("bob","sue","fred")
    Break
    dim tmp() As String
    
    tmp=s
    
    tmp.Remove(tmp.IndexOf("bob"))
    Break

    I am trying to remove the element from just tmp but both tmp and s end up with same value with the element removed

    I would think s would be unaffected.

    TIA

    dim s() As  String
    s= array("bob","sue","fred")
    Break
    dim tmp() As String
    for i  as Integer =0 to s.Ubound
      tmp.Append(s(i))
    next
    tmp.Remove(tmp.IndexOf("bob"))
    Break

    Seems to do the trick

  2. Maximilian T

    Dec 12 Pre-Release Testers, Xojo Pro Europe, Germany, Berlin

    https://blog.xojo.com/2018/12/12/what-kind-of-variable-are-you/

  3. Tim K

    Dec 12 Pre-Release Testers, Xojo Pro

    Yep just saw
    in the byval docs

    All arrays and objects are passed by reference, not copied, so changes to that array or object will be reflected in the calling method. This is no different than assigning an array or object to a second variable or property.

  4. Tim K

    Dec 13 Pre-Release Testers, Xojo Pro Answer
    dim s() As  String
    s= array("bob","sue","fred")
    Break
    dim tmp() As String
    for i  as Integer =0 to s.Ubound
      tmp.Append(s(i))
    next
    tmp.Remove(tmp.IndexOf("bob"))
    Break

    Seems to do the trick

or Sign Up to reply!