• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

An OO way to pass Visual Basic variable values to a form

发布: 2007-6-21 21:57 | 作者:   | 来源:   | 查看: 18次 | 进入软件测试论坛讨论

领测软件测试网

   


  Object oriented programming guidelines stipulate that objects--including forms--should maintain their own internal values. With this in mind, you注释:ll need a way to pass values to loaded forms without using universally global variables. Fortunately, Visual Basic provides just such a way with its property Let() and Get() procedures.

For example, suppose you have a button Click() event on Form1 that loads Form2. Form2 displays a value collected in Form1. In the past, you may have created a public variable with an application scope, and then read this variable in Form2 to obtain the proper value. Using this technique, however, soon results in hard-to-manage, spaghetti code.

As a more elegant alternative, you can add a property to Form2 that Form1 can then set.

For instance, in Form2 you would add the following property procedures along with the variable declaration:

Private myVar as Variant

Public Property Get PassVar() As Variant
PassVar = myVar
End Property

Public Property Let PassVar(ByVal vNewValue As Variant)
If IsNumeric(vNewValue) Then myVar = vNewValue
End Property

For these procedures, you can change the property type, but it must match in both the Get and Let procedures. Also notice that we included some validation code to ensure that the passed value is a number.

Now, to read or assign a value to this property, use the following code on Form1

Private Sub Command1_Click()
With Form2
    .PassVar = 25
    .Show
    Debug.Print .PassVar
End With
End Sub
(完)标题的中文意思:在VB中获得form的变量值的方法(不确切,还是你自己来看吧。^o^)

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网