PDA

View Full Version : Solved: Number help!!!



Lutoniall
11-02-2007, 12:11 PM
I am a complete beginner in VBA so could you help with this.

I have a seven segment LCD display which are really lines to make it look like it. What I need is to make the numbers go to 199.9, so my display looks like XXX.X. I have done the code so far 1-9:

Private Sub Change_Number_Click()
Line1.Visible = False
Line2.Visible = False
Line3.Visible = False
Line4.Visible = False
Line5.Visible = False
Line6.Visible = False
Line7.Visible = Fasle
Line8.Visible = False
Line9.Visible = False
Line10.Visible = False
Line11.Visible = False
Line12.Visible = False
Line13.Visible = False
Line14.Visible = Fasle

Number = InputBox("Enter the number to display")

Select Case Number

Case 0
Line1.Visible = True
Line2.Visible = True
Line3.Visible = True
Line4.Visible = True
Line5.Visible = True
Line6.Visible = True
Line7.Visible = False

Case 1
Line1.Visible = False
Line2.Visible = False
Line3.Visible = True
Line4.Visible = True
Line5.Visible = False
Line6.Visible = False
Line7.Visible = False

Case 2
Line1.Visible = False
Line2.Visible = True
Line3.Visible = True
Line4.Visible = False
Line5.Visible = True
Line6.Visible = True
Line7.Visible = True

Case 3
Line1.Visible = False
Line2.Visible = True
Line3.Visible = True
Line4.Visible = True
Line5.Visible = True
Line6.Visible = False
Line7.Visible = True

Etc.. on to case 9 (This is not in the code:) )
End Select
End Sub

So how do I make it go to 199.9 without writing out case 1 to 199.9 as this would take a long time. Many Thanks!!!

TonyJollans
11-04-2007, 04:29 PM
It's hard to see what this has to do with Access but let's assume it's on an Access Form.

There's no way to avoid hard coding the cross reference from numbers to lines somewhere as Access doesn't know them for itself, but you can make it easier by doing something like this:


Dim Digits(0 To 9)
Digits(0) = Array(1, 1, 1, 1, 1, 1, 0)
Digits(1) = Array(0, 0, 1, 1, 0, 0, 0)
Digits(2) = Array(0, 1, 1, 0, 1, 1, 1)
Digits(3) = Array(0, 1, 1, 1, 1, 0, 1)
Digits(4) = Array(1, 0, 1, 1, 0, 0, 1)
Digits(5) = Array(1, 1, 0, 1, 1, 0, 1)
Digits(6) = Array(1, 1, 0, 1, 1, 1, 1)
Digits(7) = Array(0, 1, 1, 1, 0, 0, 0)
Digits(8) = Array(1, 1, 1, 1, 1, 1, 1)
Digits(9) = Array(1, 1, 1, 1, 1, 0, 1)



With this set up you can display a number like this


Number = 4 ' perhaps

For Segment = 1 To 7
Controls("Line" & Segment).Visible = Digits(Number)(Segment - 1) = 1
Next


You don't say how you have the multiple digits set up but you should be able to extend the above to do once for each digit.

Lutoniall
11-08-2007, 02:29 PM
My display is XXX.X in the forum made out of lines.

What i want is to click on a command button, which then bring up an InputBox and to enter an amount XXX.X, when click OK, it will have changed the lines to look like what ive typed in.

Hope thats clearer!

TonyJollans
11-08-2007, 11:30 PM
What you want is clear enough - with the presumption that it's on an Access Form.

What I don't know is what all your lines are called. I simply noted how you were using Lines 1 to 7 to build up a single digit and gave you an example of how to do that.

Does it not work for you? Or can you not convert it for your other digits? Or is there something I'm missing?

Lutoniall
11-09-2007, 10:46 AM
What you want is clear enough - with the presumption that it's on an Access Form.

What I don't know is what all your lines are called. I simply noted how you were using Lines 1 to 7 to build up a single digit and gave you an example of how to do that.

Does it not work for you? Or can you not convert it for your other digits? Or is there something I'm missing?

Yes it is on a access form and my lines for first digit are called line1, line2, line3, line4, line5, line6, line7 and for the other three digits it carrys on. e.g The second digit will have line8, line9, line10, line11, line12, line13, line14 . What I cant do is convert all the numbers in XXX.X when typing it into a InputBox.

Sorry about confusion just started on VBA

TonyJollans
11-09-2007, 12:46 PM
(ignoring the decimal point for the moment)

I have given you code to do one number with lines 1 to 7.
Can you change it to do another one with lines 8 to 14?

There are lots of ways to deal with the inputbox - this should get you started but there's more checking needed.


InNum = Inputbox("Whatever")
If Isnumeric(Innum) then
If INNum > 0 And InNum < 1000 Then
Hundreds = InNum \ 100
Tens = InNUm \ 10 Mod 10
' etc...

Lutoniall
11-09-2007, 01:06 PM
(ignoring the decimal point for the moment)

I have given you code to do one number with lines 1 to 7.
Can you change it to do another one with lines 8 to 14?

There are lots of ways to deal with the inputbox - this should get you started but there's more checking needed.


InNum = Inputbox("Whatever")
If Isnumeric(Innum) then
If INNum > 0 And InNum < 1000 Then
Hundreds = InNum \ 100
Tens = InNUm \ 10 Mod 10
' etc...


I am getting very dumb now, when I put this code into a command button it doesnt seem to work:think: It may be simple but only started this around 2 months ago.

TonyJollans
11-09-2007, 04:03 PM
what does it do? if it errors, on what line?

just as a by the way, if you are working with a form why don't you have a textbox on the form instead of using an inputbox?

Lutoniall
11-10-2007, 03:50 AM
what does it do? if it errors, on what line?

just as a by the way, if you are working with a form why don't you have a textbox on the form instead of using an inputbox?

When typed in the code it doesnt do anything. I suppose I could use a textbox, by the way have you designed this, because if you have it may be easier to sent it to me.

TonyJollans
11-10-2007, 06:20 AM
I just gave you something to get you started - it requires a bit of effort on your part. What have you done? Can you post it all here?

No, I've never designed anything like this - it's your project and I'm just trying to help. I'm sure it would be easier for me to write it for you but that isn't really the purpose of the forum and you wouldn't learn much from it.

TonyJollans
11-10-2007, 01:07 PM
I see you have marked this solved. I presume you have worked it out with or without what I have given you. Well done.