List box Myarray to long

S

SN

Good Day,
I currently have a list box running from the following code Everyting is
working perfectly fine it is just that in myarray where i list my Listbox
items I have a total of 96 to select from.
If i get threw a third of my wording I have to start a new row via using the
, underscore, (these are however words not numbers )
example myArray = Array("1 ", "2", "3", _
, "4", "to 96")
Via doing this everthing appears in my listbox but a blank space between the
last listed item and the new listed ie 3 and 4.

I am not to familuar with VBA so might be an extremely stupid question, but
is there a way that i can allow more that allowed on line of code in my
listbox without having a space between the two.

Thank you very much
SN

Code



Private Sub cmdCancel_Click()
Unload Me
End Sub


Private Sub cmdOK_Click()
Dim StrSkillList As String
Dim j As Long, k As Long
Dim var, var2, var3
Dim SkillsArray()
k = 1
For var = 1 To lstSkills.ListCount
If lstSkills.Selected(var - 1) = True Then
ReDim Preserve SkillsArray(j)
SkillsArray(j) = lstSkills.List(var - 1)
j = j + 1
End If
Next
For var2 = 0 To UBound(SkillsArray)
ActiveDocument.FormFields("Skill" & k).Result = _
SkillsArray(var2)
k = k + 1
Next
Unload Me
End Sub

Private Sub lstSkills_Click()

End Sub

Private Sub UserForm_Initialize()
Dim var
Dim myArray()
myArray = Array("1 ", "2", "3","4 ", "5", "6", "to 96")



For var = 0 To UBound(myArray)
lstSkills.AddItem myArray(var)
Next
lstSkills.ListIndex = 0

End Sub
 
J

Jonathan West

SN said:
Good Day,
I currently have a list box running from the following code Everyting is
working perfectly fine it is just that in myarray where i list my Listbox
items I have a total of 96 to select from.
If i get threw a third of my wording I have to start a new row via using
the
, underscore, (these are however words not numbers )
example myArray = Array("1 ", "2", "3", _
, "4", "to 96")
Via doing this everthing appears in my listbox but a blank space between
the
last listed item and the new listed ie 3 and 4.

I am not to familuar with VBA so might be an extremely stupid question,
but
is there a way that i can allow more that allowed on line of code in my
listbox without having a space between the two.

Thank you very much

there is a limit to the number of line-continuation characters you can put
in to a single VBA statement. I forget offhand what the limit is. So you
need longer lines for your myArray statement.

Alternatively, you can do this

myArray = Split("1|2|3|4|5", "|")

which achieves much the same result. If even that results in overly long
lines, you can do this

Dim sArray as String
sArray = "1|2|3|4|5"
sArray = sArray & "|6|7|8|9|10"
myArray = Split(sArray, "|")


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
L

Lene Fredborg

Just leave out the comma in the start of the new line. The empty line in your
list is caused by your two commas with no value in between.

Instead of:
example myArray = Array("1 ", "2", "3", _
, "4", "to 96")

use:
example myArray = Array("1 ", "2", "3", _
"4", "to 96")


--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
S

SN

Thank you so much,

I Appreciate your help

Lene Fredborg said:
Just leave out the comma in the start of the new line. The empty line in your
list is caused by your two commas with no value in between.

Instead of:
example myArray = Array("1 ", "2", "3", _
, "4", "to 96")

use:
example myArray = Array("1 ", "2", "3", _
"4", "to 96")


--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top