Page 1 of 1

Segment Arrays Part 2 Using a text box Rate Topic: ***** 1 Votes

#1 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Posted 29 January 2008 - 01:11 PM

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.
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.
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.

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.
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.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1