2017-04-09 2 views
0

Aktualisierter BeitragWie deklariert man Variablen innerhalb der Excel-Funktion?

Ich habe den Code wie geändert.

Option Explicit 
Public Function Isokinectic(streamVelocity As Double, sampleVelocity As Double, probeDiameter As Double, density As Double, particleDiameter As Double, viscosity As Double) 

     Dim s As Double 
     Dim stk_coefficent As Double 
     Dim stk As Double 
     Dim d As Double 

     s = ((0.16 * 10^-4)/particleDiameter) + 1 
     stk_coefficent = (1/(18 * viscosity)) * density * particleDiameter * particleDiameter * s 
     stk = (streamVelocity/probeDiameter) * stk_coefficent 
     d = 1 + (2 + 0.62 * (sampleVelocity/streamVelocity)) * stk 
     Isokinectic = 1 + ((streamVelocity/sampleVelocity) - 1) * (1 - 1/(d)) 

End Function 

Aber es funktioniert nicht. Wenn Sie jedoch den Unterbefehl MAIN() hinzufügen, so. Es klappt.

Option Explicit 
Function Isokinectic(streamVelocity As Double, sampleVelocity As Double, probeDiameter As Double, density As Double, particleDiameter As Double, viscosity As Double) 

     Dim s As Double 
     Dim stk_coefficent As Double 
     Dim stk As Double 
     Dim d As Double 

     s = ((0.16 * 10^-4)/particleDiameter) + 1 
     stk_coefficent = (1/(18 * viscosity)) * density * particleDiameter * particleDiameter * s 
     stk = (streamVelocity/probeDiameter) * stk_coefficent 
     d = 1 + (2 + 0.62 * (sampleVelocity/streamVelocity)) * stk 
     Isokinectic = 1 + ((streamVelocity/sampleVelocity) - 1) * (1 - 1/(d)) 

End Function 

Sub MAIN() 
    MsgBox Isokinectic(0.1, 0.2, 0.3, 0.4, 0.5, 0.6) 
End Sub 

Original-Beitrag:

Ich habe versucht, eine Gleichung in Excel-Funktion zu codieren. Aber ich habe #value

Function Isokinectic(streamVelocity As Double, sampleVelocity As Double, probeDiameter As Double, density As Double, particleDiamter As Double, visocity As Double) 

     Dim s As Double 
     Dim stk_coefficent As Double 
     Dim stk As Double 
     Dim d As Double 

     s = (0.16 * 10^ - 4/particleDiameter) + 1 

     stk_coefficent = (1/(18 * viscosity)) * density * particleDiamter * particleDiameter * s 

     stk = (streamVelocity/probeDiameter) * stk_coefficent 

     d = 1 + (2 + 0.62 * (sampleVelocity/streamVelocity)) * stk 

     Isokinectic = 1 + ((streamVelocity/sampleVelocity) - 1) * (1 - 1/(1 + d)) 

     End Function 

Alles, was ich in diesem Code falsch gemacht?

+0

Es läuft gut für mich. Wie nennst du es?> –

+0

Funktion einfügen. Dann tippe die Variablen ein. – JOHN

+0

Typo in der Kopfzeile *** particleDiamenter *** ist nicht *** particleDiameter *** Es kann andere Probleme geben –

Antwort

0

Mit einer wenig Bereinigung:

Option Explicit 
Function Isokinectic(streamVelocity As Double, sampleVelocity As Double, probeDiameter As Double, density As Double, particleDiameter As Double, viscosity As Double) 

     Dim s As Double 
     Dim stk_coefficent As Double 
     Dim stk As Double 
     Dim d As Double 

     s = ((0.16 * 10^-4)/particleDiameter) + 1 
     stk_coefficent = (1/(18 * viscosity)) * density * particleDiameter * particleDiameter * s 
     stk = (streamVelocity/probeDiameter) * stk_coefficent 
     d = 1 + (2 + 0.62 * (sampleVelocity/streamVelocity)) * stk 
     Isokinectic = 1 + ((streamVelocity/sampleVelocity) - 1) * (1 - 1/(1 + d)) 

End Function 

Sub MAIN() 
    MsgBox Isokinectic(0.1, 0.2, 0.3, 0.4, 0.5, 0.6) 
End Sub 

enter image description here

+0

Vielen Dank! Es klappt! Aber wenn ich den sub MAIN() Teil entfernen. Und Typ = Isokinektikum(), es wird nicht funktionieren. Warum das? – JOHN

+0

ist es # Wert. LOL – JOHN

+1

Es funktioniert jetzt. Es scheint, dass ich das Modul in das VBA-Projekt einfügen muss. Nicht das Blatt. – JOHN

0

In Ihrem Original-Beitrag von Ihnen s berechnet, d, stk aber in keinem wo in späterem Zeitpunkt Sie den Wert für die Geschwindigkeit bekommen & andere, ist Grund für den Wert Fehler. Da mit einer Unterroutine, wie Sie Value in Formel setzen, es funktioniert, schreiben Sie bitte diese Befehlszeile in Funktion Ihre Funktion wird funktionieren, vergessen Sie nicht, Wert für Velocity aus Zellen zu übergeben.

Verwandte Themen