乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: mark

检索文本框文本的示例代码

[复制链接]

194

主题

592

帖子

11

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1380
发表于 2006-10-17 17:35:32 | 显示全部楼层
谢谢你,迈克尔
I'我明天早上试一试
回复

使用道具 举报

194

主题

592

帖子

11

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1380
发表于 2006-10-17 17:39:18 | 显示全部楼层
我的荣幸,希望有帮助
回复

使用道具 举报

194

主题

592

帖子

11

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1380
发表于 2006-10-17 19:12:55 | 显示全部楼层
对于那些由于工作地点的安全设置而无法下载的用户,这里是代码
首先,名为frmMain的表单有3个控件: CommandButton,名为btnOk CommandButton,名为btnCancel 文本框&nbsp&nbsp 命名tbxMain代码--
  1. Option Explicit
  2. Private myExitState As Boolean
  3. Public Property Get ExitState() As Boolean
  4.     ''  Return the value hosted our private member variable.
  5.     ''  Since we have no corresponding Let Property statement
  6.     ''  it's ostensibly read-only.
  7.     ExitState = myExitState
  8. End Property
  9. Public Property Get UserText() As String
  10.     ''  Return the current value of the text in the tbxMain
  11.     ''  object. While the way VB[A] is structured it allows
  12.     ''  access to the object directly we should not go that
  13.     ''  route [IMO]. A future implementation may use a
  14.     ''  different object, or otherwise employ a different
  15.     ''  implementation. Such changes should not affect clients
  16.     ''  or consumers of the form. Also, this gives us the
  17.     ''  opportunity to perform other activities before we
  18.     ''  return the value, like qualifying, logging, whatever.
  19.     UserText = tbxMain.text
  20. End Property
  21. Public Property Let UserText(value As String)
  22.     ''  Allow the client set the value of the txbMain object,
  23.     ''  BUT NOT DIRECTLY. See balance of comments in the Get
  24.     ''  UserText Property.
  25.     tbxMain.text = value
  26. End Property
  27. Private Sub btnOk_Click()
  28.     ''  Set the state and then hide the form.
  29.     IndicateAccept
  30.     Me.Hide
  31. End Sub
  32. Private Sub btnCancel_Click()
  33.     ''  Set the state and then hide the form.
  34.    
  35.     IndicateCancel
  36.     Me.Hide
  37. End Sub
  38. Private Sub IndicateAccept()
  39.     ''  As there may be more than one way this is triggered
  40.     ''  let's have one procedure have responsibility for
  41.     ''  setting the state. While this seems overkill because
  42.     ''  we have but one little variable representing state,
  43.     ''  in a big application there could be many things that
  44.     ''  have to be done aside from merely setting said variable.
  45.     ''  This gives us one entry point, and thus, only one area
  46.     ''  to edit when things change, and more often than not
  47.     ''  they will.
  48.    
  49.     myExitState = True
  50. End Sub
  51. Private Sub IndicateCancel()
  52.    
  53.     ''  See comment in Sub IndicateAccept.
  54.     myExitState = False
  55. End Sub
  56. Private Sub UserForm_Activate()
  57.    
  58.     ''  Start with state indicating cancel.
  59.     IndicateCancel
  60. End Sub
  61. Private Sub UserForm_Initialize()
  62.     ''  Start with state indicating cancel.
  63.     IndicateCancel
  64. End Sub
  65. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  66.     ''  If the user closed the form via the control
  67.     ''  box instead of the [Ok] or [Cancel] buttons ...
  68.    
  69.     If CloseMode = VbQueryClose.vbFormControlMenu Then
  70.         IndicateCancel
  71.     End If
  72. End Sub
然后是模块代码,在名为mdlMain的模块中--
  1. Option Explicit
  2. Public Sub Main()
  3.    
  4.     Dim myForm As frmMain
  5.     Set myForm = New frmMain
  6.    
  7.     ''  Access and use the property(s) we exposed.
  8.     myForm.UserText = "Mark's great adventure."
  9.    
  10.     ''  Alrighty, let's show it.
  11.    
  12.     myForm.Show
  13.    
  14.     ''  Program execution will not end up here until the
  15.     ''  user closes the form, either by clicking the [Ok]
  16.     ''  or [Cancel] buttons or via the control box (the
  17.     ''  [x] in the top right corner).   
  18.    
  19.     If Not (myForm Is Nothing) Then
  20.    
  21.         ''  An error may be thrown if the user closes the
  22.         ''  form via the control box because it will have
  23.         ''  been unloaded but not yet nothing (let's trap
  24.         ''  that possibility).
  25.         
  26.         On Error GoTo ErrHandler
  27.    
  28.         If myForm.ExitState Then
  29.         
  30.             ''  access the UserText Property we exposed
  31.             
  32.             MsgBox _
  33.                 "User pressed [Ok]." & vbCrLf & vbCrLf & _
  34.                 "UserText = "
  35.                
  36.         Else
  37.         
  38.             MsgBox "User pressed [Cancel]."
  39.             
  40.         End If
  41.         
  42.         Unload myForm
  43.         
  44.         Set myForm = Nothing
  45.         
  46.         Exit Sub
  47.         
  48. ErrHandler:
  49.         If Err.Number = -2147418105 Then
  50.         
  51.             MsgBox _
  52.                 "The user closed the form via the " & _
  53.                 "form's control box."
  54.                
  55.         Else
  56.         
  57.             ''  Uhhh, what the h3ll? An error we didn't
  58.             ''  anticipate. Let's display the error
  59.             ''  description.
  60.             
  61.             MsgBox Err.Description
  62.             
  63.         End If
  64.         Err.Clear
  65.         
  66.         Resume OutOfHere
  67.         
  68.     End If
  69.    
  70. OutOfHere:
  71.    
  72.     Set myForm = Nothing
  73.         
  74. End Sub
看到问题,看到错误的建议等?让我/我们知道。谢谢
回复

使用道具 举报

194

主题

592

帖子

11

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1380
发表于 2006-10-17 19:39:04 | 显示全部楼层
一下子,议员提醒吉咪,他真的只是一个黑客……看起来像所有伟大的建议迈克尔!现在,如果我能学会将这些建议融入我写的东西中,那该多好啊……谢谢你发布代码,因为我不是'我不打算下载这个项目(我现在已经有足够的东西了……),但是哇!真让人大开眼界
Jeff_M回到了用hammer&编写代码的时代;凿子
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-10-17 20:24:58 | 显示全部楼层

It'没错,我是个黑客<不值得你的赞扬>——但老实说,我每天都在努力变得更好!如果您看到该代码或注释有任何错误,很有可能,请告诉我
谢谢杰夫
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-6 21:02 , Processed in 0.529888 second(s), 61 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表