|
i have a very basic problem and i dont know the reason for that..
suppose you have 3 forms
if in form2 u code :
form1.textbox1.text=textbox1.text
it works as at runtime value of textbox of form2 transfers into textbox of form1..
even in form 3 u code
form1.textbox1.text=textbox1.text
it works..
but if in form3 u code
form2.textbox1.text=textbox1.text
it doesnt works..
can anybody tell the reason..
and alternate method of doing the same..
thanks ...
|
|
|
|
|
You're breaking OOP encapsulation. The code on a form should be concerned with ONLY those controls on THAT form. It should not care about the controls of another form at all.
If a TextBox on a form needs to be modified, it can either subscribe to an event supplied by the object that might need to make changes, or it can pass a delegate to that object that the object can use to call a method on your form.
Having a form pass a reference of itself to another object so that object can modify the form's contents breaks encapsultation and permanently ties the object to that form. So much for reusability.
For instance, if I have a class that does some work and needs to report status information, it can expose an event that does this:
Public Class WorkerClass
Public Event ProgressReport(ByVal SomeValue As Integer, ByVal SomeMessage As String)
Public Sub DoSomeWork(blah, blah)
...
RaiseEvent ProcessReport(somenumber, "Some message...")
...
End Sub
End Class
In your Form1 code, you can create an instance of the class and wire up the events like this:
Dim myWorker As New WorkerClass
AddHandler myWorker.ProgressReport, AddressOf MyProgressHandler
.
.
.
Private Sub MyProgressHandler(ByVal SomeValue As Integer, ByVal SomeMessage As String)
' This is where you update your forms controls
End Sub
|
|
|
|
|
thanks dave,
now it makes sense to me.
as forms are classes so encapsulation concept will be voilated...
i'll try this way and come back to you..
thanks..
|
|
|
|
|
How do I make sure the user does not start more than on instance of my program? Can I do a test on the Load to see if an instance is already running? What would I test for?
|
|
|
|
|
one way to do this is on the load of you'r program check the running process
if you'r programme is already running there will be a processname very simular to you programme name
another way is to have a integer setting that gets incremented on the startup of you'r programme and decremented at the close of you're programme. then in the load you just check if that setting is 1 then go on else shutdown (you will need to increment the setting before you do this check and don't decrement it here otherwise you'll run in trouble)
another is to have a registry entry and check that (and clean it up when the programme closes)
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
Yeah, that's not a good idea since a crashed application can invalidate the count.
|
|
|
|
|
heum true
didn't think that far ahead
been a very long day but hey only half an hour to go ;P
PS: the first option would work even with crashed application (but might be a bit of a work around)
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
How would that code look like?
|
|
|
|
|
TDDragon wrote: PS: the first option would work even with crashed application (but might be a bit of a work around)
It is. Most people who use this technique will hard code the name of the .EXE in their code. What if the .EXE get's renamed by either the end-user or the guy writing the code??
|
|
|
|
|
Normal practice is to use a Mutex. Search the articles for "single instance[^]" for examples.
You application starts by checking for the existance of a known Mutex. If it doesn't exist, your code then creates the Mutex. At the termination of your app, you have to destroy the Mutex.
Now, when your second instance starts, the very same code checks for the existance of the Mutex. If it's there, your code could quit, or do whatever else you want.
|
|
|
|
|
If you are using VS2005, right click the project and click properties. On the application tab there is a checkbox that says 'Make single instance application'. If you check that then compile, it should solve your problems. If you are using VS2003 you will need to do what Dave said.
Mike Lasseter
|
|
|
|
|
Dear All,
When i executing my VB.NET project, an error message displays time to time as follows,
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an object.
Always this is displaying at Public Class Form1
anybody can help me
Dimuthu
|
|
|
|
|
this means that you are using a variable before it has been initialized
for example
private sub blabla()
dim l as list(of string)
l.add("this is going to give a object referance not set to an instance of an object error")
end sub
solution:
private sub blabla()
dim l as NEW list(of string)
l.add("this is going to give a object referance not set to an instance of an object error")
end sub
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
Dear TDDragon,
Thanks, I checked all the variables, but they have all initialyzed. Stll the problem remaining.
Dimuthu
|
|
|
|
|
declare the form as NEW instance of the form class
then show it
as:
dim f as new (Form class)
f.Show
Try
Dim SH*T as Mylife
Catch ex As Exception
msgbox("Im Happey Today")
End Try
|
|
|
|
|
Dear all,
I know that this is not a new query. On the other hand I didn't manage to find a satisfactory answer.
So here I am.
I have a VB .NET application, which employs various CPU consuming algorithms.
I want to measure the execution time of a code snippet. Not the real time, but
the actual time that my code uses the CPU. Do be more accurate, I want to
have a CPU independent unit for comparison.
Apart the above question, is there any general platform independent method or unit to
characterize the execution speed of an application.
Than you all.
Konstantinos
|
|
|
|
|
Usually, CPU intensive tasks use almost 100% of the CPU time, so the common way of measuring execution time is to make sure that the computer isn't doing anything else that is CPU intensive, and just measure the time spent.
The System.Diagnostics.StopWatch class is suitable for this.
There is no CPU independent or platform independent way to characterise execution speed. The speed is very much dependent on the CPU architecture, like cache sizes, memory speed, pipeline stall penalties, branch prediction, et.c. The efficiency of a specific combination of instructions can vary considerably from one computer to another.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thank you Guffa.
I already use stopwatch, but do you know if it counts the Real time passed or the allocated CPU time to the process, like the clock() function from C++?
If stopwatch measures real time, do you believe that it would be possible to be corrected in
some way by the allocated "% user time" (performance counter) of the process. As an example
lets say that a process runs from 2500 ms and the average process [% user time] is 80%. Is
it applicable to say [virtual time]=2500 ms x 80%= 2000 ms....
Konstantinos
|
|
|
|
|
hi,
i have a question: What event is used to resize the column of a datagridview?
thanks.
|
|
|
|
|
None. Events don't cause the resize to happen.
|
|
|
|
|
Hi,
I have an array of couple of millions of fields as byte.
The problem is In my function i need to resize the array everytime I pass through the function.
Using redim preserve array(i + someBigNumber)
And it is to slow... But speed in my app is a crucial argument.
Is there any faster way to resize the array and keep it's contents?
|
|
|
|
|
USe a list instead, it's a dynamic array. Which means the name 'list' sucks, but that's .NET for you.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
no...
but try to make a copy of this array by array. lib functions
Try
Dim SH*T as Mylife
Catch ex As Exception
msgbox("Im Happey Today")
End Try
|
|
|
|
|
|
1. Post a question normally, give a title and ask a question don't ask your question in your title and just say pls help.
2. You want findstring and you want to on textbox text changed, call this with the listbox and use the text as the string to check against. Check this out
|
|
|
|