-
July 2nd, 2014, 12:18 AM
#1
Code to model a phone
Hi, just wondering if someone can look at my codes and see what's wrong.
Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
'Digit keys
Private Sub key1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key1.Click
callDisplay.Text &= 1 'Button for "1"
End Sub
Private Sub key2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key2.Click
callDisplay.Text &= 2 'Button for "2"
End Sub
Private Sub key3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key3.Click
callDisplay.Text &= 3 'Button for "3"
End Sub
Private Sub key4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key4.Click
callDisplay.Text &= 4 'Button for "4"
End Sub
Private Sub key5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key5.Click
callDisplay.Text &= 5 'Button for "5"
End Sub
Private Sub key6_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key6.Click
callDisplay.Text &= 6 'Button for "6"
End Sub
Private Sub key7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key7.Click
callDisplay.Text &= 7 'Button for "7"
End Sub
Private Sub key8_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key8.Click
callDisplay.Text &= 8 'Button for "8"
End Sub
Private Sub key9_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key9.Click
callDisplay.Text &= 9 'Button for "9"
End Sub
Private Sub key0_Click(ByVal sender As Object, ByVal e As EventArgs) Handles key0.Click
callDisplay.Text &= 0 'Button for "0"
End Sub
Private Sub keyNumsign_Click(ByVal sender As Object, ByVal e As EventArgs) Handles keyNumsign.Click
callDisplay.Text &= "#" 'Button for "#"
End Sub
Private Sub keyAsterisk_Click(ByVal sender As Object, ByVal e As EventArgs) Handles keyAsterisk.Click
callDisplay.Text &= "*" 'Button for "#"
End Sub
Private Sub keyDEL_Click(sender As Object, e As EventArgs) Handles keyDEL.Click
callDisplay.Text = callDisplay.Text.Remove(callDisplay.Text.Length - 1, 1) 'Delete the rightmost character currently shown on the display area
End Sub
Private Sub keyClear_Click(sender As Object, e As EventArgs) Handles keyClear.Click
callDisplay.Clear() 'Clears the display area
End Sub
Function displayLength() 'Phone number input user
'displayInput = callDisplay.Text.Replace("*", "").Replace("#", "") 'Remove "*" and "#" from the digit count
If callDisplay.Text.Length = 10 Then
Return 1 'Proceed with Rule#1-Local Call
ElseIf callDisplay.Text.Length = 11 Then
Return 2 'Proceed with Rule#2-Long Distance Call
ElseIf callDisplay.Text.Length = 12 Then
Return 3 'Proceed with Rule#3-Long Distance Call
ElseIf callDisplay.Text.Length = 3 Then
Return 4
Else
Return 5
End If
End Function
'Rules for dialing
Private Sub keySend_Click(ByVal sender As Object, e As EventArgs) Handles keySend.Click 'Case selector
Dim displayMsg As String
Dim caseSelector As Integer
caseSelector = displayLength(callDisplay.Text)
Select Case caseSelector
Case Is = 1 'When input length = 10
'If the number is 10 digits, it should not begin with “0”, “1”, “911”, or “555”.
If callDisplay.Text.Substring(0, 1) = "0" Or callDisplay.Text.Substring(0, 1) = "1" Then
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (invalid first digit)"
ElseIf callDisplay.Text.Substring(0, 3) = "911" Or callDisplay.Text.Substring(1, 3) = "911" Then
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (invalid prefix 911)"
ElseIf callDisplay.Text.Substring(0, 3) = "555" Or callDisplay.Text.Substring(1, 3) = "555" Then
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (invalid prefix 555)"
Else
displayMsg = callDisplay.Text & " Call Sent (Local)"
End If
callDisplay.Text = displayMsg
Case Is = 2 'When input length = 11
'If the number begins with a “1” it should be 11 digits – long distance.
If callDisplay.Text.Substring(0, 1) = "1" Then
displayMsg = callDisplay.Text & " Call Sent (long distance)"
ElseIf callDisplay.Text.IndexOf("555") = 1 Then
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (Invalid prefix 555)" 'if final 10 digits start with 911
ElseIf callDisplay.Text.IndexOf("911") = 1 Then
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (Invalid prefix 911)" 'if final 10 digits start with 911
Else
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (Invalid first digit)" 'if number starts with other digits
End If
callDisplay.Text = displayMsg
Case Is = 3 'When input length = 12
'If the number begins with “01” it should be 12 digits – long distance.
If callDisplay.Text.Substring(0, 2) = "01" Then
displayMsg = callDisplay.Text & " Call Sent (long distance)"
ElseIf callDisplay.Text.IndexOf("555") = 2 Then
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (Invalid prefix 555)" 'if number starts with 1555
ElseIf callDisplay.Text.IndexOf("911") = 2 Then
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (Invalid prefix 911)" 'if number starts with 1911
Else
displayMsg = "Can't Complete Call to: " & callDisplay.Text & "(Invalid first digit)"
End If
callDisplay.Text = displayMsg
Case Is = 4
If callDisplay.Text = "911" Then
displayMsg = callDisplay.Text & " Call Sent (Emergency)"
Else
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (Invalid length)"
End If
callDisplay.Text = displayMsg
Case Is = 5 'all other input length
displayMsg = "Can't Complete Call to: " & callDisplay.Text & " (Invalid length)"
callDisplay.Text = displayMsg
End Select
End Sub
End Class
I don't know why but I keep getting the message "No default member found for type 'Integer'"...
Also, what should I do to make the program to recognize input such as "222222222#" 9 digit + "#" is not a valid input?
Thanks!
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
|