Link to home
Start Free TrialLog in
Avatar of jjjjjjj
jjjjjjj

asked on

Arrays

Dim y() as string
redim y(1 to len(text1.text))


This is a part of the code that I have written.  
Q #1
Once y has been redim'ed and is populated, I want to view all of the elements of y in a text box.  

As an example, the info in text1.text is string. Buried in my code, I have converted this data via encryption (and an array) using Asc.  How do I read all of the values which populate the y array?

Q#2
Is there a way to populate an array using rnd() and asc() combinations so that when a user enters data into a text box, presses a Cmd button, another text box is populated and encoded with random equivalents of Asc characters?

Thanks,

jjjjjjj
(1 to len(text1.text))
ASKER CERTIFIED SOLUTION
Avatar of Vbmaster
Vbmaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vbmaster
Vbmaster

Q2. Didn't you say you did encrypt it already? ;)
Avatar of jjjjjjj

ASKER

Yes, it is encrypted.  Basically, I created an array Dim a(97 to 123) as string. The 97 to 123 are the lowercase letters in the alphabet.  In this array, I placed random string *1 equivalents so instead of 97 = a, it could read f or g or the space bar, Asc(32) I think it is.

When the user enters data into the text box A, and then hits the cmd button the individual values of the string typed into text box a are read one by one and are converted into a random string *1 equivalent by using the asc function and the new array is populated with this value.  So if the user types "a" which is asc 97(I think the number is right) the code see this and then looks for 97 in my first array, and then populates the second array y() with that new encrypted value.  This way it is now encoded.  I have the first array hard coded but I believe that there is a better way to do it randomly.  As long as it is more efficient code, I would like to see it, if it is more than 10 lines, don't waste your time.

Please tell me if I am approaching this problem in an effective, creative way.

Thanks,

jjjjjjj
Q1 Answer:

Loop through y array ie.,

For I = 0 to UBound(y)
   Debug.Print y(I)
Next I

Q2 Answer:

use something like this:

Chr(Int((255 * Rnd) + 1))

you may want to check the output as it may not properly print on your text box.  To be sure, set the font property to something that supports TTF (Time New Roman, Verdana, etc)

Hope that helps.
Avatar of jjjjjjj

ASKER

I am only rejecting until I can get a chance to use Vbmasters code first, since he answered first.

If it fails I will try yours and if it passes I will accept.

jjjjjjj
fair enough :)
Well my code won't work because I thought you used a Byte array, not a String array. If you do a simple encryption you should use a Byte array with the Asc values instead of a String array. Anyway with a String array replace the line..

  Mid$(sValue, a, 1) = Chr$(y(a))

...with..

  Mid$(sValue, a, 1) = y(a)
Avatar of jjjjjjj

ASKER

Please explain the byte array vs string array you mentioned above, ie... the differences, why I should use byte array instead of string array.  I have only been programming about 6 months.

jjjjjjj
It sounded like your encryption algorithm uses a simple change of the characters, i.e 'a' becomes 'g', 'b' becomes 'h' etc.

If this is so you can replace code like..

   y(b) = Chr$(Asc(y(b)) + 7)

...with..

   y(b) = y(b) + 7

And this is way faster than using strings.
Avatar of jjjjjjj

ASKER

Yes,

I agree, but the shift is predictable and could be easily broken.  I like the random variable approach, however if you were to ever store the results of a conversion in a table, it would never de-code properly because the shift would be random each time the array was populated, say in the form load event.

What are your comments?

jjjjj
Avatar of jjjjjjj

ASKER

Thanks,

jjjjjjj