VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Expected Optional Error

1 REPLY 1
Reply
Message 1 of 2
herrg
367 Views, 1 Reply

Expected Optional Error

I have switched from AutoCAD 2013/64 bit to AutoCAD 2014/64 bit, and get an error on the following code that says "Expected Optional".  I cannot figure out what needs to change.  Private functions I have changed to PtrSafe Functions, but I think this one is causing problems because it is a public Function.

 

Please Help.

 

Thanks,

 

Option Explicit
 
Public Function StripOutCharType(CheckStr As String, Optional KillNumbers As Boolean = True, _
    Optional AllowedChar As String, Optional NeverAllow As String)
     
     ' The AllowedChar and NeverAllow arguments are *not* case-sensitive
    
    Dim Counter As Long
    Dim TestChar As String
    Dim TestAsc As Long
    
     ' Loop through characters
    For Counter = 1 To Len(CheckStr)
        
        ' Get current character and its ANSI number
        TestChar = Mid(CheckStr, Counter, 1)
        TestAsc = Asc(TestChar)
        
        ' Test first to see if current character is never allowed
        If InStr(1, NeverAllow, TestChar, vbTextCompare) > 0 Then
        ' do nothing
            
        ' If current character is in AllowedChar, keep it
        ElseIf InStr(1, AllowedChar, TestChar, vbTextCompare) > 0 Then
            StripOutCharType = StripOutCharType & TestChar
            
        ' If KillNumbers=True, test for not being in numeric range for ANSI
        ElseIf KillNumbers Then 'only allow non-numbers
            If TestAsc < 48 Or TestAsc > 57 Then
                StripOutCharType = StripOutCharType & TestChar
            End If
            
        ' If KillNumbers=False, test for being in numeric ANSI range
        Else 'only allow numbers
            If TestAsc >= 48 And TestAsc <= 57 Then
                StripOutCharType = StripOutCharType & TestChar
            End If
        End If
    Next
    
End Function

1 REPLY 1
Message 2 of 2
Alfred.NESWADBA
in reply to: herrg

Hi,

 

when do you get the error? Did you try to start anything or is that in the middle of any running code or when loading your module or ...?

And just because the phrase "Expected Optional" is part of the code: have you tried the declaration of your function "StripOutCharType" without the 2 "Optional" parameters?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost