|
Post by AbsoluteGenius on Apr 21, 2004 17:55:07 GMT -5
Here is a much smaller and simpler peice of code Function HexLength(ByVal sString As String) As String Dim sHexValue As String
sHexValue = Hex(Len(sString)) HexLength = String(8 - Len(sHexValue), "0") & sHexValue & sString
End Function
Use is same as Webs but i made it easier
|
|
|
Post by Webagent on Apr 22, 2004 14:50:37 GMT -5
Function PrependHexLen(ByVal str As String) As String PrependHexLen = String$(8 - Len(Hex$(Len(str))), "0") & Hex$(Len(str)) & str End Function ok beat that
|
|
Hawk
New Member
Posts: 6
|
Post by Hawk on Apr 22, 2004 15:02:20 GMT -5
Since we are all being Nit-picky.... That's really just the same thing crammed onto one line Actually, it is less efficient that way because you are doing the same operation twice. It would be better to cache it to a variable to use. (Hex$(Len(str)))
|
|
|
Post by Webagent on Apr 22, 2004 15:14:33 GMT -5
just trying to tease lol but mine still would be little faster because AG's function use a variant... if u r nit-piking
|
|
|
Post by Webagent on Apr 22, 2004 16:15:09 GMT -5
Sub PrependHexLen(ByRef str As String) Dim iBeforeLen As Integer, iAfterLen As Integer iBeforeLen = Len(str) str = Hex$(Len(str)) & str iAfterLen = Len(str) str = String$(8 - (iAfterLen - iBeforeLen), "0") & str End Sub this function reduces the over head of string creation in the memory.... ok now beat that
|
|
|
Post by AbsoluteGenius on Apr 22, 2004 16:15:41 GMT -5
Ok, just to pick more where is the Variant? ?? or is that the String( instead of String$(
|
|
|
Post by AbsoluteGenius on Apr 22, 2004 16:20:07 GMT -5
Sub PrependHexLen(ByRef str As String) Dim iBeforeLen As Integer, iAfterLen As Integer iBeforeLen = Len(str) str = Hex$(Len(str)) & str iAfterLen = Len(str) str = String$(8 - (iAfterLen - iBeforeLen), "0") & str End Sub this function reduces the over head of string creation in the memory.... ok now beat that Still getting picky? your code should actually be Sub PrependHexLen(ByRef str As String) Dim iBeforeLen As Long, iAfterLen As Long
iBeforeLen = Len(str) str = Hex$(Len(str)) & str iAfterLen = Len(str) str = String$(8 - (iAfterLen - iBeforeLen), "0") & str End Sub
Use Longs they are quicker than Integers
|
|
|
Post by Chuck on Apr 22, 2004 16:36:50 GMT -5
fighting on small things, hmmmmmmmmmm..... shame shame
|
|
|
Post by Webagent on Apr 22, 2004 16:38:28 GMT -5
lol who dont say I'm not on a 16 bit computer?
|
|
Hawk
New Member
Posts: 6
|
Post by Hawk on Apr 22, 2004 18:39:34 GMT -5
I have to agree with AG... Longs actually speed things up quite a bit. Especially in For Loops. In this case, it really doesn't matter, but for the sake of efficient programming, use of longs are best.
You could speed things up further by making this code inline, rather than a function.
|
|
|
Post by Chuck on Apr 23, 2004 1:54:33 GMT -5
16-bit integer will work faster on 16-bit system. Long works faster on 32-bit systems because memory blocks are 32-bit long, so they don’t need extra operation to adjust the memory.
In the case of loops, it makes sense, because the effects are multiplied by the number of loops.
Inline code saves the overhead of function call, but it doesn’t always results in increased performance. Too much inline code creates “code bloat” which has a negative impact on performance.
|
|
|
Post by Dangermouse on Apr 23, 2004 3:45:27 GMT -5
Wouldnt using Long's use more memory than you need..i thought that was the point of data types, to declare your vars to the data type you are going to fill them with?
|
|
|
Post by Chuck on Apr 23, 2004 6:25:48 GMT -5
Wouldnt using Long's use more memory than you need..i thought that was the point of data types, to declare your vars to the data type you are going to fill them with? First, don't pay attention to this nit-picky discussion, the speed difference on this function won't be visible to users on todays PCs. Second, you are right, but in certain speed critical situations programmer might use the fastest option. e.g. if your program search in 20,000 records, it is better to use long for indexing.
|
|
Tewl
xTeam
C# & VB Developer
Posts: 495
|
Post by Tewl on Apr 26, 2004 21:07:11 GMT -5
please do not post comments not related to topic
|
|
|
Post by anthrax on Apr 27, 2004 9:47:22 GMT -5
please do not post comments not related to topic the sweeping hand of authority ;D
|
|