Question

Text Box update problem ... Strange

Asked by: phalanx777

I have a form with a text box (Text1) ... next to the text
box is a "Calculate" button which allows the user to pop up a second form, enter some data, and calculate the value
to be inserted into Text1.Text.
 
Problem is this ... after all the data is entered in Form2,
the next step is to click an "Update" button which attempts to update the Text1.Text value using in part the callback
procedure:
...
Form1.Text1.Text = Value
 
However, when you do this, the value of Text1.Text on
the screen does not change unless you close Form1 and
reopen it. When reopened, the value of Text1.Text is
changed to the correct value indicating that the original
callback on Form2 did trigger the value-changed callback
tied to Text1 ...
 
So why doesn't the value of Text1.Text change when I
hit the button of Form2?
 
Thanks for assistance.
--
Fred Phelan
frederick.phelan@nist.gov

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2000-03-06 at 10:29:42ID10306191
Tags

callback

,

text

,

trigger

,

update

Topic

Visual Basic Programming

Participating Experts
5
Points
50
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Passing values from form1 to form2
    This question is related to my previous one. On Form1 I have a combobox from table1. On Form2 I have a text field linked to table2 as the Data Source. Both table1 and table2 are identical. My question is How can I pass the value selected from the combobox (from table1) to ...
  2. Return default value of a UserControl for ex. Text1.Text …
    Hello, How to return the default value of a UserControl for example like in TextBox Text1 value is equal to Text1.Text I have my own TextBox UserControl and wanted it to get me its Text value whenever I Call it without .Text Regards, Hesham
  3. simple question: form2 data to form1
    I've made a little program that has 2 forms. The program starts with form2 that has 2 textboxes named box1 and box2 and a submit button. The code I'm using is: Private Sub Command1_Click() Unload Form2 Load Form1 Form1.Show End Sub How do I transfer the data entered in both...
  4. best way to make text2.text = text1.text as text1. lo…
    what would be the best way to make text2.text = text1.text as text1. looses focus thanks
  5. Passing value from Form2 to Form1
    I have a form, Form1, that contains a label, Label1. When I click a button I have Form2 show. I scan a barcode which passes a string to a label, Label2, on Form2. How can I now pass this value to Label1 on Form1?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mcriderPosted on 2000-03-06 at 11:06:44ID: 2588707

Is the value you are trying to set to text1.text numeric??? If so, you need to do this:

   Form1.Text1.Text = Cstr(Value)


Cheers!®©
 


 

by: mcriderPosted on 2000-03-06 at 11:08:04ID: 2588711

You may also want to do:

   Form1.Text1.Refresh


Cheers!®©

 

by: groonePosted on 2000-03-06 at 11:49:02ID: 2588838

with MCRiders comments -  if you are calling Text1 from another form and giving it a value dont follow it with the "Text" simply do as follows

Form1.Text1 = CStr(Value)

 

by: phalanx777Posted on 2000-03-06 at 12:43:43ID: 2589015

I have tried all these things including:

Form1.Text1.Text = Cstr(Value)
Form1.Text1 = Cstr(Value)
Form1.Text1.Refresh
Form1.Refresh

I am wondering if VB does it on purpose because Text1 has a value changed callback, or if it is a bug.

Fred

 

by: phalanx777Posted on 2000-03-06 at 13:14:16ID: 2589113

Adjusted points to 50

 

by: phalanx777Posted on 2000-03-06 at 13:14:16ID: 2589114

I created a separate project consisting of

frmMain.Text1
frmMain.Text2
frmMain.Command1
Form2.Text3
Form2.Command2

The callback for frmMain.Command1 is:

Text1.Text = Text2.Text

The callback for Form2.Command2 is:

frmMain.Text1.Text = Text3.Text

It all works from frmMain, but not Form2.

This isolates the problem a bit ...
it tells us that if you do the text
change form another form, it will not
work, but it does work if you do it
from the same form.

Some event must not being sent. If I put
a

MsgBox "test"

command in the Text1_Changed callback
the message box comes up in both cases,
but the text only changes in the first case.

Fred

 

by: motilePosted on 2000-03-06 at 13:57:51ID: 2589231

Hi,

I tried your exmaples and it all worked well for me, even from a second form.
Maybe your VB is not installed properly and this is the cause for this bug.

In the meantime, to go around this problem, try to use a global variable.

Let's take your test project for example:

Add a module to the project, in which you declare a global variable (an integer for example):

Global G_Value as Integer

In the Click event of Form2.Command2 write this:

G_Value = Text3.Text
frmMain.Text1.Text = G_Value


Good luck.

 

by: phalanx777Posted on 2000-03-06 at 13:58:20ID: 2589233

I created a separate project consisting of

frmMain.Text1
frmMain.Text2
frmMain.Command1
Form2.Text3
Form2.Command2

The callback for frmMain.Command1 is:

Text1.Text = Text2.Text

The callback for Form2.Command2 is:

frmMain.Text1.Text = Text3.Text

It all works from frmMain, but not Form2.

This isolates the problem a bit ...
it tells us that if you do the text
change form another form, it will not
work, but it does work if you do it
from the same form.

Some event must not being sent. If I put
a

MsgBox "test"

command in the Text1_Changed callback
the message box comes up in both cases,
but the text only changes in the first case.

Fred

 

by: eabPosted on 2000-03-06 at 15:46:39ID: 2589558

in your code do perform the update, stick a "DoEvents" as the last entry in the procedure.


Ed.

 

by: wsh2Posted on 2000-03-06 at 22:20:34ID: 2590399

EAB.. how can you proffer that as an answer?.. <sheesh>. Its obvious that phalanx777 has NOT provided the right  information about his problem.

The updating of a Form1.Textbox from Form2 is simplicity itself.. and to have it display immediately.. is done automatically by VB if both forms are visible. No.. there is more to this story.

I suppose the most telling symptom here is when phalanx777 writes that..

"However, when you do this, the value of Text1.Text on
the screen does not change unless you close Form1 and
reopen it. When reopened, the value of Text1.Text is
changed to the correct value indicating that the original
callback on Form2 did trigger the value-changed callback
tied to Text1 ..."

Now.. how did that happen? When you close and reopen a form.. Textbox.Text1 is reinitialized back to its DEFAULT setting, But in his case, the changed value appears.  How did the Form_Load procedure know the correct value? There is more to this story that we don't know.. <sigh>.

Is the Form1.Textbox bound to a data control? What is "Value"? A global variable?.. a class property? And how is the new "Value" being derived? (Quite candidly, I think this is where the problem rests.. phalanx777 put a debug breakpoint in and check that Value is correct before it is passed to Form1.Text.. k?)

All in all.. changing Form1.Text1.Text and having it display.. IS THAT SIMPLE. The cstr(value) comments made here, while nice, are truly marginal in what they do, because if not specified, VB does the conversion automatically. Do Events? EAB, exactly which Event Procedure does the statement Form1.Text1.Text = Value trigger that is going unprocessed? Nevertheless EAB, I love ya just the same.. and I hope you take my comments in good humor.. <smile>.

Phalanx777.. use a debug breakpoint, k? I think you will find that you are putting the original value back into the Textbox.. thus causing it to appear unchanged.. <wink>.

 

by: phalanx777Posted on 2000-03-07 at 07:31:36ID: 2591895

Cannot accept this as the answer ... sorry. I have put DoEvents all over the place and it does not help in the slightest.

To wsh2: The entire mystery is that the value-changed callbox tied to Text1 is called  from Form2... this is proven because in this routine a global variable is set equal to the value of Text1.Text. When the form is unloaded and loaded, the value is correct, even though a change on the screen does not appear. This means that the value changed callback was called, because when the form reloads, the display value of Text1.Text is set to the global variable.

I am using VB5 ... could it be a bug in VB5 corrected in VB6?

Fred

 

by: wsh2Posted on 2000-03-07 at 08:20:26ID: 2592133

I doubt VERY VERY VERY much this is a VB compiler bug.. but rather a logic one.

Ok.. by virtue of the Form1.Form_Load event (when we open and close), we know that the Global value is getting updated. However, by all evidence given, this update is happening AFTER the Form1.Text1.Text write.

The easiest / best way to test this is to use VB Debug commands, set a breakpoint, and then Step through your code.. placing your cursor on each variable when you want to examine its value. Short of doing that, the second approach would be to strategically place Msgbox statements thoughout your program.. displaying the values you want to see.

In this case.. try this.. place the following statement in the Form2.Update_Click procedure right BEFORE the Form1.Text1.Text = Value statement..

MsgBox (Value)

and then run your program. I think you will find that Value will read what Text1 does.. <smile>. For the program to work.. you have to make sure that Value IS updated BEFORE you display it.. As such, what logic / procedures / events do you use to update Value?

 

by: phalanx777Posted on 2000-03-07 at 09:14:53ID: 2592381

A few things:

1) I put MsgBox(Form1.Text1.Text) calls in the Update_Click procedure both before and after the Form1.Text1.Text = Value statement ... it shows that the value of Form1.Text1.Text changes internally when it is called, but it does not change on the screen.

2) re your comment: "make sure that Value IS updated BEFORE you display it.. "  

This is not feasible ... in the context of the application we are talking about, Form1 is elaborate in which users enter a great number of values. The Form2 is a simple pop-up called from Form1 in which users enter about 3 values for a formula which allows them to calculate an exact value for a certain variable on Form1. I don't want to have to Unload Form1 and reload it every time I pop-up Form2 to calculate the variable ... I want Form1 to update automatically when I click "Update".

Did you see my test above? ... for some reason this only seems to work of the Update_Click procedure is in the same Form as Text1.

Strange.

Fred

 

by: wsh2Posted on 2000-03-07 at 09:41:59ID: 2592482

Fred.. rather than debug online as we are.. can you zip up the source code and send it to me? I think it will save our keyboards.. LOTZA punches.. <lol>.

Wsh2@aol.com

 

by: mcriderPosted on 2000-03-07 at 10:25:39ID: 2592643

phalanx777,

I know you said that you have VB5.  Do you have Service Pack 3 installed??? If not, you should... There are a boatload of fixes in it. Check out the following microsoft KB article:

INFO: Visual Studio 97 Service Packs - What, Where, and Why
http://support.microsoft.com/support/kb/articles/Q170/3/65.ASP
 

Cheers!®©

 

by: phalanx777Posted on 2000-03-07 at 10:38:06ID: 2592700

Guys, Just tested on VB6. Reproduces there. Ughh.

Fred

 

by: phalanx777Posted on 2000-03-07 at 10:53:53ID: 2592753

Ok, next test was this ... created sample project

frmMain, frmMain.Text1, frmMain.Text2, frmMain.Command1

Form1, Form1.Text3, Form1.Command2

Form2, Form2.Text4

The callback for frmMain.Command1 is:

Text1.Text=Text2.Text

This works ok ...

The callback for Form1.Command2 is:

frmMain.Text1.Text=Form1.Text3.Text
Form2.Text4.Text=Form1.Text3.Text

In this case, the value of Form2.Text4 updates but the value of frmMain.Text1 does not update. Maybe the problem only exists when the text box is drawn on the main form. What could be the problem with that?

I wonder if there is a work around.

Fred

 

by: wsh2Posted on 2000-03-07 at 11:27:26ID: 2592873

Having read your source.. you have a BAS module sub main procedure from which you start the program. In the module, you are creating a new Form1 called fMainForm.. and then displaying fMainForm rather than displaying the frmMain that we all have been so valiantly trying to update.. <smile>.

To be honest, the fMainForm is NOT necessary.. just use frmMain as it will readily suffice. As such, change your BAS sub main Module1 to read..

Sub Main()
    frmMain.Show
End Sub

----------------------------------------Change frmMain's Command1_Click () to read..

Private Sub Command1_Click()
    Text1.Text = Text2.Text ' I suspect this is only there for testing
    Form2.Show
End Sub

----------------------------------------Change Form2's Command2_Click () to read..

Private Sub Command2_Click()
  frmMain.Text1.Text = Form2.Text3.Text
  Form2.Hide
End Sub

----------------------------------------and that will give you what you want.. <smile>

 

by: phalanx777Posted on 2000-03-07 at 11:36:35ID: 2592918

My mea culpa for sure ... for some reason the code wizard starts main as fMainForm rather than frmMain. I guess to be Hungarian about everything. Thanks wsh2 ... Fred

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...