Advertisement
Guest User

Task 2 Code

a guest
Feb 22nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.     'These are the variables taht I will be using in this program
  3.    Dim PhoneKeywords(9) As String
  4.     Dim SearchWord As String
  5.     Dim answer As String
  6.     Dim response As String
  7.     Dim KeywordFound As String
  8.     Dim Test As String
  9.     Dim filename = "N:\PhoneKeywords.txt"
  10.     Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
  11.  
  12.         Test = "g"
  13.         'These are the keywords that will be identified
  14.  
  15.         PhoneKeywords(0) = "screen"
  16.         PhoneKeywords(1) = "sound"
  17.         PhoneKeywords(2) = "internet"
  18.         PhoneKeywords(3) = "water"
  19.         PhoneKeywords(4) = "turn"
  20.         PhoneKeywords(5) = "respond"
  21.         PhoneKeywords(6) = "blank"
  22.         PhoneKeywords(7) = "dropped"
  23.         PhoneKeywords(8) = "service"
  24.         PhoneKeywords(9) = "bluetooth"
  25.  
  26.         'This is the question that will be asked
  27.  
  28.         answer = InputBox("Welcome to the new and improved phone troubleshooter! What's wrong with your phone " & cmboxDevice.Text & " User?")
  29.  
  30.         Dim words As String() = answer.Split(New Char() {" "})
  31.  
  32.         'This part of the code identifies whether there is a keyword in the user's answer
  33.  
  34.         For Each word In words
  35.             For a = 0 To 9
  36.                 If word = PhoneKeywords(a) Then
  37.                     Test = (PhoneKeywords(a))
  38.                 End If
  39.             Next a
  40.         Next word
  41.  
  42.         KeywordFound = False
  43.  
  44.         'This takes a response to use depending on what keyword was found
  45.  
  46.         FileOpen(1, filename, OpenMode.Input)
  47.         Do While Not EOF(1)
  48.             Input(1, SearchWord)
  49.  
  50.             Input(1, response)
  51.             If Test = SearchWord Then
  52.                 MsgBox(response)
  53.                 KeywordFound = True
  54.             End If
  55.         Loop
  56.  
  57.         FileClose(1)
  58.  
  59.         'This part of the code makes the program show a message saying the user's answer was invalid if a keyword was not found in the user's answer
  60.  
  61.         If KeywordFound = False Then
  62.             MsgBox("Sorry, your answer was invalid, please try again")
  63.  
  64.         End If
  65.  
  66.  
  67.     End Sub
  68.  
  69.     Private Sub btnCreateFile_Click(sender As Object, e As EventArgs) Handles btnCreateFile.Click
  70.  
  71.         'These are the responses that will be shown depending on what keyword is identified in the user's answer
  72.        'They are all in a file called "Phone Keywords"
  73.  
  74.         FileOpen(1, filename, OpenMode.Append)
  75.  
  76.         WriteLine(1, "screen", "Cover any cracks if there are any and rub the screen with a cloth")
  77.  
  78.         WriteLine(1, "sound", "Consult a repair specialist. Until then, try using headphones")
  79.  
  80.         WriteLine(1, "internet", "Try contacting your internet service provider")
  81.  
  82.         WriteLine(1, "water", "Dry your phone off immediately and get any water out from the inside")
  83.  
  84.         WriteLine(1, "turn", "Charge it at the nearest power outlet")
  85.  
  86.         WriteLine(1, "respond", "Restart your phone and cool it down if it is overheating")
  87.  
  88.         WriteLine(1, "blank", "Leave your phone for a few hours  and try again. If this does not work, contact a repair specialist")
  89.  
  90.         WriteLine(1, "dropped", "Cover any cracks in the screen and see a repair specialist")
  91.  
  92.         WriteLine(1, "service", "Try contacting your service provider")
  93.  
  94.         WriteLine(1, "bluetooth", "Turn off bluetooth and turn it on again. If this fails, then check the device it is connecting to")
  95.  
  96.         FileClose(1)
  97.     End Sub
  98.  
  99.  
  100.  
  101. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement