PDA

View Full Version : INI File question?


mystica
10-21-2008, 09:45 PM
I need some help with an INI file that I'm trying to use for a simple substitution-cypher (project.apz is attached)
The INI file contains the following data:

[values]

a = 07
b = 14
c = 23
d = 38
e = 48
f = 54
g = 69
h = 72
i = 87
j = 91
k = 10
l = 18
m = 12
n = 13
o = 84
p = 19
q = 11
r = 67
s = 78
t = 92
u = 20
v = 51
w = 22
x = 21
y = 77
z = 42

Basically what I'm trying to achieve is, if the user enters a 'letter' value (eg. johnsmith) into InputBox-1,
the corresponding 'number' value (as governed by the INI file) should appear in InputBox-2.

So in this example, if 'johnsmith' was entered into InputBox-1, then '918472137812879272' should appear in InputBox-2.

At the moment, I'm using the following code:

result = Input.GetText("Input1");
value_data = INIFile.GetValue(_SourceFolder .. "\\cypher.ini", "values", result);
Input.SetText("Input2", value_data);

... but the problem of course, is that it only works if the user inputs a SINGLE letter. I need it to work REGARDLESS of how many letters are entered, and it needs to adhere to the values as specified in the INI file.

I've been playing around with both the String.Replace and INIFile.GetValue functions but can't figure out a way to achieve this. Can anyone help me out here, please? (I'm guessing that some kind of TableFunction might be required which I'm not too good with).

Imagine Programming
10-21-2008, 10:11 PM
Place this on the On Click event of the button:


result = Input.GetText("Input1");
ReturnString="";
for i=1, String.Length(result)do
sChar = String.Mid(result, i, 1);
value_data = INIFile.GetValue(_SourceFolder .. "\\cypher.ini", "values", sChar);
ReturnString=ReturnString..value_data;
end
Input.SetText("Input2", ReturnString);


Regards, CB

mystica
10-21-2008, 11:31 PM
Thanks CB,

You're a bloody legend, mate. Couldn't have asked for a better solution!

Imagine Programming
10-22-2008, 07:17 AM
hehe no problem, it worked well?:)