qqcreafis
| Inviato il: 31/01/2015 00:26:19
|
CITAZIONE
Sub Main()
Dim Doc As Object
Dim Sheet As Object
Dim Cell As Object
Dim psi(999, 9999) As Double ' matricetempo lunghezza
Dim Rho As Double ' densità fluido
Dim V0 As Double ' velocità iniziale colonna
Dim deltat As Double ' intervallo di tempo
Dim N As Integer ' numero di interazioni tra due visualizzazioni
Dim tot As Double 'tempo totale simulazione
Dim tintermedio As Double 'tempo N*deltat
Dim ltot As Double ' lunghezza ariete
Dim L0 As Double ' distanza tra segmenti L0=ltot/10000
Dim B As Double ' compressibilità
Dim Vfase As Double ' velocità sperimentale
Dim D As Double ' diametro ariete
Dim P As Double ' pressione contraria
Dim F As Double ' forza contraria
Dim A As Double ' area sezione
Dim I, J, K As Integer ' contatori
'Valori
'Rho=1000 'densità kg/m^3
'ltot = 2 'lunghezza ariete metri
'Vfase = 30 'velocita fase onda sperimentale m/s
'V0 = 5.5 'velocità ariete m/s
Doc = StarDesktop.CurrentComponent
Sheet = Doc.Sheets(0)
Cell = Sheet.getCellByPosition(0, 1)
Rho = Cell.Value
Cell = Sheet.getCellByPosition(2, 1)
Vfase = Cell.Value
Cell = Sheet.getCellByPosition(4, 1)
V0 = Cell.Value
Cell = Sheet.getCellByPosition(6, 1)
ltot = Cell.Value
Cell = Sheet.getCellByPosition(7, 1)
D = Cell.Value
Cell = Sheet.getCellByPosition(9, 1)
deltat = Cell.Value
Cell = Sheet.getCellByPosition(10, 1)
N = Cell.Value
Cell = Sheet.getCellByPosition(11, 1)
P = Cell.Value
A = 3.14 * D ^ 2 / 4
F = P * A
Cell = Sheet.getCellByPosition(15, 1)
Cell.Value = F
tot = deltat * N * 999
Cell = Sheet.getCellByPosition(12, 1)
Cell.Value = tot
B = Vfase * Vfase * Rho
Cell = Sheet.getCellByPosition(14, 1)
Cell.Value = B
L0 = ltot / 10000
Cell = Sheet.getCellByPosition(13, 1)
Cell.Value = L0
'inizializzazione
Cell = Sheet.getCellByPosition(3, 3)
Cell.String = "inizio"
psi(0, 0) = 0
For I = 1 To 9999
psi(0, I) = L0 + psi(0, I - 1)
Next I
'primo spostamento V0*deltat +psi precedente
For I = 0 To 9999
psi(1, I) = psi(0, I) - V0 * deltat
Next I
For J = 2 To 999
psi(J, 0) = 2 * psi(J - 1, 0) - psi(J - 2, 0) + 1 / Rho * (deltat / L0) ^ 2 * (P * L0 + B * (psi(J - 1, 1) - psi(J - 1, 0) - L0))
For I = 1 To 9998
psi(J, I) = 2 * psi(J - 1, I) - psi(J - 2, I) + B / Rho * (deltat / L0) ^ 2 * (psi(J - 1, I + 1) - 2 * psi(J - 1, I) + psi(J - 1, I - 1))
Next I
psi(J, 9999) = 2 * psi(J - 1, 9999) - psi(J - 2, 9999) + B / Rho * (deltat / L0) ^ 2 * (psi(J - 1, 9999) - psi(J - 1, 9998) - L0)
Cell = Sheet.getCellByPosition(5, 6)
Cell.Value = J
Cell = Sheet.getCellByPosition(J, 10)
Cell.Value = psi(J, 0)
'Cell = Sheet.getCellByPosition(j,11)
'Cell.Value =psi(j,1)
'Cell = Sheet.getCellByPosition(j,12)
'Cell.Value =psi(j,2)
'Cell = Sheet.getCellByPosition(j,13)
'Cell.Value =psi(j,3)
Next J
For I = 0 To 999
Cell = Sheet.getCellByPosition(I, 10)
Cell.Value = psi(I, 0)
Next I
'Cell = Sheet.getCellByPosition(5, 5)
'Cell.String = "o"
'for I=0 to 9999
'Cell = Sheet.getCellByPosition(0, I+10)
'Cell.Value =psi(0,I)
'next I
'for I=0 to 9999
'Cell = Sheet.getCellByPosition(1, I+10)
'Cell.Value =psi(1,I)
'next I
'for I=0 to 9999
'Cell = Sheet.getCellByPosition(2, I+10)
'Cell.Value =psi(2,I)
'next I
Cell = Sheet.getCellByPosition(6, 6)
Cell.String = "fine"
'Doc = StarDesktop.CurrentComponent
'Sheet = Doc.Sheets(0)
'Cell = Sheet.getCellByPosition(2, 0)
'Cell.String = "Test"
MsgBox Cell.Value
End Sub
è in basic di open office calc e si interfaccia con un foglio cal ma... è pietosamente lento mi alloca 1,5 GB di memoria insomma non va
le macro di vba in excel vanno meglio si possono compilare?
come si fa a leggere le celle di un foglio in vba e a scriverle????????
Modificato da qqcreafis - 31/01/2015, 00:31:50
--------------- ODE AD UNO STUDENTE MERITEVOLE (Sermone)
Allora Xyz è stato bravo! noi dobbiamo riconoscere ...
|