Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.49 KB | None | 0 0
  1.     Function Checklength(S As String) As Boolean
  2.         Dim c As Integer = 0
  3.         Dim i As Integer = 0
  4.         Dim L As Integer = S.Length
  5.         Dim Yes As String
  6.         Do While i < L
  7.             If S.Substring(i, 1) < Asc("0") Or S.Substring(i, 1) > Asc("9") Then
  8.                 Yes = True
  9.  
  10.             Else
  11.                 i += 1
  12.  
  13.             End If
  14.  
  15.         Loop
  16.  
  17.         Return Yes
  18.  
  19.     End Function
  20.  
  21.     Private Sub Checkbutt_Click(sender As Object, e As EventArgs) Handles Checkbutt.Click
  22.         Dim S As String
  23.  
  24.         S = InputTexttxt.Text
  25.  
  26.         Checklength(S)
  27.  
  28.         MessageBox.Show(S)
  29.  
  30.     End Sub
  31. End Class
  32.  
  33.  
  34. The Assignment Question-
  35. Write a function that checks whether a string has a number based.  Use what we learned about Asc to complete the following:
  36.  
  37. Function CheckLength  (S As String) As Boolean
  38. ‘add a do loop to start at first character
  39. if Ascii current character is between Asc  (0) and Asc (9)
  40.  ‘then we have a hit  Return True
  41.  ‘else check the next character
  42.  ‘if loop is over, that means no hit was found Return False
  43. End Function
  44.  
  45. Use this function in an application that allows the user to enter the string/text that should be tested by your CheckLength  function.
  46.  
  47. The problem i am having. Not usre how i can convert from string to double here.
  48.  
  49. System.InvalidCastException
  50.   HResult=0x80004002
  51.   Message=Conversion from string "o" to type 'Double' is not valid.
  52.   Source=Microsoft.VisualBasic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement