|
-
Nov 15th, 2000, 04:38 PM
#1
Thread Starter
Frenzied Member
how do i see if the number in the text box is between 2 and 8 (the number entered will be a whole number)
NXSupport - Your one-stop source for computer help
-
Nov 15th, 2000, 04:42 PM
#2
_______
<?>
Code:
Private Sub Command1_Click()
If Val(Text1) >= 2 And Val(Text1) <= 8 Then MsgBox "OK"
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 15th, 2000, 04:43 PM
#3
Frenzied Member
Code:
If number < 9 and number >1 then
'number is between 8 and 2
Ens If
-
Nov 15th, 2000, 04:44 PM
#4
Addicted Member
Would this meet your needs?
Code:
If CInt(Text1.Text) >= 2 and CInt(Text1.Text) <= 8 Then
Msgbox "The number is between 2 and 8."
Else
Msgbox "The number is NOT between 2 and 8."
End If
Hope this helps.
Micahel Woolsey
Application/Web Developer
Visual Basic 6.0 SP5
Active Server Pages
Oracle 9i
- I'm going to live forever, or die trying!
-
Nov 15th, 2000, 04:47 PM
#5
Thread Starter
Frenzied Member
NXSupport - Your one-stop source for computer help
-
Nov 15th, 2000, 07:47 PM
#6
Member
more way
if asc(text1.text)>=2 and asc(text1.text)<=8 then
'ok for now..
end if
-
Nov 15th, 2000, 09:13 PM
#7
_______
<?>
dealman:
the correct syntax would be this.
If Asc(Text1) >= 50 And Asc(Text1) <= 56 Then MsgBox "OK"
Vlatko:
the correct syntax would be this.
Dim number As Integer
number = Val(Text1)
If number < 9 And number > 1 Then MsgBox "OK"
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 16th, 2000, 01:50 AM
#8
Fanatic Member
Function for different values
Here's a more robust function:
Code:
Private Function IsInRange(ByVal num as Integer, ByVal min as Integer, ByVal max as Integer) as Boolean
'Set a default return value
IsInRange = False
If (num => min) and (num <= max) Then
IsInRange = True
End If
End Function
'Usage:
If IsInRange(Val(Text1), 2, 8) Then
MsgBox "OK"
Else
MsgBox "Not OK"
End If
'Or check a number between 5 and 25
If IsInRange(Val(Text1), 5, 25) Then
MsgBox "OK"
Else
MsgBox "Not OK"
End If
[Edited by r0ach on 11-16-2000 at 01:52 AM]
r0ach™
Don't forget to rate the post
-
Nov 16th, 2000, 03:52 AM
#9
transcendental analytic
keeping it simple
it would be better if VB could do real integer division 
Code:
If Int((num - 2) / 7) = 1 Then Msgbox "In range!"
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 16th, 2000, 06:08 AM
#10
Addicted Member
Me too!
This looks like fun. I also want a go:
Code:
Select Case Val(txtNumber.Text)
Case 2 to 8
'It's in range
Case Else
'Not in range
End Select
Shrog
-
Nov 16th, 2000, 06:35 AM
#11
Fanatic Member
kedaman,
for Integers between 2 and 8 inclusively, Int((num -2)/7) equates to zero, not 1!!!
Being really picky, the only integers between 2 and 8 are 3, 4, 5, 6 and 7. 2 and 8 are on the boundaries!
Cheers,
Paul.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Nov 16th, 2000, 10:09 PM
#12
transcendental analytic
love you paul! I think it's even better when you can leave out the equal operator! thanks for noticing my bug 
Code:
if Int((x - 3) / 5) then
'out of bounds
else
'inside bounds
end if
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 17th, 2000, 05:58 AM
#13
Fanatic Member
Love you too - but don't tell my wife!
Here's to really confusing coding (hehehe)
P.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Nov 17th, 2000, 06:55 AM
#14
Kedaman, Paul:
Isn't an integer division this > \ instead of / ???
Just thought it was...
-
Nov 17th, 2000, 07:02 AM
#15
Fanatic Member
I've not come across that. Have you an example?
P.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Nov 17th, 2000, 07:45 AM
#16
Addicted Member
Yes it is.
Code:
'These two line are the same
X = Y \ Z
X = Int(Y / Z)
People tend to miss it though, so I find that I have to put comments in my coding to point out that I am using "\" instead of "/". Most of the time it's simpler to just use the Int function, to avoid confusion.
Shrog
-
Nov 17th, 2000, 09:20 AM
#17
Guru
Originally posted by Shrog
Code:
' These two line are the same
X = Y \ Z
X = Int(Y / Z)
Not exactly. 
Code:
X = 3.6 \ 4 ' X = 1
X = Int(3.6 / 4) ' X = 0
-
Nov 17th, 2000, 09:40 AM
#18
Fanatic Member
Duh. I thought the operator was ">\".
Retires from the arena in shame...
Cheers,
P.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Nov 17th, 2000, 11:43 AM
#19
Junior Member
hope this works
Exit Sub 'you will remove this line in Lesson A
Dim intX As Integer, intDem As Integer, intRep As Integer
Dim intInd As Integer, intTotal As Integer
Dim strFont As String, sngSize As Single
Dim strPS1 As String * 3, strPS2 As String * 3, strPS3 As String * 3
Dim strPS4 As String * 3, strPS5 As String * 4
'accumulate totals
For intX = 0 To 3
intDem = intDem + Val(lblDem(intX).Caption)
intRep = intRep + Val(lblRep(intX).Caption)
intInd = intInd + Val(lblInd(intX).Caption)
Next intX
intTotal = intDem + intRep + intInd
strFont = Printer.Font 'save current printer settings
sngSize = Printer.FontSize
Printer.Font = "courier new" 'change printer settings
Printer.FontSize = 10 'print title and headings
Printer.Print Tab(30); "PAO Information - 1999"
Printer.Print
Printer.Print Tab(5); "Party"; Tab(20); "18-35"; Tab(30); "36-50"; _
Tab(40); "51-65"; Tab(50); "Over 65"; Tab(60); "Total"
'align democrat numbers and print
RSet strPS1 = Format(lblDem(0).Caption, "general number")
RSet strPS2 = Format(lblDem(1).Caption, "general number")
RSet strPS3 = Format(lblDem(2).Caption, "general number")
RSet strPS4 = Format(lblDem(3).Caption, "general number")
RSet strPS5 = Format(intDem, "general number")
Printer.Print Tab(5); "Democrat"; Tab(22); strPS1; Tab(32); strPS2; _
Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5
'align republican numbers and print
RSet strPS1 = Format(lblRep(0).Caption, "general number")
RSet strPS2 = Format(lblRep(1).Caption, "general number")
RSet strPS3 = Format(lblRep(2).Caption, "general number")
RSet strPS4 = Format(lblRep(3).Caption, "general number")
RSet strPS5 = Format(intRep, "general number")
Printer.Print Tab(5); "Republican"; Tab(22); strPS1; Tab(32); strPS2; _
Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5
'align independent numbers and print
RSet strPS1 = Format(lblInd(0).Caption, "general number")
RSet strPS2 = Format(lblInd(1).Caption, "general number")
RSet strPS3 = Format(lblInd(2).Caption, "general number")
RSet strPS4 = Format(lblInd(3).Caption, "general number")
RSet strPS5 = Format(intInd, "general number")
Printer.Print Tab(5); "Independent"; Tab(22); strPS1; Tab(32); strPS2; _
Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5
Printer.Print 'print two blank lines
Printer.Print
'print grand total
RSet strPS5 = Format(intTotal, "general number")
Printer.Print Tab(41); "Total respondents"; Tab(61); strPS5
Printer.Print 'print a blank line
Printer.Print Tab(5); "End of report" 'print message
Printer.EndDoc 'send report to printer
Printer.Font = strFont
Printer.FontSize = sngSize
End Sub
Private Sub Form_Load()
frmPao.Top = (Screen.Height - frmPao.Height) / 2
frmPao.Left = (Screen.Width - frmPao.Width) / 2
lstAge.AddItem "18 - 35"
lstAge.AddItem "36 - 50"
lstAge.AddItem "51 - 65"
lstAge.AddItem "Over 65"
End Sub
-
Nov 17th, 2000, 12:01 PM
#20
???
Ok...WHat the hell was that?... SOme sort of Voting ballot??
I thought this was the 'Every possible way to determine if a number is between 2 and 8' Board.
BTW.. everyone forgot the worst (or really the first way you every try it when you learn VB) way.
Code:
If X = 3 or X = 4 or X = 5 or X = 6 or X = 7 then
'Do Code
Else
'Do Whatever
End if
this is of course assuming that the variable is Declared an integer.
Sorry couldn't resist!!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 17th, 2000, 12:22 PM
#21
Fanatic Member
Geoff_xrx, this is even more worse...
Code:
Dim X 'evil variant
Dim InRange 'is it in the range
'do a select case on x
Select Case X
Case 3
'it's in the range
InRange = True
Case 4
'it's in the range
InRange = True
Case 5
'it's in the range
InRange = True
Case 6
'it's in the range
InRange = True
Case 7
'it's in the range
InRange = True
Case Else
'not in the range
InRange = False
End Select
'is it in the range?
If InRange = True Then
Msgbox "It's between 2 and 8"
Else
Msgbox "It's not between 2 and 8"
End If
-
Nov 17th, 2000, 04:11 PM
#22
Addicted Member
Boy, This is the 2nd thread I've seen that just drags on about a simple thing!
If the first reply (which in this case it did) seem to answer the question why add more replies???
I know sometimes you guys have some none standard/generic method of doing things and yes they may be interesting and/or worth learning but this one is just ridiculous!!! 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|