LemonBradder
10-20-2014, 09:25 AM
Hi,
The following code are two parts of the code for a userfrom. The Sub FillVars is usings variables from a Call in the Modules code.
Sub FillVars(LabelStr As String, StringsArr() As String, bookMarks() As String)
Dim numOptions As Integer, i As Integer
Dim OptionsArr() As String
Dim selectionInt As Integer
numOptions = UBound(StringsArr, 1)
ReDim OptionsArr(numOptions)
For i = 0 To numOptions
OptionsArr(i) = StringsArr(i, 0)
Next i
Label1.Caption = LabelStr
ComboBox1.List = OptionsArr
End Sub
Private Sub OkButton_Click()
selectionInt = ComboBox1.ListIndex
If selectionInt >= 0 Then
ActiveDocument.bookMarks(bookMarks(0)).Range.Text = StringsArr(selectionInt, 1)
ActiveDocument.bookMarks(bookMarks(1)).Range.Text = StringsArr(selectionInt, 2)
End If
selectionInt = -1
Unload ExportForm
End Sub
My issue is that OkButton_Click (triggered from the pressing of a command button) does not have access to StringsArr() or bookMarks() in order to do it's bookMarks commands. Is there any why to pass these arrays to OkButton_Click in the same way that ComboBox1.List is available.
I do not want to make a second combobox that just passes arrays. People will only ask why it is there.
I am aware that all functions can work with Public Arrays but I want to avoid doing this for the following reasons:
1. I have been told that it is risky using global functions when making tools to be used by many users (such as this current Project) (i.e. Global i As Integer will clash a lot of beginners codes)
2. The Calling of the user form is done multiple times. This means constantly resetting and error checking the arrays between calls as I don't want to risk an instance using the arrays from a previous instance (which will work as they require the same format).
3. The StringsArr instances will all be ,3 times x, 2D arrays where x varies between intances. In order to support a Public array I would have to write ReDim and Ubound loops to handle lot's of x variation to move from specific instance array to Public array. I could but it seems inefficient to have code copying arrays one for one rather than find a By Reference method.
Please let me know how you would handle this case? Thanks in advance.
James.
The following code are two parts of the code for a userfrom. The Sub FillVars is usings variables from a Call in the Modules code.
Sub FillVars(LabelStr As String, StringsArr() As String, bookMarks() As String)
Dim numOptions As Integer, i As Integer
Dim OptionsArr() As String
Dim selectionInt As Integer
numOptions = UBound(StringsArr, 1)
ReDim OptionsArr(numOptions)
For i = 0 To numOptions
OptionsArr(i) = StringsArr(i, 0)
Next i
Label1.Caption = LabelStr
ComboBox1.List = OptionsArr
End Sub
Private Sub OkButton_Click()
selectionInt = ComboBox1.ListIndex
If selectionInt >= 0 Then
ActiveDocument.bookMarks(bookMarks(0)).Range.Text = StringsArr(selectionInt, 1)
ActiveDocument.bookMarks(bookMarks(1)).Range.Text = StringsArr(selectionInt, 2)
End If
selectionInt = -1
Unload ExportForm
End Sub
My issue is that OkButton_Click (triggered from the pressing of a command button) does not have access to StringsArr() or bookMarks() in order to do it's bookMarks commands. Is there any why to pass these arrays to OkButton_Click in the same way that ComboBox1.List is available.
I do not want to make a second combobox that just passes arrays. People will only ask why it is there.
I am aware that all functions can work with Public Arrays but I want to avoid doing this for the following reasons:
1. I have been told that it is risky using global functions when making tools to be used by many users (such as this current Project) (i.e. Global i As Integer will clash a lot of beginners codes)
2. The Calling of the user form is done multiple times. This means constantly resetting and error checking the arrays between calls as I don't want to risk an instance using the arrays from a previous instance (which will work as they require the same format).
3. The StringsArr instances will all be ,3 times x, 2D arrays where x varies between intances. In order to support a Public array I would have to write ReDim and Ubound loops to handle lot's of x variation to move from specific instance array to Public array. I could but it seems inefficient to have code copying arrays one for one rather than find a By Reference method.
Please let me know how you would handle this case? Thanks in advance.
James.