Base Basic Básico

Teste de código

REM  *****  BASIC  *****
 
Sub Main
	
End Sub
 
'Open one form, using a button, where in the property "Additional information" of
'the button the user put "name_form_to_open,name_form_to_close" and the name_form_to_close
'is the form that the button is in.
'Abre um form, usando um botão, onde na propriedade "Informações adicionais" do
'botão o usuário coloca "nome_form_que_quer_abrir,nome_form_que_quer_fechar", sendo o
'nome_form_que_quer_fechar o form que possui o botão.
SUB From_form_to_form(oEvent AS OBJECT)
	DIM stTag AS String
	'vá nas propriedades do botão, na aba "Geral", em "Informações adicionais" e
	'coloque "FrmCadastroPessoa,FrmUnificaçãoDesmemb" que são os dois forms, o 1º é o
	'que vai abrir e o 2º o que vai fechar
	stTag=oEvent.Source.Model.Tag
	aForm() = Split(stTag, ",")
	'ThisDatabaseDocument it refers to the Base document (MyDataBaseDoc.odb)
	ThisDatabaseDocument.FormDocuments.getByName( Trim(aForm(0)) ).open
	ThisDatabaseDocument.FormDocuments.getByName( Trim(aForm(1)) ).close
END SUB
 
'Open one form, using a button, where in the property "Additional information" of
'the button the user put "name_form_to_open"
'Abre um form, usando um botão, onde na propriedade"Informações adicionais" do
'botão o usuário coloca "nome_form_que_quer_abrir"
SUB Open_form(oEvent AS OBJECT)
	DIM stTag AS String
	'vá nas propriedades do botão, na aba "Geral", em "Informações adicionais" e
	'coloque "FrmCadastroPessoa" que é o form que se quer abrir
	stTag=oEvent.Source.Model.Tag
	aForm() = Split(stTag, ",")
	'ThisDatabaseDocument it refers to the Base document (MyDataBaseDoc.odb)
	ThisDatabaseDocument.FormDocuments.getByName( Trim(aForm(0)) ).open
END SUB
 
REM Não Usar esta função, ela é só uma função de teste
SUB Open_form_pass_key(oEvent AS OBJECT)
	DIM stTag AS String
	DIM oDoc AS OBJECT
	DIM oDrawpage AS OBJECT
	DIM oForm1 AS OBJECT
	DIM oForm2 AS OBJECT
	DIM oField1 AS OBJECT
	DIM oField2 AS OBJECT
	'thisComponent refers to the Form document
	oDoc = thisComponent
	oDrawpage = oDoc.drawpage
	'vá nas propriedades do botão, na aba "Geral", em "Informações adicionais" e
	'coloque "FrmCadastroPessoa" que é o form que se quer abrir
	stTag=oEvent.Source.Model.Tag
	aForm() = Split(stTag, ",")
	ThisDatabaseDocument.FormDocuments.getByName( Trim(aForm(0)) ).open
	
	DIM oDoc1 AS OBJECT
	DIM oDrawpage1 AS OBJECT
	oDoc1 = StarDesktop.CurrentComponent
	oDrawpage1 = oDoc1.drawpage
	oForm1 = oDrawpage1.forms.getByName("MainForm")
	oField1 = oForm1.getByName("fmtCodPessoa")
	MsgBox(oField1.getCurrentValue())
	
	oForm2 = oDrawpage.forms.getByName("MainForm")
	oField2 = oForm2.getByName("fmtCodProcesso")
	MsgBox(oField2.getCurrentValue())
END SUB
 
Sub	Copy_key(oEvent AS OBJECT)
	Dim vTemp
	'In the current form, we get the the foring key
	DIM oDoc AS OBJECT
	DIM oDrawpage AS Object
	DIM oForm1 AS OBJECT
	DIM oField1 AS OBJECT
	'thisComponent refers to the Form document
	oDoc = thisComponent
	oDrawpage = oDoc.drawpage
	oForm1 = oDrawpage.forms.getByName("MainForm")
	oField1 = oForm1.getByName("fmtCodPessoa")
	vTemp = oField1.getCurrentValue()
	
	DIM stTag AS String
	'vá nas propriedades do botão, na aba "Geral", em "Informações adicionais" e
	'coloque "FrmUnificaçãoDesmemb" que é o form que se quer abrir
	stTag=oEvent.Source.Model.Tag
	aForm() = Split(stTag, ",")
	'ThisDatabaseDocument refers to the Base document (MyDataBaseDoc.odb)
	ThisDatabaseDocument.FormDocuments.getByName( Trim(aForm(0)) ).open
	
	'In the other form, we put the value of the key we copied
	DIM oForm2 AS Object
	Dim oSubForm2 As Object
	Dim oTable As Object
	DIM oField2 AS Object
	'thisComponent refers to the Form document
	oDoc = StarDesktop.CurrentComponent
	oDrawpage = oDoc.drawpage
	oForm2 = oDrawpage.forms.getByName("MainForm")
	oSubForm2 = oForm2.getByName("SubFormProprietario")
	oTable = oSubForm2.getByName("Proprietarios")
	oField2 = oTable.getByName("CodPessoa")
	'oField2 = oForm2.getByName("numField1")
	oField2.Value = vTemp
	'oField2.effectiveValue = vTemp
	oField2.commit() 'commits the content of the component into the data source it is bound to
	
	'The line below was commented out becouse we do not want it to insert automatically to the DataBase
	'A linha abaixo foi colocada como comentário pois não queremos que insira automaticamente no Banco de  Dados
	'oSubForm2.insertRow() 'Inserts the contents of the insert row into the result set and the database. Must be on the insert row when this method is called.
	
	'The line below was commented out becouse we do not want it to save the change automatically
	'A linha abaixo foi colocada como comentário pois não queremos que salve a alteração automaticamente
	'oSubForm2.updateRow() 'Updates the underlying database with the new contents of the current row. Cannot be called when on the insert row.
	
	'MsgBox(oField2.getCurrentValue())
	
End Sub