VB学习第四周--字符函数验证

前端之家收集整理的这篇文章主要介绍了VB学习第四周--字符函数验证前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

字符函数验证:

  1. Public Class Form1
  2.  
  3. Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
  4. TextBox2.Text = Len(TextBox1.Text)
  5. Label2.Text = Button1.Text & "函数的结果"
  6. End Sub
  7.  
  8. Private Sub Button4_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button4.Click
  9. TextBox2.Text = Trim(TextBox1.Text)
  10. Label2.Text = Button4.Text & "函数的结果"
  11. End Sub
  12.  
  13. Private Sub Button5_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button5.Click
  14. Dim a%
  15. a = InputBox("请输入重复出现的次数(必须为数字)","StrDup函数")
  16. TextBox2.Text = StrDup(a,TextBox1.Text)
  17. Label2.Text = Button5.Text & "函数的结果"
  18. End Sub
  19.  
  20. Private Sub Button6_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button6.Click
  21. Dim b$
  22. b = InputBox("输入查找字串","InStr函数")
  23. TextBox2.Text = InStr(TextBox1.Text,b)
  24. Label2.Text = Button6.Text & "函数的结果"
  25. End Sub
  26.  
  27. Private Sub Button7_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button7.Click
  28. Dim c$,d$
  29. c = InputBox("输入需要替换的字符串","Replace函数")
  30. d = InputBox("输入替换后的字符串","Replace函数")
  31. TextBox2.Text = Replace(TextBox1.Text,c,d)
  32. Label2.Text = Button7.Text & "函数的结果"
  33. End Sub
  34.  
  35. Private Sub Button8_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button8.Click
  36. Dim m%,n%
  37. m = InputBox("输入从左开始取得位置(必须为数字)","Mid函数")
  38. n = InputBox("输入要取得字符数(必须为数字)","Mid函数")
  39. TextBox2.Text = Mid(TextBox1.Text,m,n)
  40. Label2.Text = Button8.Text & "函数的结果"
  41. End Sub
  42.  
  43. Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
  44.  
  45. End Sub
  46. End Class

猜你在找的VB相关文章