嗨,如何在调酒师 VB 脚本中实现以下逻辑?
X18 VL40197366
= 33+1+8+38+31+21+4+0+1+9+7+3+6+6=168其中X=33
、" "=38
、V=31, L=21
。
现在,上述结果被存储到一个名为"temp1"的变量中其中 temp1 包含现在=168;'temp1=168''
我的代码在下面。我知道我的代码不完整,如果我错了,请纠正我
Dim A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
A = 10
B=11
C=12
D=13
E=14
F=15
G=16
H=17
I=18
J=19
K=20
L=21
M=22
N=23
O=24
P=25
Q=26
R=27
S=28
T=29
U=30
V=31
W=32
X=33
Y=34
Z=35
'Here i don't know how to declare the values for special characters and number
'I need to assign, if my final result is 0,...to 9, i need 0 to 9 as result.
'In addition to that, if my final result is 36, 37, 38, 39, 40, 41, 42, I need to show the corresponding symbols - . "" $ / + %
Dim temp1,temp3,temp4,temp5,temp6, temp7, temp8
float temp2
temp4 = Format.Objects("Text 1").Value 'Here i input first three characters depending on user input, ex:X18
'how can i give a check option here to add the above text , for ex, i need the result called 33+1+8 to be stored
'I have syntax called IIF(ConditionalExpr, ExprIfTrue, ExprIfFalse)
temp5= Format.Objects("Text 2").Value 'Here i input second three characters depending on user inputer, this is the characters after the space ex:VL4
'same here too,
temp6= Format.Objects("Text 3").Value 'Here i input third 7 characters depending on user inputer, ex:0197366
'same here too,
temp7 = 38 'this variable is for the space always this is constant
'temp1=temp4+temp7+temp5+temp6'but this code is giving me result called X1838VL40197366, which is incorrect. I need to be like shown as below
temp1= "" 'should hold the addition of all above for ex: 33+1+8+38+31+21+4+0+1+9+7+3+6+6=168
如何实现!
提前致谢
您没有将变量声明为数值类型。 编译器猜测您希望它们是字符串,因为Format
返回一个字符串。您必须将字符串值转换为数值。
Integer.Parse(text)
temp6 = Integer.Parse(temp5) + x
当您有大量变量时,请考虑使用数组。
Dim iValues As Integer() = New Integer() {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35}
temp6 = Integer.Parse(temp5) + iValues(24)
首先,我显然不明白你想做什么。
但是,在您的情况下,您应该使用 Dictionary 类而不是声明单个变量。
Dim dicResult as new Dictionary(Of String, Decimal)
Dim arrSymballs() As String = {"A","B","C","D","E","F","G","H","I"} ''You can add more
Dim iValue As Decimal = 10
For i As Integer = 0 To arrSymballs.Length-1
dicResult.Add(arrSymballs(i), iValue)
iValue += 1
Next
''Function to get string from result
''I don't know how the result you will get the following logic is for "10,11,12,13,14,15"
Private Function getResultString(_result As String) As Decimal
Dim dNumResult As Decimal
For Each c As String in _result.Split(",")
dNumResult += dicResult(c)
Next
Return dNumResult
End Function