Home All Groups Group Topic Archive Search About
Author
7 Jun 2005 9:27 AM
Jimbo Jim
sb = New StringBuilder
sb.Append(vbNewLine)
sb.Append("function init() {")
sb.Append(vbNewLine)
sb.Append("ModuleMenu = new TRMenu.TRMenu();")
sb.Append(vbNewLine)
sb.Append("ModuleMenu.Add('Modules',0,'ModuleMenuList');")

Or

sb = New StringBuilder
sb.Append(vbNewLine & "function init() {" & vbNewLine & "MMenu = new
Menu.Menu();" & vbNewLine & "ModuleMenu.Add('Modules',0,'ModuleMenuList');")

I've been told that the first method of joining a string is definately a
better way of programming. Is this correct? To me it seems like more work to
for the same result.

Author
7 Jun 2005 10:05 AM
Cor Ligthert
Jimbo,

I find definitly the first way much nicer, however the compiler optimizes
the second way.

I hope this helps,

Cor
Are all your drivers up to date? click for free checkup

Author
7 Jun 2005 3:47 PM
Jimbo Jim
Thanks for your reply.
So for instance:
s = New StringBuilder
s.Append(vbNewLine)
s.Append(vbNewLine)
s.Append("function init() {")
s.Append(vbNewLine)
s.Append("MMenu = new Menu.Menu();")
s.Append(vbNewLine)
s.Append(vbNewLine)
s.Append("MMenu.Add('Modules',0,'MMenuList');")
If something Then
s.Append(vbnewline)
s.Append("and add this:")
s.Append("then this")
End If

Runs better like this:

s = New StringBuilder
s.Append(vbNewLine & "function init() {" & vbNewLine & "MMenu = new
Menu.Menu();" & vbNewLine & "ModuleMenu.Add('Modules',0,'ModuleMenuList');")

If something Then s.Append(vbnewline & "and add this: then this")

The reason I ask is that our .Net programmer had created a program that I'm
guessing has way to many ".Appends" when they are not needed. I could
probably reduce the amount of code by a few houndred lines.



Show quoteHide quote
"Cor Ligthert" wrote:

> Jimbo,
>
> I find definitly the first way much nicer, however the compiler optimizes
> the second way.
>
> I hope this helps,
>
> Cor
Author
7 Jun 2005 5:05 PM
Cor Ligthert
Jimbo,

The used time is almost the same and in think that the best is in the
middle.


Just my idea

Cor
Author
7 Jun 2005 10:35 AM
Josh
Show quote Hide quote
"Jimbo Jim" <Jimbo***@discussions.microsoft.com> wrote in message
news:25BF1A8A-1803-4646-AA6C-09A8DE6AA720@microsoft.com...
> sb = New StringBuilder
> sb.Append(vbNewLine)
> sb.Append("function init() {")
> sb.Append(vbNewLine)
> sb.Append("ModuleMenu = new TRMenu.TRMenu();")
> sb.Append(vbNewLine)
> sb.Append("ModuleMenu.Add('Modules',0,'ModuleMenuList');")
>
> Or
>
> sb = New StringBuilder
> sb.Append(vbNewLine & "function init() {" & vbNewLine & "MMenu = new
> Menu.Menu();" & vbNewLine &
> "ModuleMenu.Add('Modules',0,'ModuleMenuList');")
>
> I've been told that the first method of joining a string is definately a
> better way of programming. Is this correct? To me it seems like more work
> to
> for the same result.
>
I wouldn't use a string builder for the second case ( unless you were going
to continue to append ).  The string builder becomes efficient when append
is used repeatadly

Bookmark and Share