Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Mid$ magic Posted by BitByBit_Thor on 5 Jan 2007 at 7:53 AM
Am I the only one flabbergasted here?

Dim sText As String

sText = "Hello I am John"
Mid$(sText, 12, 4) = "Mark"
MsgBox sText

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
Report
Re: Mid$ magic Posted by iwilld0it on 5 Jan 2007 at 12:58 PM
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?
:
:
: Dim sText As String
: 
: sText = "Hello I am John"
: Mid$(sText, 12, 4) = "Mark"
: MsgBox sText
: 

: 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
:

Report
Re: Mid$ magic Posted by BitByBit_Thor on 6 Jan 2007 at 5:29 AM
: 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

Report
Re: Mid$ magic Posted by dokken2 on 8 Jan 2007 at 12:01 PM
: : 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.
Report
Re: Mid$ magic Posted by BitByBit_Thor on 8 Jan 2007 at 12:10 PM
:
: 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

Report
Re: Mid$ magic Posted by Jonathan on 10 Jan 2007 at 2:40 PM
: 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.");

Report
Re: Mid$ magic Posted by BitByBit_Thor on 10 Jan 2007 at 3:14 PM
: 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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.