|
|
发表于 2006-11-28 18:20:00
|
显示全部楼层
Re:问个有关VB脚本的问题。
Private Type Variable
Name As String
Value As String
End Type
Dim VarCount As Integer
Dim Var() As Variable
定义变量:
tmpstr = Parameter + ","
tmpint = 0
For i = 1 To Len(tmpstr)
If Mid(tmpstr, i, 1) = "," Then tmpint = tmpint + 1
Next i
VarCount = tmpint
ReDim Var(tmpint)
For i = 1 To tmpint
Var(i).Name = Mid(tmpstr, 1, InStr(1, tmpstr, ",", vbTextCompare) - 1)
tmpstr = Mid(tmpstr, InStr(1, tmpstr, ",", vbTextCompare) + 1)
Var(i).Value = ""
Next i
设置变量的值:
tmpstr = Scripts(j)
For i = 1 To VarCount
If GetPart(Parameter, ",", 1) = Var(i).Name Then
Select Case GetPart(Parameter, ",", 3)
Case "", "String"
Var(i).Value = GetPart(Parameter, ",", 2)
Case "Number", "Numerical"
Var(i).Value = Calc(PatchVar(GetPart(Parameter, ",", 2)))
End Select
Exit For
End If
Next i
引用变量:(我的程序里变量部分用/'和'/括起来)
Private Function PatchVar(strInput As String) As String
Dim i As Integer, tmpstr As String, tmpstr2 As String, tmpint As Long
tmpstr = strInput
Do While InStr(1, tmpstr, "/'", vbTextCompare) > 0
If GetBetween(tmpstr, "/'", "'/") Like "*.Direction" Then
tmpstr2 = Mid(GetBetween(tmpstr, "/'", "'/"), 1, InStr(1, GetBetween(tmpstr, "/'", "'/"), ".", vbTextCompare) - 1)
If tmpstr2 = "Lead" Then
tmpstr = Mid(tmpstr, 1, InStr(1, tmpstr, "/'", vbTextCompare) - 1) + ConvertDirection(Trim(Str(Direction))) + Mid(tmpstr, InStr(1, tmpstr, "'/", vbTextCompare) + 2)
Else
For i = 0 To SpiritsCount 'SpiritsCount - 1
If GetPart(Spirits(i).Name, ",", 1) = tmpstr2 Then
tmpstr = Mid(tmpstr, 1, InStr(1, tmpstr, "/'", vbTextCompare) - 1) + Spirits(i).ArrSpiritsDirection + Mid(tmpstr, InStr(1, tmpstr, "'/", vbTextCompare) + 2)
Exit For
End If
Next i
End If
ElseIf GetBetween(tmpstr, "/'", "'/") Like "*.Position" Then
tmpstr2 = Mid(GetBetween(tmpstr, "/'", "'/"), 1, InStr(1, GetBetween(tmpstr, "/'", "'/"), ".", vbTextCompare) - 1)
If tmpstr2 = "Lead" Then
If Spirits(0).ArrSpiritsX < imgWidth Then
tmpint = Spirits(0).ArrSpiritsX + (Spirits(0).ArrSpiritsY - 1) * imgWidth
Else
tmpint = Spirits(0).ArrSpiritsY * imgWidth
End If
tmpstr = Mid(tmpstr, 1, InStr(1, tmpstr, "/'", vbTextCompare) - 1) + Trim(Str(tmpint)) + Mid(tmpstr, InStr(1, tmpstr, "'/", vbTextCompare) + 2)
Else
For i = 0 To SpiritsCount 'SpiritsCount - 1
If GetPart(Spirits(i).Name, ",", 1) = tmpstr2 Then
If Spirits(i).ArrSpiritsX < imgWidth Then
tmpint = Spirits(i).ArrSpiritsX + (Spirits(i).ArrSpiritsY - 1) * imgWidth
Else
tmpint = Spirits(i).ArrSpiritsY * imgWidth
End If
tmpstr = Mid(tmpstr, 1, InStr(1, tmpstr, "/'", vbTextCompare) - 1) + Trim(Str(tmpint)) + Mid(tmpstr, InStr(1, tmpstr, "'/", vbTextCompare) + 2)
Exit For
End If
Next i
End If
Else
For i = 1 To VarCount
If Var(i).Name = GetBetween(tmpstr, "/'", "'/") Then
tmpstr = Mid(tmpstr, 1, InStr(1, tmpstr, "/'", vbTextCompare) - 1) + Var(i).Value + Mid(tmpstr, InStr(1, tmpstr, "'/", vbTextCompare) + 2)
Exit For
End If
Next i
End If
Loop
PatchVar = tmpstr
End Function
时间仓促,没有整理,只是把我的游戏里的相关代码贴出,看不懂的继续研究,谢谢。 |
|