By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 1,987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

My code should return the speed but it doesnt, please help!!!!!

P: 1
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim startHour As Double
  3.     Dim startMinute As Double
  4.     Dim startSeconds As Double
  5.     Dim finalHour As Double
  6.     Dim finalMinute As Double
  7.     Dim finalSeconds As Double
  8.     Dim speed As Double
  9.     Dim x As Integer = 0
  10.     Dim distance As String
  11.  
  12.  
  13.  
  14.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  15.         Dim name As String
  16.         Dim array() As Char
  17.         Dim registration As String
  18.         Dim flag As Boolean = False
  19.  
  20.         If TextBox10.Text = "" Then
  21.             MessageBox.Show("please input a registration")
  22.         End If
  23.         If TextBox1.Text = "" Then
  24.             MessageBox.Show("please input a name")
  25.         End If
  26.  
  27.         If TextBox2.Text = "" Then
  28.             MessageBox.Show("please input distance (2miles)")
  29.         End If
  30.  
  31.         If TextBox3.Text = "" Then
  32.             MessageBox.Show("please input an hour for start time")
  33.         End If
  34.  
  35.         If TextBox4.Text = "" Then
  36.             MessageBox.Show("please input minutes for start time")
  37.         End If
  38.         If TextBox6.Text = "" Then
  39.             MessageBox.Show("please input seconds for start time")
  40.         End If
  41.         If TextBox7.Text = "" Then
  42.             MessageBox.Show("please input an hour for final time")
  43.         End If
  44.         If TextBox8.Text = "" Then
  45.             MessageBox.Show("please input minutes for final time")
  46.         End If
  47.         If TextBox9.Text = "" Then
  48.             MessageBox.Show("please input seconds for final time")
  49.         End If
  50.  
  51.  
  52.         registration = TextBox10.Text
  53.         name = TextBox1.Text
  54.         array = name.ToCharArray
  55.         distance = Val(TextBox2.Text)
  56.         startHour = Val(TextBox3.Text)
  57.         startMinute = Val(TextBox4.Text)
  58.         startSeconds = Val(TextBox6.Text)
  59.         finalHour = Val(TextBox7.Text)
  60.         finalMinute = Val(TextBox8.Text)
  61.         finalSeconds = Val(TextBox9.Text)
  62.  
  63.  
  64.  
  65.         x = 0
  66.         While flag = False And x <= Len(name) - 1
  67.             x = x + 1
  68.             If (Asc(array(x)) >= 65) And (Asc(array(x)) <= 122) Then
  69.                 flag = False
  70.             Else
  71.                 flag = True
  72.                 MessageBox.Show("please input only letters in textbox1")
  73.             End If
  74.  
  75.             While flag = False
  76.                 If (Asc(distance) = 50) Then
  77.                     flag = False
  78.                 Else
  79.                     flag = True
  80.                     MessageBox.Show("please input the set distance into textbox2 (2miles)")
  81.                 End If
  82.             End While
  83.         End While
  84.  
  85.         TextBox5.Text = speed
  86.  
  87.         Dim objWriter As System.IO.StreamWriter
  88.  
  89.         If speed > 70 Then
  90.             Try
  91.                 objWriter = New System.IO.StreamWriter("N:\MY WORK\notepad.txt")
  92.                 objWriter.Write(registration & System.Environment.NewLine)
  93.                 objWriter.Close()
  94.                 TextBox1.Text = ""
  95.             Catch ex As Exception
  96.  
  97.             End Try
  98.         End If
  99.     End Sub
  100.  
  101.     Private Function timeTaken() As Double
  102.         Dim startTime As Double
  103.         Dim finalTime As Double
  104.  
  105.  
  106.  
  107.         startTime = (startHour) + (startMinute / 60) + (startSeconds / 3600)
  108.         finalTime = (finalHour) + (finalMinute / 60) + (finalSeconds / 3600)
  109.  
  110.         timeTaken = (finalTime - startTime)
  111.  
  112.         speed = (distance / timeTaken)
  113.         TextBox5.Text = speed
  114.     End Function
  115.  
  116.  
  117. End Class
May 16 '15 #1
Share this Question
Share on Google+
1 Reply


Seth Schrock
Expert 2.5K+
P: 2,941
Speed is never calculated. You declare it in line 8, but it never is given a value. You have the calculation in the function timeTaken, but that function is never called so it is never executed.
May 17 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.