Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 验证Powerpoint VBA中的字符串内容_String_Validation_Vba_Powerpoint - Fatal编程技术网

String 验证Powerpoint VBA中的字符串内容

String 验证Powerpoint VBA中的字符串内容,string,validation,vba,powerpoint,String,Validation,Vba,Powerpoint,我需要验证用户是否在输入框中输入了大写字母(a-Z)或几个不同的标点符号(,-')。他们只能输入其中一个字符。有人能帮我吗 提前谢谢 大概是这样的: strtest = InputBox("Enter a capital letter or punctuation mark:") If strtest <> [A-Z , ' -] Then MsgBox "Invalid Entry." strtest=InputBox(“输入大写字母或标点符号:”) 如果strtest[A-Z,

我需要验证用户是否在输入框中输入了大写字母(a-Z)或几个不同的标点符号(,-')。他们只能输入其中一个字符。有人能帮我吗

提前谢谢

大概是这样的:

strtest = InputBox("Enter a capital letter or punctuation mark:")
If strtest <> [A-Z , ' -] Then MsgBox "Invalid Entry."
strtest=InputBox(“输入大写字母或标点符号:”)
如果strtest[A-Z,'-]则MsgBox为“无效条目”

像KazJaw一样,我怀疑RegExp可能是最好的选择;但我也没有足够的经验。因此,这里有另一种方法:

Function TestEntry(sTest As String) As Boolean

    Dim bTemp As Boolean
    Dim sOKChars As String
    Dim x As Long

    bTemp = False ' by default
    sOKChars = "!@#$%^&*()_+" ' add/remove chars as appropriate

    If Len(sTest) > 1 Then
        MsgBox "Doggone it, I said ONE character only. Try again."
        ' I'd remove the msgbox and test the Len before passing the 
        ' string to this function, actually
    End If

    If 64 < Asc(sTest) And Asc(sTest) < 91 Then
        bTemp = True
    End If

    If Not bTemp Then
        For x = 1 To Len(sOKChars)
            If Mid$(sOKChars, x, 1) = sTest Then
                bTemp = True
                Exit For
            End If
        Next
    End If

    TestEntry = bTemp

End Function

Sub TestTestEntry()
    If TestEntry(",") Then
        MsgBox "Ok"
    Else
        MsgBox "NOT ok"
    End If

End Sub
函数TestEntry(sTest作为字符串)作为布尔值
作为布尔值的Dim bTemp
暗索克查尔作为字符串
暗x等长
默认情况下,bTemp=False
sOKChars=“!@#$%^&*()_kchars+””根据需要添加/删除字符
如果Len(sTest)>1,则
MsgBox“该死,我只说了一个字符。再试一次。”
在通过测试之前,我会移除msgbox并测试Len
'实际上,是这个函数的字符串
如果结束
如果64
输入框中的
当前代码是什么?我要求提供更准确的建议…我编辑了我的问题,以包括我正在寻找的一个例子。谢谢似乎最好的选择是在您的情况下使用
RegExp
。这里有很多这样的例子。我没有足够的经验来帮助你,但你可以从感谢开始!这起作用了。花的比我想象的要多,但效果很好。