[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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))
0
jjjjjjj
Asked:
jjjjjjj
  • 5
  • 4
  • 2
1 Solution
 
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
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now