Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Mid$ magic

BitByBit_ThorBitByBit_Thor Posts: 2,444Member
Am I the only one flabbergasted here?

[code]
Dim sText As String

sText = "Hello I am John"
Mid$(sText, 12, 4) = "Mark"
MsgBox sText
[/code]
Result is "Hello I am Mark"

(VB6)

Please tell me you are as surprised about this as I am.
Makes me wonder how... My IDE colors Mid$ blue when I put it like this, so maybe it recognised it as a pointer this way?

Best Regards,
Richard

Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    When Mid is on the left-side of the equal sign it is actually a built-in visual basic statement rather than a function call like when it is on the right-hand-side...

    Gotta luv VB's hidden quirks and sometimes non-standard statements


    : Am I the only one flabbergasted here?
    :
    : [code]
    : Dim sText As String
    :
    : sText = "Hello I am John"
    : Mid$(sText, 12, 4) = "Mark"
    : MsgBox sText
    : [/code]
    : Result is "Hello I am Mark"
    :
    : (VB6)
    :
    : Please tell me you are as surprised about this as I am.
    : Makes me wonder how... My IDE colors Mid$ blue when I put it like this, so maybe it recognised it as a pointer this way?
    :
    : Best Regards,
    : Richard
    :

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : Gotta luv VB's hidden quirks and sometimes non-standard statements
    :

    I love 'm!

    Just wish I had known this earlier :( A little hint in the book I learned VB from would've been nice

    Best Regards,
    Richard

  • dokken2dokken2 Posts: 532Member
    : : Gotta luv VB's hidden quirks and sometimes non-standard statements
    : :
    :
    : I love 'm!
    :
    : Just wish I had known this earlier :( A little hint in the book I learned VB from would've been nice
    :
    : Best Regards,
    : Richard
    :
    :

    The on-line help [see also] lists both a Mid func. and a Mid statement, as if its an overloaded operator.
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    :
    : The on-line help [see also] lists both a Mid func. and a Mid statement, as if its an overloaded operator.
    :

    Yeah I found that a couple of minutes after I made the post :)
    I though it might have something to do with secret hidden Variant pointers to strings etc etc :)
    But too bad it was just a hard-coded statement.

    And I was getting all excited about having pointers ^^

    Best Regards,
    Richard

  • JonathanJonathan Posts: 2,914Member
    : But too bad it was just a hard-coded statement.
    :
    I remember it from my VB days, though I'm not sure how I discovered it. I think it maybe worked for Left$ and Right$ too. It's certainly an odd construct - reminds we in part of Perl's lvalue subroutines (basically you assign to a sub call, which magically is returning something assignable, or something weird...)

    : And I was getting all excited about having pointers ^^
    Hehe, not much has changed since I used to post here years ago. :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : I remember it from my VB days, though I'm not sure how I discovered it. I think it maybe worked for Left$ and Right$ too. It's certainly an odd construct - reminds we in part of Perl's lvalue subroutines (basically you assign to a sub call, which magically is returning something assignable, or something weird...)
    :

    Got excited about tht too :) But no, Left and Right are only ever Left and Right.

    : Hehe, not much has changed since I used to post here years ago. :-)
    :
    Wt?! :P
    Best Regards,
    Richard

Sign In or Register to comment.