Solved

Some explanation on the code

Posted on 2006-11-14
5
140 Views
Last Modified: 2010-04-30
Can somebody please explain to me what does the below code do?

Class StringClass

 

            'Global Variables

            Private m_array

            Private m_length

            Private m_buffer

            Private m_growthSize

 

            'Constructor (sort of)

            Private Sub Class_Initialize

                        m_array = Array()

                        m_length = 0

                        m_buffer = 0

                        m_growthSize = 32'Dynamically grows inside Append()

            End Sub

 

            'Public Methods

            Public Function Append(ByVal value)

                        Dim ValueLen: ValueLen = Len(value)

                        Do While ValueLen > m_buffer

                                    ReDim Preserve m_array(UBound(m_array) + m_growthSize)

                                    m_buffer = m_buffer + m_growthSize

                                    m_growthSize = m_growthSize * 2

                        Loop

 

                        For i = 0 To ValueLen - 1

                                    m_array(m_length) = Mid(value, i + 1, 1)

                                    m_length = m_length + 1

                                    m_buffer = m_buffer - 1

                        Next

            End Function

 

            'Properties

            Public Property Get Length

                        Length = m_length

            End Property

 

            Public Property Get Text

                        Text = Join(m_array, "")

            End Property

            Public Property Let Text(ByVal value)

                        'Reset the array without reducing the current capacity.

                        m_array = Array(m_length + m_buffer - 1)

                        m_buffer = m_length + m_buffer

                        m_length = 0

                        Append(value)

            End Property

 

End Class

Thanks
Harish
0
Comment
Question by:harishsc
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17939219
Basically it is a VB6 attempt at building a StringBuilder like structure:
http://msdn2.microsoft.com/en-us/library/system.text.stringbuilder.aspx

The hope is that you get better performance when concatenating many strings together.
0
 

Author Comment

by:harishsc
ID: 17939380
Thanks for the response, my problem is, we have been asked to use better tricks for manipulating strings, the below code is asked to use the Class that I posted earlier in my question for string manipulation. Does anybody has any suggestions, I am posting the existing code below.

<%
With o_Rec
      Do while not .EOF
            strShopper = .Fields("community_name").Value
            if IsNull(strShopper) then ''Try using IsNull Here and see if its appropriate
                  if not bolDictExists(o_DiscDict,strShopper) then
                        Set o_DiscDict(strShopper) = Server.CreateObject("Commerce.Dictionary")
                  end if
                  Set objShopperDiscounts = o_DiscDict(strShopper)

                  str_SKU = .Fields("sku").Value
                  if not bolDictExists(objShopperDiscounts,str_SKU) then
                        Set objShopperDiscounts(str_SKU) = Server.CreateObject("Commerce.Dictionary")
                  end if
                  Set objSkuDiscount = objShopperDiscounts(str_SKU)
                  objSkuDiscount("disc_type")  = trim(.Fields("discount_type").Value)
                  objSkuDiscount("disc_value") = trim(.Fields("discount_value").Value)
                  objSkuDiscount("Local_FixedPrice") =trim( .Fields("local_fixed_amount").Value)
                  objSkuDiscount("USD_FixedPrice") = trim(.Fields("fixed_amount").Value)
            End if
            .MoveNext
      Loop
End With
%>
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17940402
I don't see how the StringClass applies to your current code...
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17962829
@harishsc : I dont think you can really change much about your code as far as the strings go.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now