PDA

View Full Version : Out of Memory error in Outlook 2007 form



caveatrob
07-28-2008, 10:28 AM
I have a form with a listbox, a textbox, and a button. I paste a multi-line chunk of text into the textbox and push the button to parse the text into a listbox.

I us the following code:
Private Sub cmdQuickAdd_Click()

Dim sTmp As String, iPos1 As Integer, iPos2 As Integer

sTmp = txtQuickAdd.Text

iPos1 = 1
iPos2 = InStr(sTmp, vbCrLf)
Do While iPos2
lstTasks.AddItem Mid$(sTmp, iPos1, iPos2 - iPos1)
iPos1 = iPos2 + 2
iPos2 = InStr(iPos1, sTmp, vbCrLf)

Loop

End Sub

The first time the form runs, it seems to work fine. Subsequent loadings of the form result in Out of Memory errors that persist until I quit an restart Outlook 2007.

Any ideas? Can the textbox hold all the clipboard characters?

Mavyak
07-28-2008, 10:59 AM
Simplify!!

Private Sub cmdParse_Click()
lstTasks.List() = Split(txtQuickAdd.Text, vbCrLf)
End Sub
Enjoy!

Edit: As for the out of memory, I believe listboxes and comboboxes are limited to 1000 values (0-999). The following code will stop you from adding more than a 1000 values to your listbox:

Private Sub cmdParse_Click()
Dim vals
vals = Split(txtQuickAdd.Text, vbCrLf)
If UBound(vals) > 999 Then
MsgBox "Too many line items!", vbCritical, "D'oh!"
Else
lstTasks.List() = vals
End If
End Sub