Solved

Strange Syntax error on a VBScript Class definition

Posted on 2006-11-01
4
663 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

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

Suggested Solutions

Title # Comments Views Activity
How do i Properly Convert Date time String in C# 29 66
Dreamweaver server behavior gone 6 112
Forcing form refresh - classic ASP 7 59
XML Parsing Classic ASP 5 50
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

910 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

19 Experts available now in Live!

Get 1:1 Help Now