Ski Lodge Reservation Program

Create a VB program to accept and display reservations in a list box

Page 1 of 1

10 Replies - 1516 Views - Last Post: 30 November 2009 - 08:33 PM Rate Topic: -----

#1 Kilborndj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 14-November 09

Ski Lodge Reservation Program

Posted 24 November 2009 - 04:13 PM

So after 3 days of working with this. I can not find the proper way to verify characters only in a text box. I am having a hell of a time trying to understand all that. I have 3 errors in my code. One error is "Error-Reference to a non-shared member requires an object reference." the other two errors are in reference to an explicit conversion from string to double. strName is what I am using as my variable for the input of the name in txtName.text Below is my full code. "----" are used to separate the classes.

Attached documents are in .PDF format and HAVE TO BE FOLLOWED to the letter. Pages 2 & 3 contains the UML diagram as well as how the project should look and the structure chart for the code

Last note. I am not truly sure if my DisplayReservation is what will work to use in the list box. Is there any other reference I could get to help me understand how to use a list box as the project requires.

'********************************************************
' Name: Dave Johnson
' Date: 24 November 2009
' Project: Lab 8 - Ski Lodge Reservation
' Purpose: This program takes input of name and how many nights the person staying
' then displays them in a list box and accurately caluclates the price of the total stay
'********************************************************
Public Class frmReservations
	Private Sub btnReserve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReserve.Click

		'Obstantiate object
		Dim objRoom As Reservation
		objRoom = New Reservation

		'declare variables
		Dim strName As String
		Dim intNights As Integer
		Dim decPrice As Decimal

		If IsValid(strName, intNights) Then
			With objRoom
				.Name = strName
				.Nights = intNights
			End With

			'Call Display Reservation
			Call DisplayReservation(objRoom, strName, intNights, decPrice)

		End If

	End Sub
	Private Function IsValidName(ByRef strName As String) As Boolean

		Dim IsValid As Boolean
		Const c_MinName As Decimal = 3
		Const c_MaxName As Decimal = 15

		IsValid = False

		If String.Length(txtName.Text, strName) AndAlso _
			strName > c_MinName AndAlso strName <= c_MaxName Then
			IsValid = True
		End If
		If IsValid = False Then
			MessageBox.Show(String.Format("Name length must be bettween {0} and {1}", _
										 c_MinName, c_MaxName))
			txtName.Focus()
			txtName.SelectAll()
			IsValid = False
		End If
		Return IsValid
	End Function

	Private Function IsValidNights(ByRef intNights As Integer) As Boolean
		'Declare variables
		Dim IsValid As Boolean

		'Declare Constants
		Const c_MinNights As Integer = 1
		Const c_MaxNights As Integer = 30

		'Reset IsValid
		IsValid = False

		'Validate proper entry of nights (integer)
		If Integer.TryParse(txtNights.Text, intNights) AndAlso _
			intNights > c_MinNights AndAlso intNights <= c_MaxNights Then
			IsValid = True
		End If
		If IsValid = False Then
			MessageBox.Show(String.Format("Please enter whole number between {0} and {1}", _
									  c_MinNights, c_MaxNights))
			txtNights.Focus()
			txtNights.SelectAll()
			IsValid = False
		End If

		Return IsValid
	End Function

	Private Function IsValid(ByRef strName As String, ByRef intNights As Integer) As Boolean
		Return IsValidName(strName) And IsValidNights(intNights)
	End Function
	   
 Private Sub DisplayReservation(ByVal objPtr As Reservation, ByVal strName As String, ByVal intNights As Integer, ByRef decPrice As Decimal)
		lstReservations.Items.Add(String.Format("{0,-15} {1,9:c} {0,9:c}", strName, intNights, decPrice))
	End Sub
	'Clear All data from fields.  
	
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
		txtName.Clear()
		txtNights.Clear()
		lstReservations.ResetText()
		txtName.Focus()
	End Sub

End Class


"-------------------------------------------------------------------------------"
Public Class Reservation

	Private m_sName As String
	Public Property Name() As String
		Get
			Return m_sName
		End Get
		Set(ByVal value As String)
			m_sName = value
		End Set
	End Property

	Private m_iNights As Integer
	Public Property Nights() As Integer
		Get
			Return m_iNights
		End Get
		Set(ByVal value As Integer)
			m_iNights = value
		End Set
	End Property
	
Public Function Price() As Decimal

		Return Nights * 100
	End Function
End Class

[attachment=15076:attachment][attachment=15076:attachment]

This post has been edited by Kilborndj: 24 November 2009 - 04:15 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Ski Lodge Reservation Program

#2 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Ski Lodge Reservation Program

Posted 24 November 2009 - 11:49 PM

Hi,

Please indicate in your code, where you get the errors with comments..

like


'get error "Error-Reference to a non-shared member requires an object reference." here




This is how i would check for numbers

	 If IsNumeric(Textbox1.Text) = True Then

	 Else

	 End If



Also just a question, why do you wan't characters only in your text box? (You could make it Characters only by handling the KeyPress Event.)

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
		Select Case e.KeyChar
			Case "1"
				e.KeyChar = ""
			Case "2"
				e.KeyChar = ""
			Case "3"
				e.KeyChar = ""
			Case "4"
				e.KeyChar = ""
			Case "5"
				e.KeyChar = ""
			Case "6"
				e.KeyChar = ""
			Case "7"
				e.KeyChar = ""
			Case "8"
				e.KeyChar = ""
			Case "9"
				e.KeyChar = ""
			Case Else

		End Select
		 
	End Sub


Was This Post Helpful? 0
  • +
  • -

#3 Kilborndj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 14-November 09

Re: Ski Lodge Reservation Program

Posted 25 November 2009 - 10:34 AM

Motcom,
If String.Length(txtName.Text, strName) AndAlso _
			strName > c_MinName AndAlso strName <= c_MaxName Then
			IsValid = True
		End If
		If IsValid = False Then
			MessageBox.Show(String.Format("Name length must be bettween {0} and {1}", _
										 c_MinName, c_MaxName))
			txtName.Focus()
			txtName.SelectAll()
			IsValid = False
		End If


this is the area that is having the 1st error. Error = "Reference to a non shared member requires a reference"

'********************************************************************************************

To answer your question. I have to validate any and all input because that is what is required by my professor. I am wanting to only be able to allow only letters because it would gain me 10 extra points. But if I can't get that, then I'll suffice for just being able to verify the length of the name is 3-15 characters long. I posted the specifications in a .PDF if you haven't seen them. The txtName.text is the only one I am having a problem of verifying. Any suggestion would be greatly appreciated. txtNights.text is fine, I have that handled just fine.

I think I understand the keypress event handler for the text box. But would I have to write a 26+ letter case to only allow Letters and what about the backspace key? I have to allow a backspace in case someone is stupid enough to misspell a name.

'********************************************************************************************


View Postmotcom, on 24 Nov, 2009 - 10:49 PM, said:

Hi,

Please indicate in your code, where you get the errors with comments..

like


'get error "Error-Reference to a non-shared member requires an object reference." here




This is how i would check for numbers

	 If IsNumeric(Textbox1.Text) = True Then

	 Else

	 End If



Also just a question, why do you wan't characters only in your text box? (You could make it Characters only by handling the KeyPress Event.)

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
		Select Case e.KeyChar
			Case "1"
				e.KeyChar = ""
			Case "2"
				e.KeyChar = ""
			Case "3"
				e.KeyChar = ""
			Case "4"
				e.KeyChar = ""
			Case "5"
				e.KeyChar = ""
			Case "6"
				e.KeyChar = ""
			Case "7"
				e.KeyChar = ""
			Case "8"
				e.KeyChar = ""
			Case "9"
				e.KeyChar = ""
			Case Else

		End Select
		 
	End Sub


Was This Post Helpful? 0
  • +
  • -

#4 ScottD  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 25-November 09

Re: Ski Lodge Reservation Program

Posted 25 November 2009 - 01:21 PM

Not quite sure about your error as I didn't really read into it, but here is a better code example for checking you text.

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
		If Asc(e.KeyChar) > 64 And Asc(e.KeyChar) < 91 Then 'Caps
			e.KeyChar = e.KeyChar
		ElseIf Asc(e.KeyChar) > 96 And Asc(e.KeyChar) < 123 Then 'Lower case
			e.KeyChar = e.KeyChar
		ElseIf Asc(e.KeyChar) = 8 Then 'Backspace
			e.KeyChar = e.KeyChar
		Else
			e.KeyChar = ""
		End If
	End Sub


That can no doubt be refined, but it's the day before Thanksgiving, and my coding brain has already shut down. Hope that helps.

This post has been edited by ScottD: 25 November 2009 - 01:26 PM

Was This Post Helpful? 0
  • +
  • -

#5 Kilborndj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 14-November 09

Re: Ski Lodge Reservation Program

Posted 25 November 2009 - 01:26 PM

That does help. How do I verify length though. It has to be between 3 and 15 characters long. I think that is the problem with the error. I am using something different to check length, and it's associated with numerics. But yours prevents any other character from being entered? I'll have to find out how to prevent a "." from being entered in the txtNights.Textbox as well. thank you very much!

Dave "Kilborn"

View PostScottD, on 25 Nov, 2009 - 12:21 PM, said:

Not quite sure about your error as I didn't really read into it, but here is a better code example for checking you text.

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
		If Asc(e.KeyChar) > 64 And Asc(e.KeyChar) < 91 Then
			e.KeyChar = e.KeyChar
		ElseIf Asc(e.KeyChar) > 96 And Asc(e.KeyChar) < 123 Then
			e.KeyChar = e.KeyChar
		Else
			e.KeyChar = ""
		End If
End Sub


Also, you will need to add another line in there for backspace. Noticed that after I posted the code.

That can no doubt be refined, but it's the day before Thanksgiving, and my coding brain has already shut down. Hope that helps.

Was This Post Helpful? 0
  • +
  • -

#6 ScottD  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 25-November 09

Re: Ski Lodge Reservation Program

Posted 25 November 2009 - 01:28 PM

View PostKilborndj, on 25 Nov, 2009 - 12:26 PM, said:

That does help. How do I verify length though. It has to be between 3 and 15 characters long. I think that is the problem with the error. I am using something different to check length, and it's associated with numerics. But yours prevents any other character from being entered? I'll have to find out how to prevent a "." from being entered in the txtNights.Textbox as well. thank you very much!

Dave "Kilborn"

View PostScottD, on 25 Nov, 2009 - 12:21 PM, said:

Not quite sure about your error as I didn't really read into it, but here is a better code example for checking you text.

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
		If Asc(e.KeyChar) > 64 And Asc(e.KeyChar) < 91 Then
			e.KeyChar = e.KeyChar
		ElseIf Asc(e.KeyChar) > 96 And Asc(e.KeyChar) < 123 Then
			e.KeyChar = e.KeyChar
		Else
			e.KeyChar = ""
		End If
End Sub


Also, you will need to add another line in there for backspace. Noticed that after I posted the code.

That can no doubt be refined, but it's the day before Thanksgiving, and my coding brain has already shut down. Hope that helps.


I fixed the backspace for you. Let me code you up an example for len.

EDIT:

See if this helps you:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
		If Len(TextBox1.Text) < 3 Or Len(TextBox1.Text) > 15 Then
			Button1.Enabled = False
		Else
			Button1.Enabled = True
		End If
	End Sub

This post has been edited by ScottD: 25 November 2009 - 01:34 PM

Was This Post Helpful? 0
  • +
  • -

#7 ScottD  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 25-November 09

Re: Ski Lodge Reservation Program

Posted 25 November 2009 - 01:37 PM

View PostKilborndj, on 25 Nov, 2009 - 12:26 PM, said:

That does help. How do I verify length though. It has to be between 3 and 15 characters long. I think that is the problem with the error. I am using something different to check length, and it's associated with numerics. But yours prevents any other character from being entered? I'll have to find out how to prevent a "." from being entered in the txtNights.Textbox as well. thank you very much!

Dave "Kilborn"


That code prevents everything but upper case, lower case, and backspace. Just add it to the code for the other text boxes and it will work for them as well. If you need other characters, just look up their ascii code and apply as needed.

This post has been edited by ScottD: 25 November 2009 - 01:38 PM

Was This Post Helpful? 0
  • +
  • -

#8 Kilborndj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 14-November 09

Re: Ski Lodge Reservation Program

Posted 25 November 2009 - 03:11 PM

Scott,
I want to say that I really do appreciate the help. This has really helped A TON! Take your time on any help your giving me. I have a feeling that my professor will "light the way" come this Saturday. I am just trying to get as much complete as possible, so that I can enjoy my Turkey-A-La-King on Saturday Night!!!

So this is what I have now. There is a problem though. Shown in code below. As comments. I have to have {option strict = on, option explicit= on} for this class. Is there another way around this? If I am reading this correctly, without the e.KeyChar = "" it will still allow those inputs to be entered. Yes?
Private Sub txtName_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress
		If Asc(e.KeyChar) > 64 And Asc(e.KeyChar) < 91 Then
			e.KeyChar = e.KeyChar
		ElseIf Asc(e.KeyChar) > 96 And Asc(e.KeyChar) < 123 Then
			e.KeyChar = e.KeyChar
		Else
			e.KeyChar = "" ' Error = Option Strict On disallows conversion from string to char.
		End If
	End Sub

	Private Sub txtNights_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNights.KeyPress
		If Asc(e.KeyChar) = 46 Then
			e.KeyChar = "" ' Error = Option Strict On disallows conversion from string to char.
		End If
	End Sub



So now this is my otherl problem. I input your length code into mine...I just hope I used it correctly. I did modify it to fit my IsValid idea...(Which is required) but I don't think it works though. I keep getting both error messages when i should only get one.

I am wanting it to stop at the first error, ask to fix then continue once they have input the correct data. So far, this checks both errors and then returns both message errors, one after the other. Code below
	Private Function IsValidName(ByRef strName As String) As Boolean

		Dim IsValid As Boolean
		Const c_MinName As Decimal = 3
		Const c_MaxName As Decimal = 15

		IsValid = False

		If Len(txtName.Text) > c_MinName And Len(txtName.Text) <= c_MaxName Then
			IsValid = True
		Else
			IsValid = False
		End If
		If IsValid = False Then
			MessageBox.Show(String.Format("Name length must be bettween {0} and {1}", _
										 c_MinName, c_MaxName))
			txtName.Focus()
			txtName.SelectAll()
			IsValid = False
		End If
		Return IsValid
	End Function

	Private Function IsValidNights(ByRef intNights As Integer) As Boolean
		'Declare variables
		Dim IsValid As Boolean

		'Declare Constants
		Const c_MinNights As Integer = 1
		Const c_MaxNights As Integer = 30

		'Reset IsValid
		IsValid = False

		'Validate proper entry of nights (integer)
		If Integer.TryParse(txtNights.Text, intNights) AndAlso _
			intNights > c_MinNights AndAlso intNights <= c_MaxNights Then
			IsValid = True
		End If
		If IsValid = False Then
			MessageBox.Show(String.Format("Please enter whole number between {0} and {1}", _
									  c_MinNights, c_MaxNights))
			txtNights.Focus()
			txtNights.SelectAll()
			IsValid = False
		End If

		Return IsValid


I will get my professor or another tutor at school to help me figure out the display in the Listbox. With what I have now, it does take the amount of nights, converts to $ and displays it on 1 column of the listbox. So far this is a WAY better improvement. Thank you so much!

May I ask, what the heck is this talking about? I believe it means that this variable is being passed before it has been given a value and therefor might come up with something funky? (in a short short version)
But maybe you can explain?
 If IsValid(strName, intNights) Then ' Warning = Variable 'strName' is passed by reference before it has been assigned a value. A null reference exception could result at runtime.

			With objRoom
				.Name = strName
				.Nights = intNights
			End With



View PostScottD, on 25 Nov, 2009 - 12:37 PM, said:

That code prevents everything but upper case, lower case, and backspace. Just add it to the code for the other text boxes and it will work for them as well. If you need other characters, just look up their ascii code and apply as needed.

Was This Post Helpful? 0
  • +
  • -

#9 ScottD  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 25-November 09

Re: Ski Lodge Reservation Program

Posted 30 November 2009 - 08:55 AM

View PostKilborndj, on 25 Nov, 2009 - 02:11 PM, said:

Scott,
I want to say that I really do appreciate the help. This has really helped A TON! Take your time on any help your giving me. I have a feeling that my professor will "light the way" come this Saturday. I am just trying to get as much complete as possible, so that I can enjoy my Turkey-A-La-King on Saturday Night!!!

So this is what I have now. There is a problem though. Shown in code below. As comments. I have to have {option strict = on, option explicit= on} for this class. Is there another way around this? If I am reading this correctly, without the e.KeyChar = "" it will still allow those inputs to be entered. Yes?
Private Sub txtName_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress
		If Asc(e.KeyChar) > 64 And Asc(e.KeyChar) < 91 Then
			e.KeyChar = e.KeyChar
		ElseIf Asc(e.KeyChar) > 96 And Asc(e.KeyChar) < 123 Then
			e.KeyChar = e.KeyChar
		Else
			e.KeyChar = "" ' Error = Option Strict On disallows conversion from string to char.
		End If
	End Sub

	Private Sub txtNights_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNights.KeyPress
		If Asc(e.KeyChar) = 46 Then
			e.KeyChar = "" ' Error = Option Strict On disallows conversion from string to char.
		End If
	End Sub



So now this is my otherl problem. I input your length code into mine...I just hope I used it correctly. I did modify it to fit my IsValid idea...(Which is required) but I don't think it works though. I keep getting both error messages when i should only get one.

I am wanting it to stop at the first error, ask to fix then continue once they have input the correct data. So far, this checks both errors and then returns both message errors, one after the other. Code below
	Private Function IsValidName(ByRef strName As String) As Boolean

		Dim IsValid As Boolean
		Const c_MinName As Decimal = 3
		Const c_MaxName As Decimal = 15

		IsValid = False

		If Len(txtName.Text) > c_MinName And Len(txtName.Text) <= c_MaxName Then
			IsValid = True
		Else
			IsValid = False
		End If
		If IsValid = False Then
			MessageBox.Show(String.Format("Name length must be bettween {0} and {1}", _
										 c_MinName, c_MaxName))
			txtName.Focus()
			txtName.SelectAll()
			IsValid = False
		End If
		Return IsValid
	End Function

	Private Function IsValidNights(ByRef intNights As Integer) As Boolean
		'Declare variables
		Dim IsValid As Boolean

		'Declare Constants
		Const c_MinNights As Integer = 1
		Const c_MaxNights As Integer = 30

		'Reset IsValid
		IsValid = False

		'Validate proper entry of nights (integer)
		If Integer.TryParse(txtNights.Text, intNights) AndAlso _
			intNights > c_MinNights AndAlso intNights <= c_MaxNights Then
			IsValid = True
		End If
		If IsValid = False Then
			MessageBox.Show(String.Format("Please enter whole number between {0} and {1}", _
									  c_MinNights, c_MaxNights))
			txtNights.Focus()
			txtNights.SelectAll()
			IsValid = False
		End If

		Return IsValid


I will get my professor or another tutor at school to help me figure out the display in the Listbox. With what I have now, it does take the amount of nights, converts to $ and displays it on 1 column of the listbox. So far this is a WAY better improvement. Thank you so much!

May I ask, what the heck is this talking about? I believe it means that this variable is being passed before it has been given a value and therefor might come up with something funky? (in a short short version)
But maybe you can explain?
 If IsValid(strName, intNights) Then ' Warning = Variable 'strName' is passed by reference before it has been assigned a value. A null reference exception could result at runtime.

			With objRoom
				.Name = strName
				.Nights = intNights
			End With



View PostScottD, on 25 Nov, 2009 - 12:37 PM, said:

That code prevents everything but upper case, lower case, and backspace. Just add it to the code for the other text boxes and it will work for them as well. If you need other characters, just look up their ascii code and apply as needed.


Ok, a quick look over @ your Option Strict / Explicit problem,

replace
e.KeyChar = ""
with
e.KeyChar = Nothing

But I think you may have already had your class. Sorry I couldn't help with that, was out of town for the holiday.
Was This Post Helpful? 1
  • +
  • -

#10 Kilborndj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 14-November 09

Re: Ski Lodge Reservation Program

Posted 30 November 2009 - 07:03 PM

Scott, I did manage to find how to prevent input of certain characters. This is what I found in my research. It works too! In VB express 2008, the "Backspace" key is represented by some funky symbol. It doesn't copy well and so I had to switch to Asc(e.KeyChar) values. You really helped me on this, thank you very much!

Gratzi
Dave "Kilborn"

  Private Sub txtName_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress

		If e.KeyChar >= "A" And e.KeyChar <= "Z" Then 'Allows Capital A-Z
			e.KeyChar = e.KeyChar
		ElseIf e.KeyChar >= "a" And e.KeyChar <= "z" Then 'Allows lowercase a-z
			e.KeyChar = e.KeyChar
		ElseIf e.KeyChar = "." Then
			If txtName.Text.IndexOf(".") > -1 Then 'Allows " . " and prevents more than 1 " . "
				e.Handled = True
			End If
		ElseIf Asc(e.KeyChar) = 8 Then
					e.KeyChar = e.KeyChar
		ElseIf e.KeyChar = " " Then 'Allows "Spacebar" to be used
			e.KeyChar = e.KeyChar
		Else
			e.Handled = True 'Disallows all others keys and chars in txtName.Text
		End If

Private Sub txtNights_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNights.KeyPress

		If e.KeyChar >= "0" And e.KeyChar <= "9" Then 'Allows only numbers
			e.KeyChar = e.KeyChar
		ElseIf Asc(e.KeyChar) = 8 Then
				e.KeyChar = e.KeyChar
		ElseIf e.KeyChar = " " Then 'Allows "Spacebar" to be used
			e.KeyChar = e.KeyChar
		Else
			e.Handled = True  'Disallows all other characters from being used on txtNights.Text
		End If
	End Sub


Was This Post Helpful? 0
  • +
  • -

#11 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Ski Lodge Reservation Program

Posted 30 November 2009 - 08:33 PM

try this for the first field -
If Not (IsWhiteSpace(e.KeyChar) Or IsLetter(e.KeyChar) Or (Asc(e.KeyChar) = 8) Or ((e.KeyChar = ".") And (txtName.Text.IndexOf(".") <> -1) Then
   e.Handled = True
End If


Extension to the second field is left as an exercise for the reader - hint IsDigit...
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1