Welcome to Dream.In.Code
Click Here
Getting Help is Easy!

Join 118,480 Programmers for FREE! Ask your question and get quick answers from experts. There are 968 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Segment Arrays Part 2

 
Reply to this topicStart new topic

> Segment Arrays Part 2, Using a text box

Rating  5
sam_benne
Group Icon



post 29 Jan, 2008 - 01:11 PM
Post #1


Well come to part 2 where we will advance on part 1.

This time we will be able to Use a text box instead of option buttons. However, we will be using the same one as before to make this easier. If you haven't already made one it would be good to have a look at part 1.

At the top of your form Add a text box with these properties
Name - txtCheckString
maxlength - 1

You will also need a button
Name - cmdChange

When you have these created you then need to go into code view for the button. the first thing is to declare a variable.
CODE

Dim iFirstNumber As Integer

This will help later on as iFirstNumber is the number you will be entering in the text box. In part three you will also see why it is called iFirstNumber.

Underneath that we will be creating a very simple string this will also be explained in more detail in part 3.
CODE

firstnumber = Mid(txtCheckString, 1, 1)


What this does is it checks the first number of the text box and only selects that number.

Now like before the code is very alike for selecting the colors for the numbers but this time it will be done as "if's" statements.

CODE

If firstnumber = 1 Then
shpR1.FillColor = &H80000000
shpR1.BackColor = &H80000000
shpR2.FillColor = vbBlue
shpR2.BackColor = vbBlue
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = &H80000000
shpR4.BackColor = &H80000000
shpR5.FillColor = &H80000000
shpR5.BackColor = &H80000000
shpR6.FillColor = &H80000000
shpR6.BackColor = &H80000000
shpR7.FillColor = &H80000000
shpR7.FillColor = &H80000000

ElseIf firstnumber = 2 Then
shpR1.FillColor = vbBlue
shpR1.BackColor = vbBlue
shpR2.FillColor = vbBlue
shpR2.BackColor = &H80000000
shpR3.FillColor = &H80000000
shpR3.BackColor = vbBlue
shpR4.FillColor = vbBlue
shpR4.BackColor = vbBlue
shpR5.FillColor = vbBlue
shpR5.BackColor = vbBlue
shpR6.FillColor = vbBlue
shpR6.BackColor = vbBlue
shpR7.FillColor = &H80000000
shpR7.BackColor = &H80000000

ElseIf firstnumber = 3 Then
shpR1.FillColor = vbBlue
shpR1.BackColor = vbBlue
shpR2.FillColor = vbBlue
shpR2.BackColor = vbBlue
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = vbBlue
shpR4.BackColor = vbBlue
shpR5.FillColor = &H80000000
shpR5.BackColor = &H80000000
shpR6.FillColor = vbBlue
shpR6.BackColor = vbBlue
shpR7.FillColor = &H80000000
shpR7.BackColor = &H80000000

ElseIf firstnumber = 4 Then
shpR1.FillColor = &H80000000
shpR1.BackColor = &H80000000
shpR2.FillColor = vbBlue
shpR2.BackColor = vbBlue
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = &H80000000
shpR4.BackColor = &H80000000
shpR5.FillColor = &H80000000
shpR5.BackColor = &H80000000
shpR6.FillColor = vbBlue
shpR6.BackColor = vbBlue
shpR7.FillColor = vbBlue
shpR7.BackColor = vbBlue

ElseIf firstnumber = 5 Then
shpR1.FillColor = vbBlue
shpR1.BackColor = vbBlue
shpR2.FillColor = &H80000000
shpR2.BackColor = &H80000000
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = vbBlue
shpR4.BackColor = vbBlue
shpR5.FillColor = &H80000000
shpR5.BackColor = &H80000000
shpR6.FillColor = vbBlue
shpR6.BackColor = vbBlue
shpR7.FillColor = vbBlue
shpR7.BackColor = vbBlue

ElseIf firstnumber = 6 Then
shpR1.FillColor = vbBlue
shpR1.BackColor = vbBlue
shpR2.FillColor = &H80000000
shpR2.BackColor = &H80000000
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = vbBlue
shpR4.BackColor = vbBlue
shpR5.FillColor = vbBlue
shpR5.BackColor = vbBlue
shpR6.FillColor = vbBlue
shpR6.BackColor = vbBlue
shpR7.FillColor = vbBlue
shpR7.BackColor = vbBlue

ElseIf firstnumber = 7 Then
shpR1.FillColor = vbBlue
shpR1.BackColor = vbBlue
shpR2.FillColor = vbBlue
shpR2.BackColor = vbBlue
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = &H80000000
shpR4.BackColor = &H80000000
shpR5.FillColor = &H80000000
shpR5.BackColor = &H80000000
shpR6.FillColor = &H80000000
shpR6.BackColor = &H80000000
shpR7.FillColor = &H80000000
shpR7.BackColor = &H80000000

ElseIf firstnumber = 8 Then
shpR1.FillColor = vbBlue
shpR1.BackColor = vbBlue
shpR2.FillColor = vbBlue
shpR2.BackColor = vbBlue
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = vbBlue
shpR4.BackColor = vbBlue
shpR5.FillColor = vbBlue
shpR5.BackColor = vbBlue
shpR6.FillColor = vbBlue
shpR6.BackColor = vbBlue
shpR7.FillColor = vbBlue
shpR7.BackColor = vbBlue

ElseIf firstnumber = 9 Then
shpR1.FillColor = vbBlue
shpR1.BackColor = vbBlue
shpR2.FillColor = vbBlue
shpR2.BackColor = vbBlue
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = &H80000000
shpR4.BackColor = &H80000000
shpR5.FillColor = &H80000000
shpR5.BackColor = &H80000000
shpR6.FillColor = vbBlue
shpR6.BackColor = vbBlue
shpR7.FillColor = vbBlue
shpR7.BackColor = vbBlue

ElseIf firstnumber = 0 Then
shpR1.FillColor = vbBlue
shpR1.BackColor = vbBlue
shpR2.FillColor = vbBlue
shpR2.BackColor = vbBlue
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = vbBlue
shpR4.BackColor = vbBlue
shpR6.FillColor = &H80000000
shpR6.BackColor = &H80000000
shpR5.FillColor = vbBlue
shpR5.BackColor = vbBlue
shpR7.FillColor = vbBlue
shpR7.BackColor = vbBlue
End If


As you can see what this does is if iFirstNumber = 0 to 9 then it will do the code that follows and none of the other code.

Now test it and it now should work. If it doesn't contact me if it does then you can try and make it even better by clikin the text box and going in the code view and but the code from the button into the text box section this should then change the number automatically. Or even instead of a text box you could do a combo box.

If you were to do a combo box then remember that in form load you would need to
(Name of combobox) .Additem "0"
Then click on your combo box and where it says change, change it to click and do an if statement.
CODE

If (name).text = "1" Then

shpR1.FillColor = &H80000000
shpR1.BackColor = &H80000000
shpR2.FillColor = vbBlue
shpR2.BackColor = vbBlue
shpR3.FillColor = vbBlue
shpR3.BackColor = vbBlue
shpR4.FillColor = &H80000000
shpR4.BackColor = &H80000000
shpR5.FillColor = &H80000000
shpR5.BackColor = &H80000000
shpR6.FillColor = &H80000000
shpR6.BackColor = &H80000000
shpR7.FillColor = &H80000000
shpR7.FillColor = &H80000000

Elseif (name).text = "2" Then
ETC ...


As you can see this can be done in different ways. So keep an eye out for part three where we have four segment arrays, either to make a timer or a number with theses formats ####, ###.#, ##.##, #.###.

If you have any problems just comment or contact me (sam_benne@hotmail.co.uk) or if you have any questions.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 10/11/08 06:06AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month