|
-
Aug 29th, 2000, 12:03 PM
#1
Thread Starter
New Member
Why would you use Mid$ when parsing a string? I am not sure what the $ does?
-
Aug 29th, 2000, 12:05 PM
#2
Fanatic Member
The $ indicates string. Mid$ only works with strings and Mid also works with other data types. (I'm not sure which others) Therefore, Mid$ is faster.
-
Aug 29th, 2000, 08:17 PM
#3
Member
Ah the good ol' days of DOS
Back in the day, $ used to indicate a string(text) variable in basic, coincidently, you can still use it to declare a string variable.
The functions are identical in code, the only reason Mid$ is faster is because the variables are explicitly declared as string and therefore don't have to be converted from a variant to whatever which takes that extra few nanoseconds.
-
Aug 29th, 2000, 08:32 PM
#4
Guru
Here's the whole deal. 
I'm almost sure it's correct, however, do some tests because I sort of "forgot" to 
But the differences are very small, so it only matters if you use very large strings and/or quantities of strings. 
Code:
' Fastest:
Dim A As String
A = Mid$(MyText, X, Y)
' Following two are the same speed:
Dim A As String
A = Mid(MyText, X, Y) ' This is what I always use! :)
Dim A As Variant
A = Mid$(MyText, X, Y)
' Slower:
Dim A As Variant
A = Mid(MyText, X, Y)
' Slowest:
' No Option Explicit and no Dim
A = Mid(MyText, X, Y)
-
Aug 30th, 2000, 03:35 AM
#5
transcendental analytic
Hehe yonatan, how do you know it's slower to return variant into a variant - because that's what i've been doing if i use Mid, not Mid$. Well, should do some tests, but not on this comp
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 30th, 2000, 05:38 AM
#6
-
Aug 30th, 2000, 06:04 AM
#7
transcendental analytic
eh? convert a variant back to a variant? my thought was that you don't have to convert the variant you get in return but it has to be converted to a string if it's assigned to a string.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 30th, 2000, 06:09 AM
#8
_______
<?>
Code:
$ = String
% = Integer
& = Long
! = Single
# = Double
@ = Currency
(Nothing) = Variant
Shortcuts for declaration of strings
Dim Art$ is the same as Dim Art As String
Dim intCre% is the same as Dim intCre as Integer
etc.
dim Art is the same as Dim Art As Variant
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 30th, 2000, 06:37 AM
#9
If you don't use Option Explicit in your code all assignments are slower even if you have declared your variables.
This is because of the fact that VB has to check if the variable is declared or not during run-time. If it's not declared VB create it in the form of a Variant.
When you use Option Explicit this check isn't necessary during run-time because it's done during the compile.
-
Aug 30th, 2000, 07:03 AM
#10
_______
<?>
If you go to tools/options/editor in VB and tick off Require variable declaration and then you can't forget to put in option explicit
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
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
|