(VBA-PPT) Redim error 9? Index out of bounds - vba

I dont get it - i have an array in a different module, which holds the data and is initialised at start with standard values.
When i try to use daten.getWasserTemp() it seems not deliver a array everytime. Arraysize incoming is always 5.
The line with vWate(1) throws an array out of bounds error 9. (line 5)
EDIT:
The data is saved in module daten.
It gets initialised when the slide (slide30) is first opened with method daten.reset()
Thanks!
Can you help me? I am blind.. Thanks!
Module Logik:
Dim vTemp As Double
Dim vWate() As Double
ReDim vWate(5)
vWate = daten.getWasserTemp
If vWate(1) <= 0 Then vTemp = 0
Module Daten:
Dim vWasserTemp() As Double
....
Function getWasserTemp() As Double()
getWasserTemp = vWasserTemp
End Function
...
sub reset ()
vWasserTemp(1) = 15
vWasserTemp(2) = 14
vWasserTemp(3) = 5
vWasserTemp(4) = 4
end sub
Module Slide30:
Sub OnSlideShowPageChange()
daten.reset
End Sub

Related

VBA: Select all slides of defined sections

I'm playing with a progress bar (with basically zero experience with VBA whatsoever). I found the following snippet online:
Sub ProgressBar()
On Error Resume Next
With ActivePresentation
.SectionProperties.SlidesCount(
For N = 2 To .Slides.Count
.Slides(N).Shapes("Progress_Bar").Delete
Set s = .Slides(N).Shapes.AddShape(msoShapeRectangle, 0, .PageSetup.SlideHeight - 10, N * .PageSetup.SlideWidth / .Slides.Count, 10)
Call s.Fill.Solid
s.Fill.ForeColor.RGB = RGB(128, 128, 128)
s.Line.Visible = False
s.Name = "Progress_Bar"
Next N:
End With
End Sub
Note the part with For N = 2 To .Slides.Count. I'd like the progress bar not to reach from the second slide the last one but rather from the second slide to the last slide of the section I called "conclusion". How can I do that?
Thanks!
Edit: My current workaround is a hard coded number of slides that I define as a variable at the beginning of the macro and then use the variable throughout the rest of it.
Here are a couple of bits that should get you started:
LastSlideOf returns the slide index of the last slide in the named section passed to it:
Function LastSlideOf(sSectionName As String) As Long
Dim x As Long
With ActivePresentation.SectionProperties
x = SectionIndexOf(sSectionName)
LastSlideOf = (.FirstSlide(x) + .SlidesCount(x)) - 1
End With
End Function
Function SectionIndexOf(sSectionName As String) As Long
Dim x As Long
With ActivePresentation.SectionProperties
For x = 1 To .Count
If .Name(x) = sSectionName Then
SectionIndexOf = x
End If
Next
End With
End Function

Small function to rearrange string array in VBA

I've been writing a macro for Solidworks in VBA, and at one point I'd like to rearrange the sheets in a drawing in the following way--if any of the sheets are named "CUT", bring that sheet to the front. Solidworks API provides a way to rearrange the sheets, but it requires an array of sheet names sorted into the correct order--fair enough. The way to get the sheet names looks to be this method.
So, I tried to write a small function to rearrange the sheets in the way I want. The function call I'm trying to use and the function are shown here
Function Call
Dim swApp As SldWorks.SldWorks
Dim swDrawing As SldWorks.DrawingDoc
Dim bool As Boolean
Set swApp = Application.SldWorks
Set swDrawing = swApp.ActiveDoc
.
.
.
bool = swDrawing.ReorderSheets(bringToFront(swDrawing.GetSheetNames, "CUT"))
Function Definition
Private Function bringToFront(inputArray() As String, _
stringToFind As String) As String()
Dim i As Integer
Dim j As Integer
Dim first As Integer
Dim last As Integer
Dim outputArray() As String
first = LBound(inputArray)
last = UBound(inputArray)
ReDim outputArray(first to last)
For i = first To last
If inputArray(i) = stringToFind Then
For j = first To (i - 1)
outputArray(j + 1) = inputArray(j)
Next j
For j = (i + 1) To last
outputArray(j) = inputArray(j)
Next j
outputArray(first) = stringToFind
End If
Next i
bringToFront = outputArray
End Function
The error I get is "Type mismatch: array or user defined type expected" on the function call line. I've done quite a bit of searching and I think what I'm messing up has to do with static vs dynamic arrays, but I haven't quite been able to get to the solution on my own.
Besides the corrections suggested in the comments, what is happening is that at the lines
bringToFront(j + 1) = inputArray(j)
and
bringToFront(first) = stringToFind
the compiler thinks you are trying to call recursively the function bringToFront. That is why it complains about the number of parameters in the error message. To fix this, just create another array as local array variable, with a different name, let us name it "ret", fill it appropriately, and assign it at the end before returning.
EDIT: Also, it is better to declare the arrays as Variant types to avoid interoperability problems between VB6 and .Net . This was the final issue
Private Function bringToFront(inputArray As Variant, _
stringToFind As String) As Variant
Dim i As Integer
Dim j As Integer
Dim first As Integer
Dim last As Integer
first = LBound(inputArray)
last = UBound(inputArray)
Dim ret() As String
ReDim ret(first To last)
For i = first To last
If inputArray(i) = stringToFind Then
For j = first To (i - 1)
ret(j + 1) = inputArray(j)
Next j
ret(first) = stringToFind
End If
Next i
bringToFront = ret
End Function

'AddRange' is not a member of... (while i attempt to save column order of a DataGridView

I'm trying to save and load the data grid view column order.
I'm using this code that i suppose is also right.
Private Sub SaveColumnOrder()
Dim upperBound As Integer = Me.DataTable1DataGridView.ColumnCount - 1
Dim columnIndexes(upperBound) As String
For index As Integer = 0 To upperBound
Dim column As DataGridViewColumn = Me.DataTable1DataGridView.Columns(index)
columnIndexes(column.DisplayIndex) = index.ToString()
Next
My.Settings.GridColumnIndexes = New StringCollection
My.Settings.GridColumnIndexes.AddRange(columnIndexes)
End Sub
Private Sub LoadColumnOrder()
Dim columnIndexes As StringCollection = My.Settings.GridColumnIndexes
For displayIndex As Integer = 0 To columnIndexes.Count - 1
Dim index As Integer = CInt(columnIndexes(displayIndex))
Me.DataTable1DataGridView.Columns(index).DisplayIndex = displayIndex
Next
End Sub
Problem is that i don't know how to set the GridColumnIndexes inside project property settings.
I set to string and other "data" options but i always get the error: 'AddRange' is not a member of... {option selected}
Which is the right option in settings to make it finally work? Thank you :)

Why is list of objects giving "Illegal Parenthesized Reference" error when adding to it via LotusScript agent?

Have this line of lotusscript code in an agent that gives an "Illegal Parenthesized Reference: Items" error:
Set tempObligor.Facilities.items(Cstr(facilitydoc.requestnum(0))) = tempFacility
Facilities.items is defined as a list of objects.
So not getting why error is being thrown by the Notes 8.5 designer.
Equally odd that this worked without problem in Notes 8.0.2.
Code that makes up the objects is below.
Let me know if you have any ideas.
Believe I can do a work around by using a FOR loop that goes through all values looking for a match... but not knowing why the error is occurring bugs me...
Dim tempObligor As Obligor
'This line errs out - does not like () after .items
Set tempObligor.Facilities.items(Cstr(facilitydoc.requestnum(0))) = tempFacility
Class Obligor As CollectableObject
Public Facilities As SortableList
End Class
Class CollectableObject
' STUB
End Class
Class SortableList
Public items List As CollectableObject
Private Sub Sort()
Dim uboundarray As Integer
Dim nextTag As String
Dim x As Integer
Dim sortedArray As Variant
Dim ArrayToSort() As Variant
uboundArray = 0
Forall elem In items
NextTag = Listtag(elem)
Redim Preserve ArrayToSort(uboundArray)
ArrayToSort(uboundArray) = NextTag
uboundArray = uboundArray + 1
End Forall
SortedArray = SortArray(ArrayToSort)
Dim TempList List As CollectableObject
For x = 0 To Ubound(SortedArray)
Set TempList(SortedArray(x)) = items(SortedArray(x))
Next
Erase items
Forall elem In TempList
Set items(Listtag(elem)) = TempList(Listtag(elem))
End Forall
Erase TempList
End Sub
Function SortArray(ArrayToSort) As Variant
Dim NumberOfElements As Integer
Dim temp As String
Dim x As Integer
Dim y As Integer
NumberOfElements = Ubound(ArrayToSort)
If NumberOfElements% = 0 Then
SortArray = ArrayToSort
Exit Function
End If
For x = 0 To (NumberOfElements)
For y = 0 To ( NumberOfElements - x - 1)
If Ucase$(ArrayToSort(y)) > Ucase$(ArrayToSort(y+1)) Then
temp = ArrayToSort(y)
ArrayToSort(y) = ArrayToSort(y+1)
ArrayToSort(y+1) = temp$
End If
Next y
Next x
SortArray = ArrayToSort
End Function
End Class
I pasted your code into a ScriptLibrary. At first I got the same error. Then I noticed that there is another error of type "Reference appears before declaration" in the class definition of class Obligor. Your class Obligor is of type CollectableObject. Domino Designer seems to have a problem with the fact that CollectableObject is referenced before it is defined. So you should place the class Obligor after that class definition and then your code should work (I had to move the first two lines in the initilize though).

How to get each value in an array and show it in a listbox

Hi I am new to VB and I have problems with using array. My code is like that.
This is class FindFactorsObject.vb
Public Sub FindFactors()
count = 0
temp = Convert.ToInt32(Math.Sqrt(_x))
For i As Integer = 1 To temp
If _x Mod i = 0 Then
ReDim array(count)
array(count) = i
count += 1
End If
Next
So I created an array and stored the results. Now I want to display each value in my array in Form.vb and if it is possible can somebody teach me how to make delay for each of the displayed value. Thanks very much
Always declare your variables, if possible to their exact types, you think they will take care of. When you say 'Now I want to display each value in my array in Form.vb' I understood literally: in the Form so, we will print them on your form
Public Sub FindFactors(_x As Integer)
Dim temp As Integer = Convert.ToInt32(Math.Sqrt(_x))
Dim l As New List(Of Integer)
For i As Integer = 1 To temp
If _x Mod i = 0 Then
l.add(i)
End If
Next
Dim pf As New PointF(20, 20)
For Each i As Integer In l
creategraphics.drawstring(i.ToString, New font(font.fontFamily, 24), brushes.cadetblue, pf)
pf = New PointF(pf.X, pf.Y + 30)
Next
End Sub