SSProcess.PushUndoMark
SSProcess.ClearSelectConditionGroups
SSProcess.ClearSelectCondition
SSProcess.ClearSelection
SSProcess.SetSelectCondition "SSObj_Type", "==", "point"
SSProcess.SelectFilter
cnt= SSProcess.GetSelGeoCount
for i=0 to cnt-1[step 2]
id= SSProcess.GetSelGeoValue (i,"SSObj_ID" )
MSGBOX id
next
SSProcess.PushUndoMark
SSProcess.ClearSelectConditionGroups
SSProcess.ClearSelectCondition
SSProcess.ClearSelection
SSProcess.SetSelectCondition "SSObj_Type", "==", "point"
SSProcess.SelectFilter
cnt= SSProcess.GetSelGeoCount
while cnt<>0
id= SSProcess.GetSelGeoValue (cnt-1, "SSObj_ID" )
MSGBOX id
cnt=cnt-1
wend
while-wend 语句在循环中不允许结束,不如我们只想显示前5个点的ID
SSProcess.PushUndoMark
SSProcess.ClearSelectConditionGroups
SSProcess.ClearSelectCondition
SSProcess.ClearSelection
SSProcess.SetSelectCondition "SSObj_Type", "==", "point"
SSProcess.SelectFilter
cnt= SSProcess.GetSelGeoCount
c=0
do while( c<5)
id= SSProcess.GetSelGeoValue (c,"SSObj_ID" )
MSGBOX id
c=c+1
loop
Dim value '定义一个变量
value = 10 '变量赋值为10
Select Case value '判断变量的值大小,如果相等则输出变量值
Case 0 MsgBox 0
Case 1 MsgBox 1
Case 2 MsgBox 2
Case Else MsgBox "数值超出范围!" '如过都不相等,则输出”数值超出范围!”
End Select
定义数组,使用常数定义数组的长度,不能直接使用数值变量定义,如果要使用数值变量,则首先定义一个不带参数的数组,再redim
Dim arr(5)
Dim arrX()
Cnt=9
Redim arrX(Cnt)
SSProcess.ClearSelectConditionGroups
SSProcess.ClearSelectCondition
SSProcess.ClearSelection
SSProcess.SetSelectCondition "SSObj_Type", "==", "POINT"
SSProcess.SelectFilter
cnt= SSProcess.GetSelGeoCount
MSGBOX cnt
dim arrX()
dim arrY()
dim arrZ()
redim arrX(cnt)
redim arrY(cnt)
redim arrZ(cnt)
for i=0 to cnt-1
arrX(i)= SSProcess.GetSelGeoValue (i,"SSObj_X")
arrY(i)= SSProcess.GetSelGeoValue (i,"SSObj_Y")
arrZ(i)= SSProcess.GetSelGeoValue (i,"SSObj_Z")
next
类似于C#里的hashtable,key value
Sub OnClick()
'添加代码将左侧2个房屋的名称设置为4#,编号分别设置为1和2,右侧两栋楼名称设置为5#,编号分别设置为1和2,以名称和编号的组合为key保存每栋楼的建筑面积,并根据key提取4#楼1层的面积
SSProcess.PushUndoMark
SSProcess.ClearSelectConditionGroups
SSProcess.ClearSelectCondition
SSProcess.ClearSelection
SSProcess.SetSelectCondition "SSObj_Code", "==", "3103013"
SSProcess.SelectFilter
cnt= SSProcess.GetSelGeoCount
dim dic
set dic=CreateObject("Scripting.Dictionary")
for i=0 to cnt-1
lh= SSProcess.GetSelGeoValue (i,"[JZMC]")
bh= SSProcess.GetSelGeoValue (i,"[JZBH]")
key=lh+bh
mj= SSProcess.GetSelGeoValue (i,"SSObj_Area")
dic.add key ,mj
next
if dic.Exists("4#1") then'判断某个key是否存在
c=dic.Item("4#1")'提取key对应的value
msgbox c
end if
msgbox dic.count'输出字典数据总数
End Sub
str="1,2,3,4,5"
arrStr=split(str,",")
msgbox arrStr(4)
>5
通常情况下,要分割的字符串之中,字符之间的空格往往不是一个且个数并不相同,比如
Str=”1 2 3 4 5”分割的话,直接用
arrStr=split(str," ")
msgbox arrStr(4)
是实现不了的,通常是先将字符之间的空格替换为1个空格,然后再分割。类似于这种替换多个空格为1个空格的通用函数,可以将其写在一个vbs文件里,方便多个程序调用,这里顺便记录一下跨文件函数引用的方法,不同于c中的include,vbs稍微复杂点,直接贴代码:
commonFunction.vbs文件里
Function myReplace(ByVal s )
'将字符串中的多个连续空白符成一个
'调用:str=myReplace(ostr)
myReplace = ""
With CreateObject("VBSCRIPT.REGEXP")
.Global = True
.IgnoreCase = True
.Pattern = "\s+" '查找空白字符,空格、制表符什么的
myReplace = .Replace(s," ")
End With
End Function
在test.vbs里引用
********************************************************************
Sub Include (strFile)
Dim fsObj : Set fsObj = CreateObject("Scripting.FileSystemObject")
Dim vbsFile : Set vbsFile = fsObj.OpenTextFile(strFile,1, TRUE)
Dim myFunctionsStr : myFunctionsStr = vbsFile.ReadAll
vbsFile.Close
Set vbsFile = Nothing
Set fsObj = Nothing
ExecuteGlobal myFunctionsStr
End Sub
*********************************************************************
Sub OnClick()
scriptLocation ="C:\Users\Administrator\Desktop\砀山\Eps2008\DeskTop\外业生产台面\Script\杨军建\commonFunction.vbs"
Include(scriptLocation)’引用文件位置
str="1 2 3 4 5"
msgbox str
str1=myReplace(str)
msgbox str1
arrStr=split(str1," ")
msgbox arrStr(4)
End Sub
str="YangJunJian"
msgbox str
str1=mid(str,3,4)
msgbox str1
>ngJu
str="YangJunJian"
msgbox str
str1=mid(str,1,4)
msgbox str1
>Yang
dim txt
txt="This is a beautiful day!"
document.write(Replace(txt,"beautiful","horrible"))
输出:
This is a horrible day!
复杂情况参考正则表达式
此外还有LTrim/RTime/Trim/Len/inStr/Join