469,900 Members | 1,437 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,900 developers. It's quick & easy.

restricting data that you can put into box?

I have a form which displays info. On top of it there is a text box for
input box which lets you put number from 1 thu 112.I need to verify that
the
number entered by the user is within the range of 1-12. If it isn't, notify
the user and set the focus back to the text box. Do not allow processing to
continue until a valid entry is entered in the textbox.
How can i achive that

Thanks in advance
Here is my code whats wrong with it?

Private Sub btnDisplayGifts_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDisplayGifts.Click

Dim intI, intJ, intNumDays, intDays As Integer

Dim strName, number As String

Dim dblPrice, dblTotalCost, dblGrandTotal As Double

Dim strSr As IO.StreamReader = IO.File.OpenText("Xmas.txt")

intNumDays = CInt(txtNumDays.Text)

If intNumDays <= 0 And intNumDays > 12 Then

Do

MsgBox("Please enter 1 thru 12 ", , " Number of Days")

txtNumDays.Text = ""

txtNumDays.Focus()

Loop Until (intNumDays > 0 And intNumDays < 12)

lstTable.Items.Clear()

lstTable.Items.Add("The gift for the day" & " " & intNumDays & " " & "are:")

End If

lstTable.Items.Clear()

lstTable.Items.Add("The gift for the day" & " " & intDays & " " & "are:")

For intI = 1 To intDays

strName = strSr.ReadLine

dblPrice = CDbl(strSr.ReadLine)

dblTotalCost += dblPrice * intI

lstTable.Items.Add(intI & "." & " " & strName)

Next

lstTable.Items.Add("Cost:" & "" & FormatCurrency(dblTotalCost, 2))

lstTable.Items.Add("")

strSr.Close()

End Sub
Nov 20 '05 #1
2 1117

This is what the if should look like:

If intNumDays >= 0 AndAlso intNumDays <= 12 Then

"AndAlso" is a new operator in vb.net that provides "short-
circuiting", which is simply when the first condition
fails the test it doesn't bother checking the second which
is a performance increase.

That should do you what you need.

Hope this helps.

Bart A. Robinson, MCP
-----Original Message-----
I have a form which displays info. On top of it there is a text box for input box which lets you put number from 1 thu 112.I need to verify thatthe
number entered by the user is within the range of 1-12. If it isn't, notifythe user and set the focus back to the text box. Do not allow processing tocontinue until a valid entry is entered in the textbox.
How can i achive that

Thanks in advance
Here is my code whats wrong with it?

Private Sub btnDisplayGifts_Click(ByVal sender As Object, ByVal e AsSystem.EventArgs) Handles btnDisplayGifts.Click

Dim intI, intJ, intNumDays, intDays As Integer

Dim strName, number As String

Dim dblPrice, dblTotalCost, dblGrandTotal As Double

Dim strSr As IO.StreamReader = IO.File.OpenText ("Xmas.txt")
intNumDays = CInt(txtNumDays.Text)

If intNumDays <= 0 And intNumDays > 12 Then

Do

MsgBox("Please enter 1 thru 12 ", , " Number of Days")

txtNumDays.Text = ""

txtNumDays.Focus()

Loop Until (intNumDays > 0 And intNumDays < 12)

lstTable.Items.Clear()

lstTable.Items.Add("The gift for the day" & " " & intNumDays & " " & "are:")
End If

lstTable.Items.Clear()

lstTable.Items.Add("The gift for the day" & " " & intDays & " " & "are:")
For intI = 1 To intDays

strName = strSr.ReadLine

dblPrice = CDbl(strSr.ReadLine)

dblTotalCost += dblPrice * intI

lstTable.Items.Add(intI & "." & " " & strName)

Next

lstTable.Items.Add("Cost:" & "" & FormatCurrency (dblTotalCost, 2))
lstTable.Items.Add("")

strSr.Close()

End Sub
.

Nov 20 '05 #2
This line is wrong: (IntNumDays can't be < 0 and > 12 at the same time)

If intNumDays <= 0 And intNumDays > 12 Then

It should read:

If intNumDays <= 0 Or intNumDays > 12 Then

Also, your DO loop dosen't give anyone a chance to enter the correct number.
It just keeps on going and going and going......

Try this instead:

Private Sub txtNumDay_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtNumDay.Validating

If intNumDays <= 0 And intNumDays > 12 Then
MsgBox("Please enter 1 thru 12 ", , " Number of Days")

txtNumDays.Text = ""

txtNumDays.Focus()

End if

End Sub

"W. Adam" <wa****@poczta.onet.pl> wrote in message
news:EA******************@newssrv26.news.prodigy.c om...
I have a form which displays info. On top of it there is a text box for
input box which lets you put number from 1 thu 112.I need to verify that
the
number entered by the user is within the range of 1-12. If it isn't, notify the user and set the focus back to the text box. Do not allow processing to continue until a valid entry is entered in the textbox.
How can i achive that

Thanks in advance
Here is my code whats wrong with it?

Private Sub btnDisplayGifts_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDisplayGifts.Click

Dim intI, intJ, intNumDays, intDays As Integer

Dim strName, number As String

Dim dblPrice, dblTotalCost, dblGrandTotal As Double

Dim strSr As IO.StreamReader = IO.File.OpenText("Xmas.txt")

intNumDays = CInt(txtNumDays.Text)
Loop Until (intNumDays > 0 And intNumDays < 12)
lstTable.Items.Clear()

lstTable.Items.Add("The gift for the day" & " " & intNumDays & " " &

"are:")
End If

lstTable.Items.Clear()

lstTable.Items.Add("The gift for the day" & " " & intDays & " " & "are:")

For intI = 1 To intDays

strName = strSr.ReadLine

dblPrice = CDbl(strSr.ReadLine)

dblTotalCost += dblPrice * intI

lstTable.Items.Add(intI & "." & " " & strName)

Next

lstTable.Items.Add("Cost:" & "" & FormatCurrency(dblTotalCost, 2))

lstTable.Items.Add("")

strSr.Close()

End Sub

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Xenophobe | last post: by
6 posts views Thread by Altramagnus | last post: by
2 posts views Thread by Brett Romero | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.