Friday, November 10, 2006

Arrays as subroutine arguments

In the last version of VBA that I used, if one wanted to use an array as an argument in a subroutine or function, one was limited to one array which had to be the last argument. This isn't the case with ooo basic. One or more arguments can be arrays, and arrays can be placed anywhere in the argument list.

Thursday, November 09, 2006

start to Main

This is the start to my main macro. I'm putting it here so it's less likely for me to lose it again. It just shows different ways to get info from a dialog.

dim ten(9)
oDSheet = ThisComponent.Sheets.getbyName("Data")
oDRange = ThisComponent.Sheets.getByName("Data").getCellbyposition(0,0)
ThisComponent.getCurrentController.select(oDRange)

with oDialog1
tfield = .getcontrol("ListField").getselecteditem()
dsn = .getcontrol("Label1").text
if .getcontrol("CheckNegAdj").state then
n = right(dsn,1)
if n = "1" then n = "0" else n = "1"
dsn = left(dsn,2) & n
end if
PPS = .getcontrol("NumPPS").value

ten(0) = .getcontrol("NumShares").value
if mid(dsn,2,1) then
if ten(0) = 0 then msgbox "number of shares?" : exit sub
if right(dsn,1) = "1" and ten(0) > 0 then ten(0) = 0 - ten(0)
if right(dsn,1) = "0" and ten(0) < 0 then ten(0) = 0 - ten(0)
else
ten(0) = ""
end if
ten(1) = .getcontrol("ComboName").text
if ten(1) = "" then
if .getcontrol("CheckChange").state then
answer = msgbox("Is this a broker name change?",4,"name change/transfer")
if answer <> 6 then msgbox tfield & " name?" : exit sub
else
msgbox tfield & " name?" : exit sub
end if
end if
ten(2) = .getcontrol("DateField1").text
if not isdate(ten(2)) then msgbox "date is not date" : exit sub
if datediff("d",ten(2),now) < 0 then msgbox "date is in future" : exit sub
date1 = ten(2)
ten(3) = year(ten(2))
ten(4) = choose(month(ten(2)),1,1,1,2,2,2,3,3,3,4,4,4)
if month(ten(2)) = 1 and day(ten(2)) < 5 then
answer = MsgBox("Should this be reported as previous year income?", 4, "Reportable")
If answer = 6 Then
ten(3) = ten(3) - 1
ten(4) = 4
ten(7) = "reportable " & ten(3) & " " & ten(7)
End If
end if
ten(5) = .getcontrol("NumCash").value
if left(dsn,1) then
if ten(5) = 0 then msgbox "cash amount?" : exit sub
if right(dsn,1) = "1" and ten(5) > 0 then ten(5) = 0 - ten(5)
if right(dsn,1) = "0" and ten(5) < 0 then ten(5) = 0 - ten(5)
else
ten(5) = ""
end if
ten(6) = .getcontrol("ComboType").text
if .getcontrol("CheckPPS").state then ten(6) = "PPS"
if .getcontrol("CheckLieu").state then ten(6) = "cash in lieu"
if tfield = "cash" and ten(6) = "div" then
temp = msgbox("Is this a mm div?",4,"mm div?")
if temp = 6 then ten(6) = "mm div"
if ten(6) = "buy" then ten(6) = "dep"
if ten(6) = "sell" then ten(6) = "wth"
end if
if ten(6) = "" then msgbox "transaction?" : exit sub
if .getcontrol("CheckNonTax").state then
ten(6) = "non " & ten(6)
temp = msgbox("Is this reportable?",4 + 256,"Reportable?")
if temp = 7 then ten(6) = "n " & ten(6)
end if
if .getcontrol("CheckChange").state then
ten(6) = "change"
else
if .getcontrol("CheckCorrection").state then
oldtype = ten(6)
ten(6) = .getcontrol("ComboCorrection").text
if ten(6) = "" then msgbox "new transaction type?" : exit sub
end if
end if

ten(7) = .getcontrol("TextComments").text
if .getcontrol("CheckNegAdj").state then ten(7) = "Correction--" & ten(7)
ten(8) = .getcontrol("ComboBroker").text
ten(9) = ""
if val(ten(5)) <> 0 then
if tfield = "cash" then
if ten(6) = "dep" or ten(6) = "wth" then ten(0) = ten(5)
if .getcontrol("CheckReinv").state then ten(0) = ten(5)
end if
if val(ten(0)) <> 0 then
ten(9) = ten(5)
if PPS = 0 then PPS = Rounding(ten(5)/ten(0),3)
end if
end if
end with