473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Application.Run(form1)


Using VB2005 Beta 2

If I use Application.Run(New Form1) in the below code.
Then code like TAM.Form1.rtbAllAcq.Text = aryStatistics(0) that
is used to update a richtextbox on Form1 does not work. There
is now error but the contents never change. If I use Application.Run(Form1)
then all works fine. I assume that this is because New creates a new form
that TAM.Form1 does
not reference. Is this correct? Will the following code cause me problems
later because I do not use
New?

Thanks,

Thomas

Public Class clsMain
Public Shared Sub Main()

Try
Application.Run(Form1)
Catch ex As Exception
Response = MessageBox.Show("Error.")
End Try

End Sub
End Class

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
4 4208

Form1 (presumably) is a class name (a type) and thus will not work with
Application.Run(). As noted you need to use Application.Run(new Form1).

Not too sure what TAM is - namespace? project name?

I cannot get something of the form

<Type>.<ControlName>.<Property>

to even compile unless I go in and manually change the generated code
to make it Shared.

This is bad/wrong is so many ways.
What are you trying to do with

TAM.Form1.rtbAllAcq.Text = aryStatistics(0)

what you need to address it this way?
Also, I would recommend turning on both Option Explicit and Option
Strict ON.

{For
Response = MessageBox.Show("Error.")
to compile, Option Explicit must be off which means Option Strict is
probably off too)
Yes, they will make you life harder up front but they are good
defensive programming and will help you long term.

Alan.

Nov 21 '05 #2
Alan,

Application.Run(Form1).
This works perfect, but I don't know that it is correct.

Not too sure what TAM is - namespace? project name?
TAM is the project name

What are you trying to do with

TAM.Form1.rtbAllAcq.Text = aryStatistics(0)


This updates the richtextbox rtbAllAcq with the text in the string variable
aryStatistics(0), if this is not correct how do I assign a value to a
control in one form when the code is located in another form or a module?
Thanks,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #3

Something strange here.

I have a form class

Public Class frmBitwise

I have a code snippet

...
dim mainForm as new frmBitwise
Application.Run(mainForm)
...

This works fine and I would expect it too - Application.Run() takes a
form as a parameter

If I change it to

Application.Run(frmBitwise)

then it does not compile, I get a

' frmBitwise is a type and cannot be used as an expression'

error.

- If Form1 is a type then I don't see how you are not getting this
error.
- if Form1 is a variable, then where is it declared/initialized?

As for communicating between forms there are LOTS of threads in the NG
about this.

There are a few general solutions but which one to use depends upon the
particular situation
Is it a sub-form/pop-up trying to interact with it's parent?
Does one have multiple siblings that need to update or reflect
changes in each other?
Does one have multiple children to be updated by the parent? Or the
parent updated by the children?
Personal opinion, I would avoid using global variables (say, stored in
a module ) to store the references to each form. As a solution, it
works within a certain size/complexity range but eventually (if one
keeps adding functionality) it fails. Too many pieces know about and
can interact with each other, and do.
Structure the system so that sub-systems only know about and can
interact with those pieces with which they need to.
For simple child/parent situations one can use the owner property

Parent
dim child as new ChildForm
child.owner = me
child.show()
Child
DirectCast(me.owner,Parent).DoSomething()

Have a look through the NG for other threads on this topic

hth

Alan.

Nov 21 '05 #4
<th*****@msala.net> wrote in message
news:43**********************@news.newsdemon.com.. .
If I use Application.Run(New Form1) in the below code.
New Form1 creates a new *object* of /Type/ Form1.
This object is passed to the Application.Run method.
Then code like TAM.Form1.rtbAllAcq.Text = aryStatistics(0)


There is no "Global" reference to Form1 any more (that ended with
VB6). You must use a variable to hold a reference to the Form1
*object*, so you can use it elsewhere in the project or, better
still, pass the Form object (or Control) between methods.

' Reinventing Global Form1 - inadvisable, but will work.
Global frmOne as Form1

Sub Main()
frmOne = New Form1
Application.Run( frmOne )
End Sub

' Passing things around ...

Public Class Form1
. . .
Public Property AllAcqText() as String
Get
Return rtbAllAcq.Text
End Get
Set( Value as String )
rtbAllAcq.Text = Value
End Set
End Property
. . .
End Class

[Module1.vb]
Module OtherCode

Public Sub LoadFromArray( _
ByVal oaForm as Form1 _
, ByVal oaData as SomeSortOfArray _
)
oaForm.AllAcqText = oaData( 0 )
End Sub

End Module

Then

LoadFromArray( frmOne, aryStatistics )

HTH,
Phill W.
Nov 21 '05 #5

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

Similar topics

8
by: Andrew Warren | last post by:
I'm trying to exit a Windows Forms application while in the form's constructor (after InitializeComponent() has been called) and am finding that calling Application.Exit () still leaves the form...
20
by: Michael A. Covington | last post by:
See: http://www.ai.uga.edu/mc/SingleInstance.html While attempting to use a mutex to allow only one instance of my app to run at a time (Recipe 4.12 in C# Programmer's Cookbook), I found that if...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
4
by: Skysurfer | last post by:
Hi. I made a simple VB.Net 2003 application in which i have one Module with the Sub Main and two forms with un button in each one. I run the application on Windows XP Professional. This is...
1
by: Richard | last post by:
Hello there, I have a form that is called from a Sub Main procedure using application.run(Form1). On my main form there is a button to open an instance of Form2 and then at the same time hide...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
3
by: Karan | last post by:
I am calling finalize when form2 loads and deactivates form1 which closes form1. However, same thing is not happening in form2 because finalize is already called. Does anybody has solution to it....
6
by: rrowe | last post by:
Admittedly, I am new to VB.NET I have some real simple code that I am trying to run in VB.NET Friend Module xxx Friend F1 As Form1 ----------------- Public Sub Main()
7
by: Lee Crabtree | last post by:
I remember when I was first getting into .NET Forms programming that there was a rather emphatic rule about not constructing a form before calling Application.Run with it. So this: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.