tags:

views:

497

answers:

6

My project has maybe 130 controls (total of all labels, textboxes, etc.) in an SSTab (4 tabs). The project loads fine, it runs fine, I don't see a single error or warning at any point, but when I save the form with the SStab on it, the SStab data isn't saved (it is completely gone). Normally the relevant portion of the .frm file looks like this:

   Begin TabDlg.SSTab SSTab1 
     Height          =   8895
     [1550 more lines of code for all the controls]
     Width           =   540
   End
   Begin VB.Menu FileMenu

But lately it's getting cropped to:

   Begin TabDlg.SSTab SSTab1 
   Begin VB.Menu FileMenu

This is very frustrating! In my VB IDE, the frame, sstab, and all the controls are there, editable, running/compiling fine, no error messages at any point, but when you save the file, 1550 lines of precious sstab data just disappears - again, with no warning or error messages. So if you exit and restart the IDE, you get a form load error because 60% of the code is now missing. The log file points to the first error it finds (in this case a Begin TabDlg with no End) - there's no other info in it. (The log file was generated after the code was deleted and saved, so it makes sense that it wouldn't be helpful.)

When I first posted this question, I thought it had to do with the number of controls, because it appeared after I added a control, and in my first few tests, seemed to disappear when that control (or other controls) was deleted. Now I can't seem to get that form to save under any circumstances, even when I delete many controls (bringing the number of controls far below where it was when it was last stable).

I also tried deleting the SStab and moving all the controls to 4 different frames. I successfully did that in the IDE, but when I saved, a huge chunk of the data (starting with a slider control) was missing. So I have no fraking idea what is going on.

The problem is reproducible on two different PCs, so it doesn't appear to be a hardware/corrupt software VB install issue.

Has anyone else run into something like this?

+1  A: 

Not sure if this is the issue, but on a VB6 form, there is a limit to 255 (or is it 256) named controls. Perhaps you are running into that?

One way around that limitation is to use control arrays. For example, if you had 10 labels, instead of label1, label2, label3, etc, you could do label(0) through label(9), and use up only one named control.

The other thing worth mentioning about the SSTAB is the way it shows/hides controls. While it may appear that the controls are on separate tabs, what is really happening is that the controls are getting moved waaaayyyyy to the left (and consequently out of view). Perhaps with so many components, the SSTAB is choking on this in the IDE as it tries to render the controls in design view?

Again, not sure if this is the issue, but I know these two tidbits are relatively unknown.

OneNerd
Interesting...I didn't think I'd hit 255, and a lot of the controls are already arrays, so I don't think it's that. However I'm questioning some of my original assumptions about what triggers the code deletion. Need to do some more testing today and update my description. Thanks for the response!
Fred Hamilton
+1  A: 

Sounds horrible, never heard of anything like that.

Presumably you aren't getting an error log file from VB6 when you load the form into the IDE before it gets corrupted? The log file has the same filename as the form file but with a .log filename extension. For example, if errors occurred when loading Myform.frm, Visual Basic would create a log file named Myform.log. The error messages you might see there are documented in the manual.

Have a look in the Windows Event Log, see whether it records any interesting problems against the VB6 IDE?

Are you using any weird controls? Maybe one of them is somehow corrupting the FRM or FRX. FRM files are just text as you obviously know & the format is documented in the VB6 manual. Can you see any corruption in the FRM in a text editor? If you remove any properties defined in the FRX, does it still fail.

I think I would try creating a new project and a new form, and then use the IDE to copy and paste all the control definitions into it - no code. Play with the new form, see whether it has the same problem. Maybe you can recreate the form this way without the problem. If the new form does have the problem, do the same thing but only take half the controls. Maybe you can find a problem control by "binary search".

MarkJ
I took your advice and created an entirely new project, pasting all the controls into it - it's working so far.Nothing useful in the error log for the file (except for pointing out the line number where the discontinuity first appears). Where is the "event log" file?
Fred Hamilton
It's the Windows event log, you use the Event Viewer from the control panel. http://support.microsoft.com/kb/308427
MarkJ
Well the solution turned out to be the above-mentioned copying all the controls and code to a new project. It didn't take too long to get it working and the form's been working fine after days of heavy use and additions. If I ever figure out root cause I'll update this question.
Fred Hamilton
Glad its working! You could use a file differencer to look for differences between your new working form and the old corrupt one.
MarkJ
A: 

So the SAVE function is not working.

I suspect one of the components you are placing on the tab strip is the culprit.

So ..

1) Take an inventory of each and every kind of component you are placing on the form

2) eliminate one (kind), SAVE

3) Did it SAVE?

-> Yes = that was the problematic control

-> No = return to step 2, but pick another kind

Of course, its important to remove all controls of a certain kind in step #2 (for example, ALL labels, or ALL textboxes, etc).

I have never heard of this happening however.

OneNerd
+3  A: 

Create a UserControl for each tab. That makes editing MUCH easier. It also allows you to nicely modularize the code, so each tab lives in its own file, and it'll allow you to reuse tabs elsewhere if you want.

Joel Spolsky
Wow, I never knew about UserControls until this. I put each tab in a user control, then couldn't figure out how to address the controls in the user control from my main module. Then right around then the save corruption happened. I will look into this again when I have time - it seems quite cool.
Fred Hamilton
I have to agree with Joel here. This is the way to "fill in" tabbed controls. You don't put the tab in a usercontrol, you put a usercontrol into each tab.You don't address the controls from the form, you move their logic into the usercontrol. Think of them as classes - just a special kind.
Bob
+1  A: 

You are not alone! I've seen this problem. . .in fact I'm dealing it right now, which is what brought me to this site.

I've been working with VB since '94 (VB3) and I first saw this problem about 5 or 6 years ago, while using VB6. My solution then, was not unlike some of the suggestions that you have recieved from the good folks who've responded above: throw out the existing file and rebuild the form in a new file. I did that back and the affected form has worked ever since.

My current problem is appearing in another, much newer form, and the replace/rebuild option (performed about a month ago) only worked for about three weeks. Now the problem is back and each new iteration of the file gets corrupted very quickly. Following the reply above regarding the total number of allowable controls, I'm looking into just how many controls I have. . .and, as it happens, I was in the process of consolidating the primary the buttons and menus into control arrays, simply because it was going to streamline their management.

I can also confirm your observations about moving the project to a second PC. . . I've done that too, and problem persists. Moreover, I can add that I have moved the project from one shared storage system to another to no avail. (The original storage location was on a drive mounted to a Win-tel system and the new location is on a UNIX-based NAS!)

Just rebuilt the file again and checked: Controls.Count = 62, so I am no where near the 255 control limit mentioned previously. This is indeed strange! (Not to mention furstrating!)

scotty-
I feel your pain! I'm still just dealing with it. After a certain amount of editing, it happens again and I have to paste everything into a new project, and it works again for a while.Are you using the sstab control? I'm wondering if that has anything to do with it.
Fred Hamilton
Does anything show when you use a file differencer to compare the working files with the corrupted files? Seems like the first thing to check.
MarkJ
I don't have a copy of a corrupt file anymore (next time I'll save a copy), but I did look at it when it first started failing and what seemed to be happening was that a huge chunk of data was just ripped out of the form (not the code) section of the .frm file. I believe the deletion started/ended on line boundaries (not in the middle of a line), but it definitely had no respect for nested structure:A B C D /D /C /B/Abecame something like:A B/AIt'd be interesting to measure the size (number of lines and bytes) that went missing...I'll do that next time.
Fred Hamilton
A: 

I get the same problem when attempting to save a form when the .FRM is writable but the .FRX is read-only

Kevin
Interesting, but I get all sorts of error messages when I try to save with a read-only FRX. Are you able to save without those error messages?
Fred Hamilton