26. juni 2017 - 08:05Der er
8 kommentarer og 1 løsning
Hente flere variable med Call
Jeg har en function med navnet "Function FindDimension()", hvor jeg skal overføre nogle variable til en Private Sub som kører fra en UserForm. Jeg bruger Call FindDimension, men skal bruge nogle variable fra Finddimension(). Hvordan får jeg dem over.
Hej Det virker men jeg vil helt ikke lave publiv variable, da der er en del forskellige Macroer i dokumentet og der bliver svært at holde styr på hvor de forskellige variable er brugt
'UserForm_Bjælkespær.Hide Function FindDimension()
'Dim L As Double Dim u As Double Dim r As Double
L = TextBox1.Value
' Taglast
Dim ctrl As control
For Each ctrl In Frame1.Controls If TypeOf ctrl Is MSForms.OptionButton Then If ctrl.Value = True Then Select Case ctrl.Caption Case Is = "Let tag: 0,25 kNm2" tabel = 1 Taglast = "Let tag: 0,25 kNm2" Case Is = "Tungt tag: 0,55 kNm2" tabel = 2 Taglast = "Tungt tag: 0,55 kNm2" Case Else
End Select
End If End If Next ctrl
' Styrkeklasse For Each ctrl In Frame2.Controls If TypeOf ctrl Is MSForms.OptionButton Then If ctrl.Value = True Then
Select Case ctrl.Caption Case Is = "C14" su = 0.88 sf = 0.88 Case Is = "C18" su = 1 sf = 1 Case Is = "C24" su = 1.08 sf = 1.15 Case Is = "C30" su = 1.15 sf = 1.29 Case Else
End Select
End If End If Next ctrl
' taghældning For Each ctrl In Frame3.Controls If TypeOf ctrl Is MSForms.OptionButton Then If ctrl.Value = True Then
Select Case ctrl.Caption Case Is = "15 grader" ru = 1 rf = 1 Case Is = "20 grader" ru = 0.97 rf = 0.98 Case Is = "25 grader" ru = 0.94 rf = 0.95 Case Is = "30 grader" ru = 0.89 rf = 0.92 Case Else
End Select
End If End If Next ctrl
' bjælkeafstand For Each ctrl In Frame4.Controls If TypeOf ctrl Is MSForms.OptionButton Then If ctrl.Value = True Then
Select Case ctrl.Caption Case Is = "0,40 m" række = 1 Case Is = "0,60 m" række = 2 Case Is = "0,80 m" række = 3 Case Is = "1,00 m" række = 4 Case Is = "1,20 m" række = 5 Case Else
End Select
End If End If Next ctrl
' bjælkebredde For Each ctrl In Frame5.Controls If TypeOf ctrl Is MSForms.OptionButton Then If ctrl.Value = True Then
Select Case ctrl.Caption Case Is = "45 mm" b = 45 Case Is = "70 mm" b = 70 Case Is = "95 mm" b = 95 Case Else
End Select
End If End If Next ctrl
'Beregning
u = ru * su f = rf * ru
Select Case tabel Case Is = 1 Select Case række Case Is = 1 Select Case b Case Is = 45
If L < 5.62 * u And L < 7.64 * f Then H = 245 If L < 5.07 * u And L < 6.88 * f Then H = 220 If L < 4.52 * u And L < 6.12 * f Then H = 195 If L < 3.96 * u And L < 5.34 * f Then H = 170 If L < 3.39 * u And L < 4.56 * f Then H = 145 If L < 2.81 * u And L < 3.77 * f Then H = 120
Case Is = 70
If L < 6.28 * u And L < 9.35 * f Then H = 245 If L < 5.69 * u And L < 8.44 * f Then H = 220 If L < 5.09 * u And L < 7.51 * f Then H = 195 If L < 4.47 * u And L < 6.58 * f Then H = 170 If L < 3.84 * u And L < 5.63 * f Then H = 145
Case Is = 95
If L < 6.73 * u And L < 10.67 * f Then H = 245 If L < 6.11 * u And L < 9.65 * f Then H = 220 If L < 5.48 * u And L < 8.62 * f Then H = 195 If L < 4.83 * u And L < 7.56 * f Then H = 170 If L < 4.17 * u And L < 6.49 * f Then H = 145
End Select
Case Is = 2 Select Case b Case Is = 45
If L < 5.02 * u And L < 6.31 * f Then H = 245 If L < 4.52 * u And L < 5.67 * f Then H = 220 If L < 4.02 * u And L < 5.03 * f Then H = 195 If L < 3.51 * u And L < 4.39 * f Then H = 170 If L < 3# * u And L < 3.74 * f Then H = 145 If L < 2.48 * u And L < 3.09 * f Then H = 120
Case Is = 70
If L < 5.67 * u And L < 7.77 * f Then H = 245 If L < 5.12 * u And L < 7# * f Then H = 220 If L < 4.57 * u And L < 6.22 * f Then H = 195 If L < 4# * u And L < 5.44 * f Then H = 170 If L < 3.43 * u And L < 4.64 * f Then H = 145
Case Is = 95
If L < 6.13 * u And L < 8.94 * f Then H = 245 If L < 5.33 * u And L < 8.06 * f Then H = 220 If L < 4.96 * u And L < 7.18 * f Then H = 195 If L < 4.35 * u And L < 6.28 * f Then H = 170 If L < 3.74 * u And L < 5.37 * f Then H = 145
End Select
Case Is = 3 Select Case b Case Is = 45
If L < 4.62 * u And L < 5.49 * f Then H = 245 If L < 4.15 * u And L < 4.93 * f Then H = 220 If L < 3.68 * u And L < 4.37 * f Then H = 195 If L < 3.21 * u And L < 3.81 * f Then H = 170 If L < 2.74 * u And L < 3.24 * f Then H = 145 If L < 2.26 * u And L < 2.67 * f Then H = 120
Case Is = 70
If L < 5.25 * u And L < 6.79 * f Then H = 245 If L < 4.73 * u And L < 6.11 * f Then H = 220 If L < 4.21 * u And L < 5.42 * f Then H = 195 If L < 3.68 * u And L < 4.73 * f Then H = 170 If L < 3.14 * u And L < 4.03 * f Then H = 145
Case Is = 95
If L < 5.7 * u And L < 7.84 * f Then H = 245 If L < 5.15 * u And L < 7.06 * f Then H = 220 If L < 4.59 * u And L < 6.27 * f Then H = 195 If L < 4.02 * u And L < 5.48 * f Then H = 170 If L < 3.44 * u And L < 4.68 * f Then H = 145
End Select
Case Is = 4 Select Case b Case Is = 45
If L < 4.31 * u And L < 4.92 * f Then H = 245 If L < 3.88 * u And L < 4.42 * f Then H = 220 If L < 3.44 * u And L < 3.91 * f Then H = 195 If L < 2.99 * u And L < 3.4 * f Then H = 170 If L < 2.55 * u And L < 2.89 * f Then H = 145 If L < 2.1 * u And L < 2.38 * f Then H = 120
Case Is = 70
If L < 4.92 * u And L < 6.11 * f Then H = 245 If L < 4.43 * u And L < 5.49 * f Then H = 220 If L < 3.94 * u And L < 4.87 * f Then H = 195 If L < 3.44 * u And L < 4.24 * f Then H = 170 If L < 2.93 * u And L < 3.61 * f Then H = 145
Case Is = 95
If L < 5.37 * u And L < 7.06 * f Then H = 245 If L < 4.84 * u And L < 6.35 * f Then H = 220 If L < 4.31 * u And L < 5.64 * f Then H = 195 If L < 3.77 * u And L < 4.92 * f Then H = 170 If L < 3.22 * u And L < 4.2 * f Then H = 145
End Select
Case Is = 5 Select Case b Case Is = 45
If L < 4.08 * u And L < 4.5 * f Then H = 245 If L < 3.66 * u And L < 4.04 * f Then H = 220 If L < 3.24 * u And L < 3.57 * f Then H = 195 If L < 2.82 * u And L < 3.1 * f Then H = 170 If L < 2.4 * u And L < 2.64 * f Then H = 145 If L < 1.98 * u And L < 2.17 * f Then H = 120
Case Is = 70
If L < 4.67 * u And L < 5.59 * f Then H = 245 If L < 4.2 * u And L < 5.02 * f Then H = 220 If L < 3.73 * u And L < 4.45 * f Then H = 195 If L < 3.25 * u And L < 3.87 * f Then H = 170 If L < 2.77 * u And L < 3.3 * f Then H = 145
Case Is = 95
If L < 5.1 * u And L < 6.48 * f Then H = 245 If L < 4.6 * u And L < 5.82 * f Then H = 220 If L < 4.09 * u And L < 5.17 * f Then H = 195 If L < 3.57 * u And L < 4.51 * f Then H = 170 If L < 3.05 * u And L < 3.84 * f Then H = 145
End Select
End Select
Case Is = 2 Select Case række Case Is = 1 Select Case b Case Is = 45
If L < 4.93 * u And L < 7.03 * f Then H = 245 If L < 4.44 * u And L < 6.33 * f Then H = 220 If L < 3.94 * u And L < 5.62 * f Then H = 195 If L < 3.44 * u And L < 4.9 * f Then H = 170 If L < 2.94 * u And L < 4.18 * f Then H = 145 If L < 2.43 * u And L < 3.46 * f Then H = 120
Case Is = 70
If L < 5.58 * u And L < 8.63 * f Then H = 245 If L < 5.03 * u And L < 7.78 * f Then H = 220 If L < 4.48 * u And L < 6.92 * f Then H = 195 If L < 3.93 * u And L < 6.06 * f Then H = 170 If L < 3.36 * u And L < 5.18 * f Then H = 145
Case Is = 95
If L < 6.03 * u And L < 9.89 * f Then H = 245 If L < 5.46 * u And L < 8.93 * f Then H = 220 If L < 4.87 * u And L < 7.96 * f Then H = 195 If L < 4.28 * u And L < 6.98 * f Then H = 170 If L < 3.67 * u And L < 5.98 * f Then H = 145
End Select
Case Is = 2 Select Case b Case Is = 45
If L < 4.37 * u And L < 5.79 * f Then H = 245 If L < 3.93 * u And L < 5.2 * f Then H = 220 If L < 3.48 * u And L < 4.61 * f Then H = 195 If L < 3.03 * u And L < 4.02 * f Then H = 170 If L < 2.58 * u And L < 3.42 * f Then H = 145 If L < 2.13 * u And L < 2.82 * f Then H = 120
Case Is = 70
If L < 4.98 * u And L < 7.16 * f Then H = 245 If L < 4.49 * u And L < 6.44 * f Then H = 220 If L < 3.99 * u And L < 5.72 * f Then H = 195 If L < 3.48 * u And L < 4.99 * f Then H = 170 If L < 2.97 * u And L < 4.26 * f Then H = 145
Case Is = 95
If L < 5.43 * u And L < 8.25 * f Then H = 245 If L < 4.9 * u And L < 7.43 * f Then H = 220 If L < 4.36 * u And L < 6.61 * f Then H = 195 If L < 3.82 * u And L < 5.78 * f Then H = 170 If L < 3.26 * u And L < 4.94 * f Then H = 145
End Select
Case Is = 3 Select Case b Case Is = 45
If L < 3.99 * u And L < 5.03 * f Then H = 245 If L < 3.59 * u And L < 4.52 * f Then H = 220 If L < 3.18 * u And L < 4 * f Then H = 195 If L < 2.76 * u And L < 3.48 * f Then H = 170 If L < 2.35 * u And L < 2.96 * f Then H = 145 If L < 1.93 * u And L < 2.44 * f Then H = 120
Case Is = 70
If L < 4.58 * u And L < 6.24 * f Then H = 245 If L < 4.12 * u And L < 5.61 * f Then H = 220 If L < 3.65 * u And L < 4.97 * f Then H = 195 If L < 3.18 * u And L < 4.34 * f Then H = 170 If L < 2.71 * u And L < 3.7 * f Then H = 145
Case Is = 95
If L < 5.01 * u And L < 7.21 * f Then H = 245 If L < 4.51 * u And L < 6.49 * f Then H = 220 If L < 4.01 * u And L < 5.77 * f Then H = 195 If L < 3.5 * u And L < 5.03 * f Then H = 170 If L < 2.99 * u And L < 4.3 * f Then H = 145
End Select
Case Is = 4 Select Case b Case Is = 45
If L < 3.72 * u And L < 4.51 * f Then H = 245 If L < 3.34 * u And L < 4.04 * f Then H = 220 If L < 2.95 * u And L < 3.58 * f Then H = 195 If L < 2.57 * u And L < 3.11 * f Then H = 170 If L < 2.18 * u And L < 2.64 * f Then H = 145 If L < 1.79 * u And L < 2.17 * f Then H = 120
Case Is = 70
If L < 4.28 * u And L < 5.6 * f Then H = 245 If L < 3.84 * u And L < 5.03 * f Then H = 220 If L < 3.41 * u And L < 4.46 * f Then H = 195 If L < 2.97 * u And L < 3.88 * f Then H = 170 If L < 2.52 * u And L < 3.31 * f Then H = 145
Case Is = 95
If L < 5.37 * u And L < 4.69 * f Then H = 245 If L < 4.84 * u And L < 4.22 * f Then H = 220 If L < 4.31 * u And L < 3.75 * f Then H = 195 If L < 3.77 * u And L < 3.27 * f Then H = 170 If L < 3.22 * u And L < 2.79 * f Then H = 145
End Select
Case Is = 5 Select Case b Case Is = 45
If L < 3.51 * u And L < 4.12 * f Then H = 245 If L < 3.15 * u And L < 3.69 * f Then H = 220 If L < 2.78 * u And L < 3.27 * f Then H = 195 If L < 2.42 * u And L < 2.84 * f Then H = 170 If L < 2.05 * u And L < 2.41 * f Then H = 145 If L < 1.68 * u And L < 1.98 * f Then H = 120
Case Is = 70
If L < 4.04 * u And L < 5.12 * f Then H = 245 If L < 3.63 * u And L < 4.6 * f Then H = 220 If L < 3.21 * u And L < 4.07 * f Then H = 195 If L < 2.8 * u And L < 3.55 * f Then H = 170 If L < 2.38 * u And L < 3.02 * f Then H = 145
Case Is = 95
If L < 4.44 * u And L < 5.95 * f Then H = 245 If L < 3.99 * u And L < 5.34 * f Then H = 220 If L < 3.54 * u And L < 4.74 * f Then H = 195 If L < 3.09 * u And L < 4.13 * f Then H = 170 If L < 2.63 * u And L < 3.52 * f Then H = 145
End Select
End Select
End Select
If H <> "" Then TextBox2.Value = b & " x " & H & "mm" Else TextBox2 = "Dimension ikke fundet" End If
End Function
Private Sub CommandButton2_Click()
Call FindDimension UserForm_Bjælkespær.Hide
Selection.Style = ActiveDocument.Styles("Overskrift 3") Selection.TypeText Text:="Bjælkespær" Selection.TypeParagraph Selection.TypeText Text:="Bjælkespæret er valgt ud fra ´Træ 58 - Træspær 2 tabel 2´." Selection.TypeParagraph Selection.TypeText Text:="Forudsætninger:" Selection.TypeParagraph Selection.TypeText Text:=L ' Selection.TypeText Text:=FindDimension(b.Value)
ej testet det må være noget i den stil hvis din kode ikke skal laves helt om. Jan
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.