Not the place for a lesson on writing functions to use from a speadsheet but I spent a few hours reading doc's and as wonderful as the facilities are they are a long way from what Basic should be. I did find a couple of examples then and came up with this for a diving head division calculator. Just the start getting the info in it and getting results back which at the moment are just what was input.
REM ***** BASIC *****
Option Explicit
Option Compatible
REM Public RowData(29) as variant
Public Function DivHead (Count as integer,RowRange as variant )
Dim CellValue as variant
Dim Counter as integer
Dim AllValues (Count-1) as integer 'The -1 will(?) cause probs with MS
if not isarray (RowRange) then
MsgBox "2nd Value Must be a Range"
exit function
end if
for each CellValue in RowRange
MsgBox "b " & CellValue
AllValues(Counter)=CellValue
Counter=Counter+1
next
DivHead = StringIt ( AllValues ) 'Covert array values to a string
' so lots can be returned
End Function
Public Function StringIt ( InputArray as Integer )
Dim ReturnString as String
Dim Avalue as Integer
Dim Row as Integer
For Row = LBound ( InputArray,1 ) to Ubound ( InputArray,1 )
Avalue = InputArray ( Row )
Rem MsgBox "String " & Avalue
ReturnString = ReturnString & Avalue & ";"
Next
Stringit = ReturnString
End Function
'A 2 dimensional arrat of cells – copied from a guide and not tried
' It sums numbers > 0 in the array eg used with Addup (B6:D12) etc
'
'Punlic Function AddUp( Range )
' Dim TheSum As Double
' Dim iRow As Integer
' Dim iCol As Integer
' TheSum = 0.0
' For iRow = LBound(Range, 1) To UBound(Range, 1)
' For iCol = LBound(Range, 2) To UBound(Range, 2)
' If Range(iRow, iCol) > 0 Then TheSum = TheSum + Range(iRow, iCol)
' Next
' Next
The lower commented out AddUp function is just another way of reading a range of cells other than the one I used in DivHead. where for each in is used. It seems functions can only return one entity hence converting and array of values to a string ie text. My idea. I will see if it's possible to write directly to any number of cells from a function but it may not be.
John
–
Edited By Ajohnw on 23/05/2016 16:44:49