Hey everybody,
I am currently writing the '.brn Maker' script! I am posting this because
the script needs to use CustomMem in order to operate. I suggest we are all
on the same page with this. In a previous post, I revealed my desire to
have multiple variables flowing from exchange to exchange. Medekza responded
and wrote these functions to Encode and Decode multiple variables
into and out of the CustomMem string:
'*********************
'Example of using CustomMem to store several custom variables
'Decode many custom variables out of the CustomMem Variable
TestVar1 = DecodeVar(CustomMem, "TestVar1")
TestVar2 = DecodeVar(CustomMem, "TestVar2")
TestVar3 = DecodeVar(CustomMem, "TestVar3")
TestVar4 = DecodeVar(CustomMem, "TestVar4")
'we output the variables to the Debug string
DebugInfo = DebugInfo & "TestVar1:" & TestVar1 & vbCrLf
DebugInfo = DebugInfo & "TestVar2:" & TestVar2 & vbCrLf
DebugInfo = DebugInfo & "TestVar3:" & TestVar3 & vbCrLf
DebugInfo = DebugInfo & "TestVar4:" & TestVar4 & vbCrLf
'We assign various random values to the variables if they are empty
'These values chosen during the first run should be kept in memory
'for the entire conversation
If TestVar1 = "" Then TestVar1 = Int(RND * 100)
If TestVar2 = "" Then TestVar2 = Int(RND * 100)
If TestVar3 = "" Then TestVar3 = Int(RND * 100)
If TestVar4 = "" Then TestVar4 = Int(RND * 100)
'We encode all the custom variables back into the CustomMem variable
CustomMem = EncodeVar(TestVar1, "TestVar1") & EncodeVar(TestVar2, "TestVar2") & EncodeVar(TestVar3, "TestVar3") & EncodeVar(TestVar4, "TestVar4")
'*************************
Then after the script unload portion of the UHP there are these two functions:
Function DecodeVar(FromWhat, DecodeWhat)
Temp = Instr(1, FromWhat, DecodeWhat & "-eq-", vbTextCompare) + Len(DecodeWhat) + 4
Temp2 = Instr(Temp, FromWhat, "-+-", vbTextCompare)
If Temp <= Len(DecodeWhat) + 4 Then
DecodeVar = ""
Else
DecodeVar = Mid(FromWhat, Temp, Temp2 - Temp)
End If
End Function
Function EncodeVar(EncodeWhat, AsWhat)
EncodeVar = AsWhat & "-eq-" & EncodeWhat & "-+-"
End Function
If one intends to keep up with what I'll be posting from this point on, you need to
have a UHP that has these two functions in the script. I have attached the script
Medekza posted- Create a project in the Brain Editor(all the test stuff is
gonna be changed) and paste the code into a brainfile and check it out...).
CatAtomic: >B)