Using "Between" in VB Script

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text box that the users enter a number between 1 and 10. If the
enter a number between 1 and 5, I want a yellow box to appear; if between 6
and 10, I want a blue box to appear. I've been able to code it partially but
don't know how to make the range included (if between 6 and 10 then), etc.
What I have so far is listed below - thank you!!!

Private Sub Text8_AfterUpdate()

If Text8 = "0" Then
Me.Controls(Yellow.Name).Visible = False
Me.Controls(Blue.Name).Visible = False
Else
Me.Controls(Yellow.Name).Visible = True
Me.Controls(Blue.Name).Visible = False
ELSe
Me.Controls(Yellow.Name).Visible = False
Me.Controls(Blue.Name).Visible = True

End If



End Sub
 
David, I'm doing something wrong because no matter what number I insert
(besides zero) only the blue box shows up - I never see the black one. Even
if I enter 8 or 9 - which are definitely greater than 6 - I still don't see
the black; just blue:

Private Sub Text8_AfterUpdate()

If Text8 = "0" Then
Me.Controls(RShoulderBlue.Name).Visible = False
Me.Controls(RShoulderBlack.Name).Visible = False
ElseIf Text10 < 6 Then
Me.Controls(RShoulderBlack.Name).Visible = False
Me.Controls(RShoulderBlue.Name).Visible = True
ElseIf Text10 > 6 Then
Me.Controls(RShoulderBlack.Name).Visible = True
Me.Controls(RShoulderBlue.Name).Visible = False
End If
End Sub
 
Your first question was about Text8.
I see that your new question is about Text8 and Text10.
Is that a mistake?

(david)
 
YES!!! It is a mistake - I goofed and it should all be for the Text8. I've
changed the code but now have another snag (I seem to be full of them today).
It seems to be coding at a higher level than I want it to. If I create
multiple records, then the change take place for the most-recently updated
record.

What I'm showing is a figure of the right arm. Each record contains several
Pain Index fields, representing the palm, fingers, wrist, forearm, etc. By
entering a number up to 6, a blue box appears over the pain area. If greater
than 6, a black box appears (more severe pain). However, now when I enter an
"8" in the wrist box for record #1, all subsequent records show a black box
over the wrist even if they have a value of 0 or 2. I need this to be RECORD
specific...I hope this makes sense.
 
I think what I need to do is set the control source of the actual square,
right? So the blue square's control source would be something like: Iif(Text8
= 0, Visible = False, Iif(Text8 < 6, Visible = True, Iif (Text8 > 6, Visible
= False))).

My example above (obviously) doesn't work...but is this close? What do I
need to do to fix?
 
from a rusty, unreliable memory, and untested:

bluecontrol.visible = ([Text8]>0) And ([Text8]<=6)

([Text8]>0) and other such logical expressions resolves to True or False.
True And True resolves to True,
True And False resolves to False

The IF ... Else statements, although more verbose, also work and are easier
for most to read.
 
Hi David,
You're great - I've almost got it. I've created a text box (set background
to blue) and inserted the following code into the control source:

=[Text17].[Visible]=([Text8]>0) And ([Text8]<=6)

However, while there is no error, the text box always shows and displays -1
(if the value is true) and 0 (if the value is false). I feel like we're so
close...

--
Thank you! - Jennifer


David Cox said:
from a rusty, unreliable memory, and untested:

bluecontrol.visible = ([Text8]>0) And ([Text8]<=6)

([Text8]>0) and other such logical expressions resolves to True or False.
True And True resolves to True,
True And False resolves to False

The IF ... Else statements, although more verbose, also work and are easier
for most to read.
 
I read your code:
I thought you were trying to make the blue box visible in one case and
invisible in the other, which was why I had the control.visible syntax.

I do not understand why you think you want to set control source.

I could have had something like:
Blackbox.visible = ([Text8] > 6)
Bluebox.visible = ([Text8]>0) And ([Text8]<=6)

except that I would want colored pictures of the various body parts in their
close to correct positions.



Jennifer Cali said:
Hi David,
You're great - I've almost got it. I've created a text box (set background
to blue) and inserted the following code into the control source:

=[Text17].[Visible]=([Text8]>0) And ([Text8]<=6)

However, while there is no error, the text box always shows and
displays -1
(if the value is true) and 0 (if the value is false). I feel like we're so
close...

--
Thank you! - Jennifer


David Cox said:
from a rusty, unreliable memory, and untested:

bluecontrol.visible = ([Text8]>0) And ([Text8]<=6)

([Text8]>0) and other such logical expressions resolves to True or False.
True And True resolves to True,
True And False resolves to False

The IF ... Else statements, although more verbose, also work and are
easier
for most to read.



Jennifer Cali said:
I think what I need to do is set the control source of the actual
square,
right? So the blue square's control source would be something like:
Iif(Text8
= 0, Visible = False, Iif(Text8 < 6, Visible = True, Iif (Text8 > 6,
Visible
= False))).

My example above (obviously) doesn't work...but is this close? What do
I
need to do to fix?
--
Thank you! - Jennifer


:

YES!!! It is a mistake - I goofed and it should all be for the Text8.
I've
changed the code but now have another snag (I seem to be full of them
today).
It seems to be coding at a higher level than I want it to. If I create
multiple records, then the change take place for the most-recently
updated
record.

What I'm showing is a figure of the right arm. Each record contains
several
Pain Index fields, representing the palm, fingers, wrist, forearm,
etc.
By
entering a number up to 6, a blue box appears over the pain area. If
greater
than 6, a black box appears (more severe pain). However, now when I
enter
an
"8" in the wrist box for record #1, all subsequent records show a
black
box
over the wrist even if they have a value of 0 or 2. I need this to be
RECORD
specific...I hope this makes sense.

---
Thank you! - Jennifer


:

Your first question was about Text8.
I see that your new question is about Text8 and Text10.
Is that a mistake?

(david)


message
David, I'm doing something wrong because no matter what number I
insert
(besides zero) only the blue box shows up - I never see the black
one.
Even
if I enter 8 or 9 - which are definitely greater than 6 - I still
don't
see
the black; just blue:

Private Sub Text8_AfterUpdate()

If Text8 = "0" Then
Me.Controls(RShoulderBlue.Name).Visible = False
Me.Controls(RShoulderBlack.Name).Visible = False
ElseIf Text10 < 6 Then
Me.Controls(RShoulderBlack.Name).Visible = False
Me.Controls(RShoulderBlue.Name).Visible = True
ElseIf Text10 > 6 Then
Me.Controls(RShoulderBlack.Name).Visible = True
Me.Controls(RShoulderBlue.Name).Visible = False
End If
End Sub
--
Thank you! - Jennifer


:


if text8 = 0 then

elseif text8 < 6 then

else

endif

(david)



in
message
I have a text box that the users enter a number between 1 and
10.
If
the
enter a number between 1 and 5, I want a blue box to appear;
if
between
6
and 10, I want a black box to appear. I've been able to code
it
partially
but
don't know how to make the range included (if between 6 and 10
then),
etc.
What I have so far is listed below - thank you!!!

Private Sub Text8_AfterUpdate()

If Text8 = "0" Then
Me.Controls(Yellow.Name).Visible = False
Me.Controls(Blue.Name).Visible = False
Else
Me.Controls(Yellow.Name).Visible = True
Me.Controls(Blue.Name).Visible = False
ELSe
Me.Controls(Yellow.Name).Visible = False
Me.Controls(Blue.Name).Visible = True

End If



End Sub
 
As an alternative, you could use Conditional Formatting. Right click
on the field in design view, then select Conditional Formatting. The
rest should be pretty self explanatory.


Chris Nebinger.


David said:
I read your code:
I thought you were trying to make the blue box visible in one case and
invisible in the other, which was why I had the control.visible syntax.

I do not understand why you think you want to set control source.

I could have had something like:
Blackbox.visible = ([Text8] > 6)
Bluebox.visible = ([Text8]>0) And ([Text8]<=6)

except that I would want colored pictures of the various body parts in their
close to correct positions.



Jennifer Cali said:
Hi David,
You're great - I've almost got it. I've created a text box (set background
to blue) and inserted the following code into the control source:

=[Text17].[Visible]=([Text8]>0) And ([Text8]<=6)

However, while there is no error, the text box always shows and
displays -1
(if the value is true) and 0 (if the value is false). I feel like we're so
close...

--
Thank you! - Jennifer


David Cox said:
from a rusty, unreliable memory, and untested:

bluecontrol.visible = ([Text8]>0) And ([Text8]<=6)

([Text8]>0) and other such logical expressions resolves to True or False.
True And True resolves to True,
True And False resolves to False

The IF ... Else statements, although more verbose, also work and are
easier
for most to read.



I think what I need to do is set the control source of the actual
square,
right? So the blue square's control source would be something like:
Iif(Text8
= 0, Visible = False, Iif(Text8 < 6, Visible = True, Iif (Text8 > 6,
Visible
= False))).

My example above (obviously) doesn't work...but is this close? What do
I
need to do to fix?
--
Thank you! - Jennifer


:

YES!!! It is a mistake - I goofed and it should all be for the Text8.
I've
changed the code but now have another snag (I seem to be full of them
today).
It seems to be coding at a higher level than I want it to. If I create
multiple records, then the change take place for the most-recently
updated
record.

What I'm showing is a figure of the right arm. Each record contains
several
Pain Index fields, representing the palm, fingers, wrist, forearm,
etc.
By
entering a number up to 6, a blue box appears over the pain area. If
greater
than 6, a black box appears (more severe pain). However, now when I
enter
an
"8" in the wrist box for record #1, all subsequent records show a
black
box
over the wrist even if they have a value of 0 or 2. I need this to be
RECORD
specific...I hope this makes sense.

---
Thank you! - Jennifer


:

Your first question was about Text8.
I see that your new question is about Text8 and Text10.
Is that a mistake?

(david)


message
David, I'm doing something wrong because no matter what number I
insert
(besides zero) only the blue box shows up - I never see the black
one.
Even
if I enter 8 or 9 - which are definitely greater than 6 - I still
don't
see
the black; just blue:

Private Sub Text8_AfterUpdate()

If Text8 = "0" Then
Me.Controls(RShoulderBlue.Name).Visible = False
Me.Controls(RShoulderBlack.Name).Visible = False
ElseIf Text10 < 6 Then
Me.Controls(RShoulderBlack.Name).Visible = False
Me.Controls(RShoulderBlue.Name).Visible = True
ElseIf Text10 > 6 Then
Me.Controls(RShoulderBlack.Name).Visible = True
Me.Controls(RShoulderBlue.Name).Visible = False
End If
End Sub
--
Thank you! - Jennifer


:


if text8 = 0 then

elseif text8 < 6 then

else

endif

(david)



in
message
I have a text box that the users enter a number between 1 and
10.
If
the
enter a number between 1 and 5, I want a blue box to appear;
if
between
6
and 10, I want a black box to appear. I've been able to code
it
partially
but
don't know how to make the range included (if between 6 and 10
then),
etc.
What I have so far is listed below - thank you!!!

Private Sub Text8_AfterUpdate()

If Text8 = "0" Then
Me.Controls(Yellow.Name).Visible = False
Me.Controls(Blue.Name).Visible = False
Else
Me.Controls(Yellow.Name).Visible = True
Me.Controls(Blue.Name).Visible = False
ELSe
Me.Controls(Yellow.Name).Visible = False
Me.Controls(Blue.Name).Visible = True

End If



End Sub
 
Back
Top