Change texbox from 0 to z

pierrejeanes

Member
Joined
Aug 14, 2011
Messages
7
Programming Experience
Beginner
Hi everyone I am new to vb .net, what i want is to change a textbox with two characters every second starting from 00 and finish with zz
(00 01 02 03 04 ...0A 0B 0C 0D...1A...1B...1C...AA..AB...AC...Aa...Ab...Ac... 0a 0b 0c 0d ...zz ) so when start is 00 and the next second is 01 and at the end is zz,
So I can combine every letter uppercase and lower case and all numbers.
And this can be fired by an onclick event.
Any Ideas?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,570
Location
Sydney, Australia
Programming Experience
10+
Create an array containing all the characters you want to use. Have two Integer variables that contain the indexes of the two characters to display, starting at zero for both. Each time your Timer raises a Tick event, increment the second Integer. If it is equal to the Length of the array, reset it to zero and increment the first Integer. Get the characters from the array at the two indexes and combine them into a String, displaying that String in the TextBox (wouldn't a Label be a better idea?). Once the first index reaches the Length of the array, you would Stop the Timer, or reset both Integers to zero to start again.
 

pierrejeanes

Member
Joined
Aug 14, 2011
Messages
7
Programming Experience
Beginner
Create an array containing all the characters you want to use. Have two Integer variables that contain the indexes of the two characters to display, starting at zero for both. Each time your Timer raises a Tick event, increment the second Integer. If it is equal to the Length of the array, reset it to zero and increment the first Integer. Get the characters from the array at the two indexes and combine them into a String, displaying that String in the TextBox (wouldn't a Label be a better idea?). Once the first index reaches the Length of the array, you would Stop the Timer, or reset both Integers to zero to start again.

Thanks for the advise, but I don't know how to do that.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,570
Location
Sydney, Australia
Programming Experience
10+
What I posted is a series of simple steps and you should look at it that way. First step:
Create an array containing all the characters you want to use.
You obviously know what characters you want to use. Do you know how to create an array? If so, that's the first step done so you do know how to do at least some of it. If not then that's what you need to research. There's plenty of information on arrays in VB.NET out on the web.

Once you've got that step out of the way, then you can move onto the next:
Have two Integer variables that contain the indexes of the two characters to display, starting at zero for both.
I'm fairly sure that you know how to declare an Integer variable and assign zero to it. Then it's on to the next step and so on. Break the whole thing down into manageable steps and deal with each one individually.
 

pierrejeanes

Member
Joined
Aug 14, 2011
Messages
7
Programming Experience
Beginner
What I posted is a series of simple steps and you should look at it that way. First step:You obviously know what characters you want to use. Do you know how to create an array? If so, that's the first step done so you do know how to do at least some of it. If not then that's what you need to research. There's plenty of information on arrays in VB.NET out on the web.

Once you've got that step out of the way, then you can move onto the next:I'm fairly sure that you know how to declare an Integer variable and assign zero to it. Then it's on to the next step and so on. Break the whole thing down into manageable steps and deal with each one individually.
Thank you again, I'm in my first steps in .net but I'll give a try and find out how to doit, thanks for pointing me to the direction !.
 

Solitaire

Well-known member
Joined
Jun 28, 2004
Messages
465
Location
New York
Programming Experience
10+
Using ASCII values of characters

An array is not needed since you are simply using all the numerals and all the alphabetic characters, each of which can be represented with an ASCII value. A For loop can be used to increment the values starting with 48 (for "0") and going up to 122 (for "z"), skipping all the values for the non-alphabetic characters in-between. To get two characters, the code is placed inside a nested For loop.

Here is a sample using ASCII values of characters inside a nested For loop. I placed a delay of 1/10 of a second between each new display, using the Threading.Thread.Sleep() command. Even so, it would take a VERY long time to display all the possibilities. It uses 2 characters starting with the numerals, then progressing to the uppercase letters and lowercase letters, skipping all the ASCII values in-between. To shorten the time, change the Sleep() argument from 100 to 10.

The Sleep command will continue executing and cannot be stopped unless you click Stop Debugging (Shift-F5) during run time. A timer would be better but I don't know how to use it with a nested loop. I'm hoping someone here can show me how this code can be revised using a timer.


VB.NET:
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ch1, ch2 As String
    For x As Integer = 48 To 122
      ch1 = Chr(x)
      If x = 58 Then x = 65
      If x = 91 Then x = 97
      For y As Integer = 48 To 122
        ch2 = Chr(y)
        If y = 58 Then y = 65
        If y = 91 Then y = 97
        TextBox1.Text = ch1 & ch2
        TextBox1.Refresh()
        Threading.Thread.Sleep(100)
      Next
    Next
  End Sub
 
Last edited:

pierrejeanes

Member
Joined
Aug 14, 2011
Messages
7
Programming Experience
Beginner
Thanks this code is working good changing the textbox every x seconds but I cannot get that code (from another textbox) because the whole application is like freezing because of the

Threading.Thread.Sleep(100), any Ideas on how to use it with timer?
 

pierrejeanes

Member
Joined
Aug 14, 2011
Messages
7
Programming Experience
Beginner
Thak You everybody

Yes solitaire, I got the timer running ok everything is working good thank you this my my code

Dim ch1, ch2, ch3, ch4
Dim primernumeroResume = TextBox19.Text

Dim segundonumeroResume = TextBox20.Text



For x As Integer = Asc(primernumeroResume) To 48 Step -1
ch1 = Chr(x)
ch3 = Chr(x)

If x = 57 Then x = 64
If x = 90 Then x = 96

For y As Integer = Asc(segundonumeroResume) To 48 Step -1
ch2 = Chr(y)
ch4 = Chr(y)
If y = 65 Then y = 58
If y = 97 Then y = 91
TextBox4.Text = ch1 & ch2
TextBox6.Text = ch3 & ch4
TextBox19.Text = ch1
TextBox20.Text = ch2

TextBox4.Refresh()
TextBox6.Refresh()



Dim TIEMPO1 As String
TIEMPO1 = TextBox11.Text
Pausa(TIEMPO1)
Next



Next
 
Top Bottom