Solved

Strange Syntax error on a VBScript Class definition

Posted on 2006-11-01
4
658 Views
Last Modified: 2012-06-21
I am having problems with a class definition in VBScript. I am getting a syntax error for no apparent reason. This is the code that gives the error:

Class FastString
      
      Dim stringArray,growthRate,numItems
      
      Private Sub Class_Initialize()
            growthRate = 50: numItems = 0
            ReDim stringArray(growthRate)
      End Sub
      
      Public Sub Append(ByVal strValue)
            ' Next line will prevent type mismatch errors if item is null. Performance hit is negligible
            strValue=strValue & ""
            If numItems > UBound(stringArray) Then       ReDim Preserve stringArray(UBound(stringArray) + growthRate)
            stringArray(numItems) = strValue:numItems = numItems + 1
      End Sub
      
      Public Sub Reset
            Erase stringArray
               Class_Initialize
         End Sub
      
      Public Function concat()
            Redim Preserve stringArray(numItems)
            concat = Join(stringArray, "")
      End Function
      
End Class

As I said I don't see what is wrong with this. However I get a Syntax Error from this the "Class FastString" line. Now this is code that has been used before without such an error, so I'm baffled. Please Help
0
Comment
Question by:thedwalker
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Preece
ID: 17850692
Do you need () after:

Public Sub Reset

Preece
0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 17850699
The code is fine. Make sure that this code is not put in incorrect place like in between a if...end if block or function... end function or another class.... end class.
0
 
LVL 1

Author Comment

by:thedwalker
ID: 17850745
Would it matter if this is included in a file that is in an if...end if statement?
0
 
LVL 58

Expert Comment

by:amit_g
ID: 17850942
Yes. You can't do that. The include files are included before any line is executed. So before any line is executed you end up having a class definition in between in...end if which is incorrect.

Why do you need a class definition inside a if logic? The code that creates the class object and calls method in it should be in the if block not the class itself.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

15 Experts available now in Live!

Get 1:1 Help Now