473,545 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

One form accesses controls on a different form - good practice?

I'm learning dotNet, although I first learned programming back in the
days when structured programming was all the rage. In both my books and
courses, I've seen something like this:

Public Class FormA
Inherits System.Windows. Forms.Form

Private Sub Button_Click(By Val etc., etc.) Handles btnCalculate.Cl ick
FormB.Textbox.T ext = "some updated value"
End Sub

Is this good programming practice? Somehow, it just feels wrong to
access a form's controls FROM A DIFFERENT form.

Isn't this no different from A accessing B's local variables? I know
compilers will let you to do it, but I learned that was not good
programming practice because (among other things) a ripple effect could
introduce subtle and difficult bugs.

And if this IS good programming practice, what's the rationale behind
it? What changed over the past 15 years?

Nov 20 '05 #1
1 1766
Cor
Trebor,
I am from before the time of structured programming but a Dijkstra follower
(One of the first inventors of structured programming)

One of the main reasons for structured programming was to keep your program
readable.
(Small parts that could be handled. For that OO programming has no
difference in my opinion).
Public Class FormA
Inherits System.Windows. Forms.Form

Private Sub Button_Click(By Val etc., etc.) Handles btnCalculate.Cl ick
FormB.Textbox.T ext = "some updated value"
End Sub

We often say in this newsgroup that one of the advantage's of VB.net is,
that it has the possibility to do it in your own way.
But I don't think this is good practise I never saw it in that way been
described by someone.
(Sometimes people ask how to do it in this way, but they never get that
answer).

Some thoughts

Cor
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
7197
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
4
1384
by: darrel | last post by:
I have a contact form that a person submits to the server. In ASP, you'd make a page, post the form to another page, which would grab the values and do somethign with them. in ASP.NET, it appears that you grab the values directly from the form objects on the postback. Here's our problem:
2
1400
by: Sky Sigal | last post by:
Hello: I'm currently messing around, and need as much feedback/help as I can get, trying to find the most economical/graceful way to build usercontrols that rely on styling to look any good... It's the last part that has got me all frazzled (the 'rely on...to look good')... Let me explain -- and please bear with me as it's a bit longer...
17
8591
by: Barret Bonden | last post by:
As an old programmer just now looking at VB.net I have a question: How does one simply open one form from another ? I don't mean how does one create a new instance of that form , but rather how to refer to THAT form ? And having done this, how does one get data to and from that form ? I have read the MS tutorial on this but it is...
7
5222
by: Boni | last post by:
Dear all, if I do myform.close() is it disposed or not? is it correct do following? myForm.close() Info=SomeControlOntheForm.text This seems to work. But am not sure that it is waterproof. Thanks, Boni
17
3513
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is populated when a user scans a label. The other is ScanDate - a date/time field that should equal the date/time of the scan (e.g. 7/31/2006 5:00:00...
9
7028
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related to VB, plus the address bar would show something like this: www.somethinghere?id=3 and if you change number 3 from the address bar to (for example)...
5
10874
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I have a form that has a button. ( this form is a child form of a parent form ( main form ). Anway...in this child form I have a button, and if clicked...
8
1728
by: Justin Rich | last post by:
So another simple question from me :) as im working away ive made a button that does a series of wonderful things.. and as it goes along it suppose to update a label to let the user know what stage its at... but.. the rendering isnt done until after the code is completed... how do i tell it to render so that the label gets updated? Thanks...
0
7490
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7449
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7780
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5351
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.