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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Multiline TextBox Array to a Container 1

Status
Not open for further replies.

rjmccorkle

Programmer
Aug 26, 2000
55
US
At runtime I am trying to copy a frame with its arrayed controls to a new frame. I got it working, but if one of the TextBoxes has its Multiline property set to True, VB crashes when I unload the form. If I don't use the
SET txtBox.Container = fraP(1)
line (to place the newly LOADed control in the new Frame) or the Multiline is set to False, the form can unload. I found a reference to Microsoft Windowless Controls that allow changing the Multiline property at runtime and will try that tonight. Anybody know what the incompatability between SET CONTAINER and Multiline is or how to work around it?
Bob
 
An example of this, start a new project using a Standard form and place
a Frame called Frame1 on the form, with Index=0
a TextBox in Frame1 called Textbox1 with Index=0, Multiline=True
2 command buttons called Command1 and Command2
then use the following code (if Command1 is clicked, a second frame with a multiline textbox appears; when Command2 is clicked to exit, VB crashes; if Textbox1 Multiline=False or the SET Container line is not used, it does not crash when unloaded):

Private Sub Command1_Click()
Dim ctl, vCI, vC As Integer
vC = Frame1.Count
Load Frame1(vC)
Frame1(vC).Top = Frame1(vC - 1).Top + Frame1(vC - 1).Height + 100
Frame1(vC).Left = Frame1(0).Left
Frame1(vC).Caption = "Frame " & vC + 1

For Each ctl In Controls
If ctl.Container Is Frame1(0) Then
Set vCI = Me.Controls(ctl.Name)
Load vCI(vC)
' if this next line gets remarked out, it does not crash when unloaded
Set vCI(vC).Container = Frame1(vC)

vCI(vC).Left = ctl.Left
vCI(vC).Top = ctl.Top
vCI(vC).Visible = True
End If
Next ctl

Frame1(vC).Visible = True
Set ctl = Nothing
Set ctl2 = Nothing
Set vCI = Nothing
Set vCI2 = Nothing
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

PS.I installed the Windowless Controls, replaced the multiline Textboxes with multiline WLText; it doesn't crash when I exit now, it crashes when the Enter key is hit in one of the copied boxes and I try to process the Form_Keydown event with the forms Keypreview=True

 
Put code in the Command2_Click event handler to unload the textboxes. I did this and it no longer crashes on ending the app:

Code:
Private Sub Command2_Click()
    For c = 1 To Frame1.Count - 1
        For Each Control In Me.Controls
            If Control.Container Is Frame1(c) Then
                Unload Control
            End If
        Next
    Next c
    Unload Me
End Sub

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
what if you place that code in the Form_Unload event?


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Thanks, jebenson, that was way in the back of my mind as I spent hours figuring out exactly where the problem occurred. So, I tried UNLOADing the controls in the Form_Unload event and it works. Sort of. The form HAS to be unloaded or VB crashes. As long as I 1.Save before RUNning and 2.DON'T hit the End button in VB while developing the program it Seemingly does OK. I am still wondering what is going on. My understanding is that adding controls dynamically was a new feature in VB6 so I guess it may just be a bug. Now I don't know if I should put up with the nuisance of not being able to stop the program from within VB and the paranoia of not knowing what else might be messed up, or if I should just put 10 frames with their controls on the form and tell the users they are limited to 10, using the Visible property to keep the clutter down.
Does anybody have any search hints for Microsoft's site to find out if this is a known problem and if there is a patch? I am going to try over there now.
 
yup... vb6 is (for the most part) no longer supported...

They already have 2 versions of their new baby (vb.net) out, and a 3rd around the corner...
They, probably, don't care about the bugs anymore...
They are focused on selling the new product...

Have you noticed how it has even gotten harder to find references for vb6 on the web now days...

I had to start adding -vb.net -.net on almost all of my google searches just to get vb6 to show up on the first page ;-)


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top