[quote=163696:@Mike Cotrone]Radium can you give an example of the sample data that you are needing to store?
Thanks[/quote]
for example, the codes for “A” would be:
“sdfgfdgd, sadadad, sdasdaf, asdada, fgdfgd, weqfvcvx, ytygbcv”
which are cut into pieces with “,” as the delimiter, each piece is trimmed of any whitespace, and put inside an array with the rest of pieces.
Then upon encryption, every “A” in the text input is replaced randomly with one of the codes provided for “A”.
[quote=163726:@Bruno Frechette]You can store arrays in a dictionary. Dictionaries store variants, so pretty much anything can go into a dictionary. When you lookup, you either need to cast the value, or predefine a variable or object of the right type before assigning the variant to it.
I would suggest encapsulating methods to store / extract data so you isolate your storage mechanism from the calling methods. You could use a module for that, call it “data”, create a private property “CodeDict” dictionary, make two protected methods: storeCodes and getCodes
By using a module, you can use the methods anywhere as “Data. storeCodes” and “Data.getCodes”. You can also change your storage methods anytime without affecting the rest of your code, as long as you keep both methods with the same parameters and return types.
Oh, and since dictionary values are case insensitive, and you may want to store different codes for “A” and “a”, you might want to convert “theChar” parameter to its ascii code.
Example (methods and property to be placed in a module)
[code]
sub StoreCodes(theChar as string,theCodes() as string)
'make sure the dictionary is initialized - could be placed in an “init” method
if CodeDict = nil then CodeDict = new dictionary
'store
CodeDict.value(asc(theChar)) = theCodes
end sub
sub getCodes(theChar as string) as string()
'make sure the dictionary is initialized - could be placed in an “init” method
if CodeDict = nil then CodeDict = new dictionary
'find the char in the dictionary
'decide what value to return if the code is not found.
'Here we return an array with a single empty string element
return CodeDict.lookup(asc(theChar),array(""))
end sub
[/code][/quote]
Thank you!!!
two questions:
- How can I make two methods out of the code you wrote, without removing the sub header footer, and without filling the return type and input type inside Xojo’s GUI fields? I mean I want to do it all by code like you pros.
- I made two methods out of the code you provided (and I’m very thankful for that!), using the GUI, and I also made another method named NumToChar, which I explain it below my question.
Then when I want to use them, I write “myModule.” and hit tab, StoreCodes, GetCodes, and CodeDict are all there in the autocomplete, but no trace of NumToChar is there.
I tried putting it into another module, changed the scope, putted it under a custom control, none of them worked. it’s giving me a bad head ache. I think it’s a Xojo bug?
Because when I create a new method under the module or custom control, it shows up as “Untitled” in the autocomplete, but just when I change its name, or paste my code inside it, it disappears from autocomplete.
How can I solve this?
The NumToChar method explanation:
I have a ComboBox as I said, with items from A-Z, this method takes the ComboBox.listIndex and turns it into the corresponding character’s string.
Here is the code:
[code]sub NumToChar(n as integer) as string
select case n
case 0
return “A”
case 1
return “B”
case 2
return “C”
case 3
return “D”
case 4
return “E”
case 5
return “F”
case 6
return “G”
case 7
return “H”
case 8
return “I”
case 9
return “J”
case 10
return “K”
case 11
return “L”
case 12
return “M”
case 13
return “N”
case 14
return “O”
case 15
return “P”
case 16
return “Q”
case 17
return “R”
case 18
return “S”
case 19
return “T”
case 20
return “U”
case 21
return “V”
case 22
return “W”
case 23
return “X”
case 24
return “Y”
case 25
return “Z”
end sub[/code]