Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Error! The variable is either undeclared o

Status
Not open for further replies.

towguy

Programmer
Jun 22, 2006
9
hi,
I am using VS2003 on WinXP.
I made a custom textbox control (Usercontrol) and pasted it on form. but when i reopen form in design mode after running or closing form that control disappears.and an error message is shown as

"The variable 'txtCurrentAddress' is either undeclared or was never assigned."


(txtCurrentAddress is control name)
but all designer generated (declaration and assigning) code is still there. and I didn't touch that code.

I tried same procedure on different forms but faced same error.
 
I made a custom textbox control

> If you have one textbox only, then you are doing it the wrong way. Just inherits from the base class and extent it.

public class myTextBox
inherits system.windows.forms.textbox

public sub new()

end sub

end class

> If you have more than one controls, then yes, user a usercontrol
 
Yes I have default Label, button and textbox controls on my user control.

 
TipGiver! what do you think this error is because of not inheriting from textbox control?
 
towguy - I'm having this exact problem. The app worked fine until I created an installer for it, now when I open it I get the undeclared or never assigned error for my custom control.

Did you ever get this solved?
 
It is probably not creating your control when you load it in the designer. The best practice on this stuff is to put the controls in a control library and reference that. That way, you can attach to it and step through.

Brian Begy
BugSentry - Automatic error reporting
 
Brian - if I understand you correctly, I believe that is what I'm doing. My control is created in a separate project, and compiled into a dll. There is a reference to that dll in the project that uses it, and I can still use the object browser there to see all of the member and properties of my control.

Since my problem happened after running the installer, my first assumption was that I had some kind of versioning problem, i.e. the designer thought the control's current version wasn't correct. Recompiling the control did not help.
 
Can you open the dll project VS and set a breakpoint? I just can't remember how I solved this problem. Maybe posting the code would help jog memories.


Brian Begy
BugSentry - Automatic error reporting
 
Yes, I can. But, in the main program in which the custom control is used, when VS starts up it generates this error:

The variable 'FileObject1' is either undeclared or was never assigned.

In this case, 'FileObject' is the name of my custom control. When I look at the form in the designer, all the controls are gone. When I look at the code, everything looks like it should, i.e. all the references to FileObject1 are just how I would expect. I can't run the program at this point, however, because the controls are missing (there's 18 of this control being used).

I was using VS w/o any problems before I ran the packager. The installation file installs a version of the program that works exactly as expected. It was when I went back to fix a minor bug that I saw the error upon opening the main project.

I imagine that I could simply re-instantiate the 18 controls at this point and it would work again. I would really like to understand the problem, though, in case it happens again.
 
Ha! This is bizarre. I can run the main program from VS, and it runs just fine. The controls all appear where they're supposed to, and they function just fine. It's just that they don't appear in the designer anymore. It also compiles just fine.

I'll keep working this, but it's not as big a problem as it was when I thought my app was no longer runnable. A reboot may even fix it, given the oddness of it all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top