|
-
Dec 22nd, 2024, 10:40 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] why MID$() was featureless in VB6?
My original post, was a mistake.
but, anyway, I tested things that maybe aren't in the help, that is good to know.
mid$(s,2,2) = "bcabrffe" ' will only copy the first two characters. as expected.
mid$(s,2)= "abccdeeff" ' will copy everything and paste it starting from the pointed position. but if the original string length is not large enough, it will only copy what it fits within the original string size
mid$(s,2,5) = "2affbccccc" if not fits, it will be cut, overriding the explicit length to copy, it won't expand the original string size.
A starting offset that is not currently allocated, like S="123":Mid$(S,5,2) = "ab" ' will result in error 5, bad procedure call.
this is the faster way to paste thing where the size of the thing do not change.
Last edited by flyguille; Dec 23rd, 2024 at 06:55 AM.
-
Dec 23rd, 2024, 01:14 AM
#2
Re: why MID$() was featureless in VB6?
Maybe I misunderstood, but this still works.
Code:
A = “ABCDEF”
Mid$(A, 2, 2) = “34”
-
Dec 23rd, 2024, 04:34 AM
#3
Thread Starter
Fanatic Member
Re: why MID$() was featureless in VB6?
 Originally Posted by Arnoutdv
Maybe I misunderstood, but this still works.
Code:
A = “ABCDEF”
Mid$(A, 2, 2) = “34”
ohhhh, right!, I re-tested it, and it works, seeing the copy past, I did a typo in the variable name, and it throw error 5, so, I though that is was featureless, also the quick help only mention it as a function not as a procedure, that also confused me!.
anyway it is interesting enough....
mid$(s,2,2) = "bcabrffe" ' will only copy the first two characters. as espected.
mid$(s,2)= "abccdeeff" ' will copy everything starting from the pointed position. but if the original lenght is not large enough, it will only copy what it fits. mid$(s,2,5) if not fits, it will be cut, overriding the desired length to copy.
this is the faster way, no concatenation, no reassign length, just a single memcopy.
Last edited by flyguille; Dec 23rd, 2024 at 04:43 AM.
-
Dec 23rd, 2024, 04:34 AM
#4
Re: why MID$() was featureless in VB6?
why did u post this before checking yourself?
as the other answered, it works. not sure why they would change its behavior in VB6.
also, always use Mid$ if the type is a string. no point returning a Variant.
another thing is to "understand" how it works
Mid$(s, 2, 2) will change from position 2
so of course "abcd" will change into "azxd"
using Mid$(s, 3, 2) will change from position 3
so it will change "abcd" into "abzx"
-
Dec 30th, 2024, 04:44 PM
#5
Re: [RESOLVED] why MID$() was featureless in VB6?
@flyguille.
VB6 uses BSTR, type of string. This string type normally didn't allow to change bytes inside memory of the string data/characters. So each time you put something in a string VB place a new string, the result. But because VB6 is like a swiss army knife, for all jobs, there are some special functions/subs which change bytes directly on string data.
These are:
1. the LSET which place a string result directly on another string data, but only those that can be written to current size of target string. If we feed something smaller, then spaces placed to not used character places.
2. RET like LSET but the feeding string placed like using right justify.
3. MID$(). Although is a function we can use it like a procedure; Used for 2 bytes or multiple of two bytes
4. MIDB$(). like MID$() but for one byte or multiple of one.
So we can use a BSTR string for UTF16LE or ANSI enconding. The debug.print not know which one we use.
let's place one byte to string A using A=chrb$(65)
So now to read it on immediate window we have to use this:
Debug.Print StrConv(A, vbUnicode)
We can place text using
A=StrConv("This Is Utf16LE", vbFromUnicode).
So now A has bytes for characters at 1:1.
So what wrong with the VB IDE??
The VB IDE is a multilanguage editor, but we have to use one language, for editing our program. So why we call it multilanguage editor? For me which I use Greek names for some string values, I choose from Editor preferences a font with a specific language (Greek). So now the editor render the text (which is saved to file in ANSI form, but without saying which codepage) as the Greek Ansi codepage. Also controls have "rendering" based on the language of font in use.
Inside your code the strings as you feed them with string literals, are UTF16LE (a Unicode encoding). So to make your program to render unicode you have to use the HDC (handler of a form using from many display functions, for rendering text to forms/controls/printers). Also with careful handling of keyboard queue you get the real unicode keys from keyboard. You can use Krools controls for totaly good results.
So my last word here is: To make vb6 programs you have a lot to consider, so for practical use try something else. VB6 is the difficult path.
-
Dec 30th, 2024, 06:50 PM
#6
Re: [RESOLVED] why MID$() was featureless in VB6?
Something else? TwinBasic?
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Jan 9th, 2025, 03:31 PM
#7
Fanatic Member
Re: [RESOLVED] why MID$() was featureless in VB6?
I am trying to comprehend this post?

got nuthin' to do but to make a new project, hype, then give up
Check out all my cool stuff btw
VB: EveryDiscord, a Discord client made fully in VB6 | MSPaint Modifier, a VB6-based MSPaint hooking engine, experimental | OpenIM, a fully VB6 instant messaging service based on TCP/IP connections | Kadooki (Overall the AltWWW project), the WWW re-imagined by me with continuations of HTML3.2's parts. | ClaFeed, A little feed algorithm I have been developing for a Twitter-style system. | CfmOS PC, my project CfmOS ported to VB6 in order to prototype faster, often lags on updates though!
C: LegacyResource, a little ResHacker ripoff | CfmOS, A mobile OS designed to mimic AOSP (Stock Android) on an ESP32-S3, featuring a full bytecode architecture
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|