Skip to content

Instantly share code, notes, and snippets.

@vndmtrx
Created June 21, 2012 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vndmtrx/2968271 to your computer and use it in GitHub Desktop.
Save vndmtrx/2968271 to your computer and use it in GitHub Desktop.
Macro Planilha Orçamento
REM ***** BASIC *****
'http://wiki.documentfoundation.org/images/d/d8/0312CG3-CalcMacros.odt
option explicit
sub efetua_lancamento
'Doc = ThisComponent
'Sheet = oDoc.CurrentController.getActiveSheet()
'Sheets = oDoc.getSheets()
'Sheet = Sheets.getByName("AdSense")
'Cell = Sheet.getCellrangeByName("B8")
'celula = Cell.getString()
'colunas = Sheet.Rows()
'Outra = Sheet.getCellrangeByName(celula)
'Outra.setString(colunas.count())
'Exit Sub
'Msgbox(busca_ultimo_registro("AdSense").getName(), 16, "Transferência de Valores")
'Msgbox(busca_ultimo_registro("AdSense").getCellByPosition(0,0).getString(), 16, "Transferência de Valores")
Msgbox(busca_ultimo_registro("AdSense").getCellByPosition(1,0).getString(), 16, "Transferência de Valores")
'if (valida_linha(busca_ultimo_registro(ThisComponent.getSheets().getByName("Contra-cheques").GetName())) = 0) then
' Msgbox("Erro na Operação", 16, "Transferência de Valores")
'end if
end sub
' Função busca_ultimo_registro
'
' Método responsável por encontrar a última linha preenchida na tabela
' Retorna um objeto linha com a linha correspondente.
'
function busca_ultimo_registro(byval plan as string) as object
dim rows as object
dim i as integer
rows = ThisComponent.getSheets().getByName(plan).getRows()
i = 0
do
'if (rows.getByIndex(i).getCellByPosition(0,0).getString() <> "") then
if (is_linha_vazia(rows.getByIndex(i)) = 0) then
i = i + 1
else
i = i - 1 'Se a linha atual é vazia, a linha anterior é a última.
exit do
end if
loop
busca_ultimo_registro() = rows.getByIndex(i)
end function
' Função busca_linha_livre
'
' Método responsável por encontrar a próxima linha disponível na tabela
' Retorna um objeto linha com a linha correspondente.
'
function busca_linha_livre(byval plan as string) as object
dim rows as object
dim i as integer
rows = ThisComponent.getSheets().getByName(plan).getRows()
i = 0
do
'if (rows.getByIndex(i).getCellByPosition(0,0).getString() <> "") then
if (is_linha_vazia(rows.getByIndex(i)) = 0) then
i = i + 1
else
exit do
end if
loop
busca_linha_livre() = rows.getByIndex(i)
end function
' Função is_linha_vazia
'
' Método responsável por avaliar se uma linha possui campos preenchidos
' Retorna 1 caso a linha esteja vazia; 0 caso haja campos preenchidos na linha.
'
function is_linha_vazia(linha as object) as integer
dim i as integer
dim retorno as integer
retorno = 1
for i = 0 to 6
if (linha.getCellByPosition(i,0).String <> "") then
retorno = 0
exit for
end if
next i
is_linha_vazia() = retorno
end function
' Função valida_linha
'
' Método responsável por fazer a verificação de todos os parâmetros da linha de forma a garantir que
' a operação de lançamento reverso funcione de maneira correta.
'
' Caso hajam campos faltantes ou errados, uma mensagem será exibida dizendo o erro relatado.
'
function valida_linha(linha as object) as integer
dim retorno as integer
dim linhas as object
dim enum_linhas as object
dim erro as Boolean
dim i as integer
retorno = 1
erro = 0
' Data, Item e Montante
if (linha.getCellByPosition(0,0).String = "") or (linha.getCellByPosition(1,0).String = "") or (linha.getCellByPosition(2,0).String = "") then
retorno = 0
Msgbox("Data, Item e Montante não podem ser vazios!", 16, "Transferência de Valores")
end if
'operação = dèbito ou crédito
if (linha.getCellByPosition(3,0).String <> ThisComponent.getSheets().getByName("Config").getCellrangeByName("C2").String) and (linha.getCellByPosition(3,0).String <> ThisComponent.getSheets().getByName("Config").getCellrangeByName("C3").String) then
retorno = 0
Msgbox("Operação deve ser " + ThisComponent.getSheets().getByName("Config").getCellrangeByName("C2").String + " ou " + ThisComponent.getSheets().getByName("Config").getCellrangeByName("C3").String + "!", 16, "Transferência de Valores")
end if
'categoria = transferência
if (linha.getCellByPosition(4,0).String <> ThisComponent.getSheets().getByName("Config").getCellrangeByName("A2").String) then
retorno = 0
Msgbox("Categoria da operação deve ser " + ThisComponent.getSheets().getByName("Config").getCellrangeByName("A2").String + "!", 16, "Transferência de Valores")
end if
'notas = uma das contas
linhas = ThisComponent.getSheets().getByName("Contas").getCellRangeByName("AdmContas")
for i = lbound(linhas.getData()) to ubound(linhas.getData())
if (linha.getCellByPosition(5,0).String = linhas.getCellByPosition(0,i).String) then
erro = 1
exit for
end if
next i
if (erro = 0) then
retorno = 0
Msgbox("Em notas deve constar o nome da conta de destino!", 16, "Transferência de Valores")
end if
valida_linha() = retorno
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment