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))
LVL 1
jjjjjjjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
Q1. Read back this way:

Dim sValue As String
Dim a As Long

sValue = Space$(Ubound(y))
For a = 1 To Ubound(y)
  Mid$(sValue, a, 1) = Chr$(y(a))
Next
Text1.Text = sValue
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VbmasterCommented:
Q2. Didn't you say you did encrypt it already? ;)
0
jjjjjjjAuthor Commented:
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
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

bonggoyCommented:
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.
0
jjjjjjjAuthor Commented:
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
0
bonggoyCommented:
fair enough :)
0
VbmasterCommented:
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)
0
jjjjjjjAuthor Commented:
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
0
VbmasterCommented:
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.
0
jjjjjjjAuthor Commented:
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
0
jjjjjjjAuthor Commented:
Thanks,

jjjjjjj
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.