[LØST] Opdatere udregning når man skifter post?

Brugerhjælp og support til databaser i LibreOffice Base

Redaktør: Lodahl

Besvar
SnowmanDK
Indlæg: 23
Tilmeldt: 16. jun 2009 12:16
Geografisk sted: Hammel

[LØST] Opdatere udregning når man skifter post?

Indlæg af SnowmanDK » 13. apr 2010 15:52

Hvordan kører man sine sql forespørgsler (der er 2) hver gang man skifter til en anden post? De skal også køre hver gang visse felter ændrer værdi.

Formoder at man skal bruge en makro :?:
Senest rettet af SnowmanDK 8. jun 2010 09:35, rettet i alt 2 gange.

SnowmanDK
Indlæg: 23
Tilmeldt: 16. jun 2009 12:16
Geografisk sted: Hammel

Indlæg af SnowmanDK » 16. apr 2010 10:40

Opdaterer lige mit spørgsmål.
Databasen kører via en mysql server gennem ODBC v3.51 connector.

Vi har en tabel med 24 talværdier. Værdierne der er tilladt er 0, 1, 2, 3, 4 og 9. Alle andre værdier kan ikke sættes ind.
Disse tal (plus en del andre data) trækkes ind og vises i en formular.
Værdierne i de felter der indeholder de tal, skal nu lægges sammen i grupper, men KUN tallene 0-4 skal regnes med. 9-taller skal bare ignoreres.
Desuden skal der udregnes et gennemsnit for værdierne, igen uden at 9-taller tæller med.
Alt dette har vi fået til at virke...

MEN...
Vores fine forespørgsler virker kun på FØRSTE post. Alle øvrige poster viser bare resulterne fra første post. "Refresh" er prøvet uden effekt. Hvordan får man den til at vise udregninger for den post der vises i formularen her-og-nu?

SnowmanDK
Indlæg: 23
Tilmeldt: 16. jun 2009 12:16
Geografisk sted: Hammel

LØSNING!

Indlæg af SnowmanDK » 8. jun 2010 09:38

Alt via MySQL blev droppet. Løsningen er en makro der trækker på formular data.

Kode: Vælg alt

REM  *****  BASIC  *****
Sub CalcTest(oEvent As Object)
	Dim Form As Object
	Dim Result1 As Integer, Result2 As Integer
	Form = ThisComponent.Drawpage.Forms.getbyName("MainForm")
	'--------------------------------------------------------------------------------------
	'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	'--------------------------------------------------------------------------------------
		'A Dimensions
		Dim FmtFelt11 as Integer, FmtFelt12 as Integer
		Dim FmtFelt21 as Integer, FmtFelt22 as Integer
		Dim FmtFelt31 as Integer, FmtFelt32 as Integer
		'A Henter Data fra formular
		FmtFelt11 = Form.getByName("FmtFelt11_H").text
		FmtFelt12 = Form.getByName("FmtFelt12_H").text
		FmtFelt21 = Form.getByName("FmtFelt21_H").text
		FmtFelt22 = Form.getByName("FmtFelt22_H").text
		FmtFelt31 = Form.getByName("FmtFelt31_H").text
		FmtFelt32 = Form.getByName("FmtFelt32_H").text
		'A Kontrollér data
		If Len(FmtFelt11) = 1 and Len(FmtFelt21) = 1 and Len(FmtFelt31) = 1 then
			If FmtFelt11 > 4 then FmtFelt11 = 0
			If FmtFelt21 > 4 then FmtFelt21 = 0
			If FmtFelt31 > 4 then FmtFelt31 = 0
			Result1 = FmtFelt11 + FmtFelt21 + FmtFelt31
		else
			Result1 = 0
			Form.getByName("fmtA1Total").text = Result1
		end if
		If Len(FmtFelt12) = 1 and Len(FmtFelt22) = 1 and Len(FmtFelt32) = 1 then
			If FmtFelt32 > 4 then FmtFelt32 = 0
			If FmtFelt32 > 4 then FmtFelt32 = 0
			If FmtFelt32 > 4 then FmtFelt32 = 0
			Result2 = FmtFelt12 + FmtFelt22 + FmtFelt32
		else
			Result2 = 0
			Form.getByName("fmtA2Total").text = Result2
		end if
		'A Indsæt resultat
		Form.getByName("fmtA1Total").text = Result1
		Form.getByName("fmtA2Total").text = Result2
	'--------------------------------------------------------------------------------------
	'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
	'--------------------------------------------------------------------------------------
		'B Dimensions
		Dim FmtFelt41 as Integer, FmtFelt42 as Integer
		Dim FmtFelt51 as Integer, FmtFelt52 as Integer
		'B Henter Data fra formular
		FmtFelt41 = Form.getByName("FmtFelt41_H").text
		FmtFelt42 = Form.getByName("FmtFelt42_H").text
		FmtFelt51 = Form.getByName("FmtFelt51_H").text
		FmtFelt52 = Form.getByName("FmtFelt52_H").text
		'B Kontrollér data
		If Len(FmtFelt41) = 1 and Len(FmtFelt51) = 1 then
			If FmtFelt41 > 4 then FmtFelt41 = 0
			If FmtFelt51 > 4 then FmtFelt51 = 0
			Result1 = FmtFelt41 + FmtFelt51
		else
			Result1 = 0
			Form.getByName("fmtB1Total").text = Result1
		end if
		If Len(FmtFelt42) = 1 and Len(FmtFelt52) = 1 then
			If FmtFelt42 > 4 then FmtFelt42 = 0
			If FmtFelt52 > 4 then FmtFelt52 = 0
			Result2 = FmtFelt42 + FmtFelt52
		else
			Result2 = 0
			Form.getByName("fmtB2Total").text = Result2
		end if
		'B Indsæt resultat
		Form.getByName("fmtB1Total").text = Result1
		Form.getByName("fmtB2Total").text = Result2
	'--------------------------------------------------------------------------------------
	'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
	'--------------------------------------------------------------------------------------
		'C Dimensions
		Dim FmtFelt61 as Integer, FmtFelt62 as Integer
		Dim FmtFelt71 as Integer, FmtFelt72 as Integer
		Dim FmtFelt8B1 as Integer, FmtFelt8B2 as Integer
		'C Henter Data fra formular
		FmtFelt61 = Form.getByName("FmtFelt61_H").text
		FmtFelt62 = Form.getByName("FmtFelt62_H").text
		FmtFelt71 = Form.getByName("FmtFelt71_H").text
		FmtFelt72 = Form.getByName("FmtFelt72_H").text
		FmtFelt8B1 = Form.getByName("FmtFelt8B1_H").text
		FmtFelt8B2 = Form.getByName("FmtFelt8B2_H").text
		'C Kontrollér data
		If Len(FmtFelt61) = 1 and Len(FmtFelt71) = 1 and Len(FmtFelt8B1) = 1 then
			If FmtFelt61 > 4 then FmtFelt61 = 0
			If FmtFelt71 > 4 then FmtFelt71 = 0
			If FmtFelt8B1 > 4 then FmtFelt8B1 = 0
			Result1 = FmtFelt61 + FmtFelt71 + FmtFelt8B1
		else
			Result1 = 0
			Form.getByName("fmtC1Total").text = Result1
		end if
		If Len(FmtFelt62) = 1 and Len(FmtFelt72) = 1 and Len(FmtFelt8B2) = 1 then
			If FmtFelt62 > 4 then FmtFelt62 = 0
			If FmtFelt72 > 4 then FmtFelt72 = 0
			If FmtFelt8B2 > 4 then FmtFelt8B2 = 0
			Result2 = FmtFelt62 + FmtFelt72 + FmtFelt8B2
		else
			Result2 = 0
			Form.getByName("fmtC2Total").text = Result2
		end if
		'C Indsæt resultat
		Form.getByName("fmtC1Total").text = Result1
		Form.getByName("fmtC2Total").text = Result2
	'--------------------------------------------------------------------------------------
	'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
	'--------------------------------------------------------------------------------------
		'D Dimensions
		Dim FmtFelt91 as Integer, FmtFelt92 as Integer
		Dim FmtFelt101 as Integer, FmtFelt102 as Integer
		Dim FmtFelt111 as Integer, FmtFelt112 as Integer
		Dim FmtFelt121 as Integer, FmtFelt122 as Integer
		'D Henter Data fra formular
		FmtFelt91 = Form.getByName("FmtFelt91_H").text
		FmtFelt92 = Form.getByName("FmtFelt92_H").text
		FmtFelt101 = Form.getByName("FmtFelt101_H").text
		FmtFelt102 = Form.getByName("FmtFelt102_H").text
		FmtFelt111 = Form.getByName("FmtFelt111_H").text
		FmtFelt112 = Form.getByName("FmtFelt112_H").text
		FmtFelt121 = Form.getByName("FmtFelt121_H").text
		FmtFelt122 = Form.getByName("FmtFelt122_H").text
		'D Kontrollér data
		If Len(FmtFelt91) = 1 and Len(FmtFelt101) = 1 and Len(FmtFelt111) = 1 and Len(FmtFelt121) = 1 then
			If FmtFelt91 > 4 then FmtFelt91 = 0
			If FmtFelt101 > 4 then FmtFelt101 = 0
			If FmtFelt111 > 4 then FmtFelt111 = 0
			If FmtFelt121 > 4 then FmtFelt121 = 0
			Result1 = FmtFelt91 + FmtFelt101 + FmtFelt111 + FmtFelt121
		else
			Result1 = 0
			Form.getByName("fmtD1Total").text = Result1
		end if
		If Len(FmtFelt92) = 1 and Len(FmtFelt102) = 1 and Len(FmtFelt112) = 1 and Len(FmtFelt122) = 1 then
			If FmtFelt92 > 4 then FmtFelt92 = 0
			If FmtFelt102 > 4 then FmtFelt102 = 0
			If FmtFelt112 > 4 then FmtFelt112 = 0
			If FmtFelt122 > 4 then FmtFelt122 = 0
			Result2 = FmtFelt92 + FmtFelt102 + FmtFelt112 + FmtFelt122
		else
			Result2 = 0
			Form.getByName("fmtD2Total").text = Result2
		end if
		'D Indsæt resultat
		Form.getByName("fmtD1Total").text = Result1
		Form.getByName("fmtD2Total").text = Result2
	'--------------------------------------------------------------------------------------
	'Beregn gennemsnit
	'--------------------------------------------------------------------------------------
		Dim fmtA1Total as Integer, fmtB1Total as Integer, fmtC1Total as Integer, fmtD1Total as Integer
		Dim fmtA2Total as Integer, fmtB2Total as Integer, fmtC2Total as Integer, fmtD2Total as Integer
		Dim Avg1 as Single, Avg2 as Single
		'Hent Data fra formular
		fmtA1Total = Form.getByName("fmtA1Total").text
		fmtA2Total = Form.getByName("fmtA2Total").text
		fmtB1Total = Form.getByName("fmtB1Total").text
		fmtB2Total = Form.getByName("fmtB2Total").text
		fmtC1Total = Form.getByName("fmtC1Total").text
		fmtC2Total = Form.getByName("fmtC2Total").text
		fmtD1Total = Form.getByName("fmtD1Total").text
		fmtD2Total = Form.getByName("fmtD2Total").text
		'Kontrollér data
		If Len(fmtA1Total) > 0 and Len(fmtB1Total) > 0 and Len(fmtC1Total) > 0 and Len(fmtD1Total) > 0 then
			Avg1 = (fmtA1Total + fmtB1Total + fmtC1Total + fmtD1Total) / 4
		else
			Avg1 = 0
			Form.getByName("fmtTestGnsn1").text = Avg1
		end if
		If Len(fmtA2Total) > 0 and Len(fmtB2Total) > 0 and Len(fmtC2Total) > 0 and Len(fmtD2Total) > 0 then
			Avg2 = (fmtA2Total + fmtB2Total + fmtC2Total + fmtD2Total) / 4
		else
			Avg2 = 0
			Form.getByName("fmtTestGnsn2").text = Avg2
		end if
		Form.getByName("fmtTestGnsn1").text = Avg1
		Form.getByName("fmtTestGnsn2").text = Avg2
End Sub

Besvar

Hvem er online

Brugere der viser dette forum: Ingen og 2 gæster