agmorgan
Mar 2nd, 2004, 10:25 AM
Im having a rough day and turned out this piece of crap.
Basically its quite repetitive.
Anyone fancy coding it better for me?
Please bear in mind that I will be modifying it later to VBScript.
e.g. For the drop down list boxes.Text wil become .value Unless you want to do the conversion as well?
How generous are you feeling? ;)
I have attached the form, because it is too long to paste the code.
Jmacp
Mar 8th, 2004, 07:19 PM
Option Explicit
Option Base 1
Private Sub Command1_Click()
Call Testing
End Sub
'Function SetupFrm3_onSubmit()
Function Testing() As Variant
Dim ANAmin As Double
Dim ANAmax As Double
'AgM 10-07-2002
ANAmin = CDbl(0.045)
ANAmax = CDbl(26.5)
Dim dblFreqs() As Double
ReDim dblFreqs(3, 1)
If Not (IsNumeric(fsta1)) Or Not (IsNumeric(fsto1)) Or Not (IsNumeric(fste1)) Then
' SetupFrm3_onSubmit = False
' alert "You must enter numeric values"
MsgBox "You must enter numeric values"
Exit Function
End If
dblFreqs(1, 1) = setupfrm3.fsta1.Text
dblFreqs(2, 1) = setupfrm3.fsto1.Text
dblFreqs(3, 1) = setupfrm3.fste1.Text
If CInt(setupfrm3.cboFreq.Text) > 1 Then
If Not (IsNumeric(fsta2)) Or Not (IsNumeric(fsto2)) Or Not (IsNumeric(fste2)) Then
' SetupFrm3_onSubmit = False
' alert "You must enter numeric values"
MsgBox "You must enter numeric values"
Exit Function
End If
ReDim Preserve dblFreqs(3, 2)
dblFreqs(1, 2) = setupfrm3.fsta2.Text
dblFreqs(2, 2) = setupfrm3.fsto2.Text
dblFreqs(3, 2) = setupfrm3.fste2.Text
End If
If CInt(setupfrm3.cboFreq.Text) > 2 Then
If Not (IsNumeric(fsta3)) Or Not (IsNumeric(fsto3)) Or Not (IsNumeric(fste3)) Then
' SetupFrm3_onSubmit = False
' alert "You must enter numeric values"
MsgBox "You must enter numeric values"
Exit Function
End If
ReDim Preserve dblFreqs(3, 3)
dblFreqs(1, 3) = setupfrm3.fsta3.Text
dblFreqs(2, 3) = setupfrm3.fsto3.Text
dblFreqs(3, 3) = setupfrm3.fste3.Text
End If
Dim stafreq As Double
Dim stofreq As Double
stafreq = CDbl(0.04)
stofreq = CDbl(18)
If dblFreqs(1, 1) < stafreq Or dblFreqs(1, 1) > stofreq Then
' SetupFrm3_onSubmit = False
' alert "You have entered an invalid start frequency of " + fsta + " GHz"
MsgBox "You have entered an invalid start frequency of " + fsta1 + " GHz"
setupfrm3.fsta1.Text = stafreq
Exit Function
ElseIf dblFreqs(2, 1) < stafreq Or dblFreqs(2, 1) > stofreq Then
' SetupFrm3_onSubmit = False
' alert "You have entered an invalid stop frequency of " + fsto + " GHz"
MsgBox "You have entered an invalid stop frequency of " + fsto1 + " GHz"
setupfrm3.fsto1.Text = stofreq
Exit Function
ElseIf dblFreqs(2, 1) < dblFreqs(1, 1) Then
' SetupFrm3_onSubmit = False
' alert "You have entered an invalid frequency range"
MsgBox "You have entered an invalid frequency range"
setupfrm3.fsta1.Text = stafreq
setupfrm3.fsto1.Text = stofreq
Exit Function
End If
'Check frequencies dont conflict with ANA range AgM 10-07-2002
If dblFreqs(1, 1) < ANAmin Or dblFreqs(1, 1) > ANAmax Then
' SetupFrm3_onSubmit = False
' alert "You have entered a start frequency outside the range of the ANA"
MsgBox "You have entered a start frequency outside the range of the ANA"
setupfrm3.fsta1.Text = stafreq
Exit Function
ElseIf dblFreqs(2, 1) > ANAmax Or dblFreqs(2, 1) < ANAmin Then
' SetupFrm3_onSubmit = False
' alert "You have entered a stop frequency outside the range of the ANA"
MsgBox "You have entered a stop frequency outside the range of the ANA"
setupfrm3.fsto1.Text = stofreq
Exit Function
End If
'Check for valid step intervals
If dblFreqs(1, 1) = dblFreqs(2, 1) And dblFreqs(3, 1) <> 0 Then
' alert "Start and Stop frequencies identical" + Chr(13) + Chr(10) + "Step size set to 0.0 GHz, please check."
MsgBox "Start and Stop frequencies identical" + Chr(13) + Chr(10) + "Step size set to 0.0 GHz, please check."
setupfrm3.fste1.Text = 0#
' SetupFrm3_onSubmit = False
Exit Function
ElseIf dblFreqs(1, 1) <> dblFreqs(2, 1) And dblFreqs(3, 1) = 0 Then
' alert "You have entered an invalid step size."
MsgBox "You have entered an invalid step size."
setupfrm3.fste1.Text = "##.##"
' SetupFrm3_onSubmit = False
Exit Function
ElseIf dblFreqs(1, 1) = dblFreqs(2, 1) And dblFreqs(3, 1) = 0 Then
' SetupFrm3_onSubmit = True
Exit Function
End If
Dim newstop As Double
newstop = CDbl(CStr(CInt((dblFreqs(2, 1) - dblFreqs(1, 1)) / dblFreqs(3, 1)) * dblFreqs(3, 1) + dblFreqs(1, 1)))
If newstop <> dblFreqs(2, 1) Then
setupfrm3.fsto1.Text = newstop
' alert "Step size did not divide frequency range equally." + Chr(13) + Chr(10) + "Stop frequency changed, please check"
MsgBox "Step size did not divide frequency range equally." + Chr(13) + Chr(10) + "Stop frequency changed, please check"
' SetupFrm3_onSubmit = False
Exit Function
End If
'Frequency 2
If dblFreqs(1, 2) < stafreq Or dblFreqs(1, 2) > stofreq Then
' SetupFrm3_onSubmit = False
' alert "You have entered an invalid start frequency of " + fsta + " GHz"
MsgBox "You have entered an invalid start frequency of " + fsta1 + " GHz"
setupfrm3.fsta2.Text = stafreq
Exit Function
ElseIf dblFreqs(2, 2) < stafreq Or dblFreqs(2, 2) > stofreq Then
' SetupFrm3_onSubmit = False
' alert "You have entered an invalid stop frequency of " + fsto + " GHz"
MsgBox "You have entered an invalid stop frequency of " + fsto1 + " GHz"
setupfrm3.fsto2.Text = stofreq
Exit Function
ElseIf dblFreqs(2, 2) < dblFreqs(1, 2) Then
' SetupFrm3_onSubmit = False
' alert "You have entered an invalid frequency range"
MsgBox "You have entered an invalid frequency range"
setupfrm3.fsta2.Text = stafreq
setupfrm3.fsto2.Text = stofreq
Exit Function
End If
'Check frequencies dont conflict with ANA range AgM 10-07-2002
If dblFreqs(1, 2) < ANAmin Or dblFreqs(1, 2) > ANAmax Then
' SetupFrm3_onSubmit = False
' alert "You have entered a start frequency outside the range of the ANA"
MsgBox "You have entered a start frequency outside the range of the ANA"
setupfrm3.fsta2.Text = stafreq
Exit Function
ElseIf dblFreqs(2, 2) > ANAmax Or dblFreqs(2, 2) < ANAmin Then
' SetupFrm3_onSubmit = False
' alert "You have entered a stop frequency outside the range of the ANA"
MsgBox "You have entered a stop frequency outside the range of the ANA"
setupfrm3.fsto2.Text = stofreq
Exit Function
End If
'Check for valid step intervals
If dblFreqs(1, 2) = dblFreqs(2, 2) And dblFreqs(3, 2) <> 0 Then
' alert "Start and Stop frequencies identical" + Chr(13) + Chr(10) + "Step size set to 0.0 GHz, please check."
MsgBox "Start and Stop frequencies identical" + Chr(13) + Chr(10) + "Step size set to 0.0 GHz, please check."
setupfrm3.fste2.Text = 0#
' SetupFrm3_onSubmit = False
Exit Function
ElseIf dblFreqs(1, 2) <> dblFreqs(2, 2) And dblFreqs(3, 2) = 0 Then
' alert "You have entered an invalid step size."
MsgBox "You have entered an invalid step size."
setupfrm3.fste2.Text = "##.##"
' SetupFrm3_onSubmit = False
Exit Function
ElseIf dblFreqs(1, 2) = dblFreqs(2, 2) And dblFreqs(3, 2) = 0 Then
' SetupFrm3_onSubmit = True
Exit Function
End If
'Dim newstop As Double
newstop = CDbl(CStr(CInt((dblFreqs(2, 2) - dblFreqs(1, 2)) / dblFreqs(3, 2)) * dblFreqs(3, 2) + dblFreqs(1, 2)))
If newstop <> dblFreqs(2, 2) Then
setupfrm3.fsto2.Text = newstop
' alert "Step size did not divide frequency range equally." + Chr(13) + Chr(10) + "Stop frequency changed, please check"
MsgBox "Step size did not divide frequency range equally." + Chr(13) + Chr(10) + "Stop frequency changed, please check"
' SetupFrm3_onSubmit = False
Exit Function
End If
'Frequency 3
If dblFreqs(1, 3) < stafreq Or dblFreqs(1, 3) > stofreq Then
' SetupFrm3_onSubmit = False
' alert "You have entered an invalid start frequency of " + fsta + " GHz"
MsgBox "You have entered an invalid start frequency of " + fsta1 + " GHz"
setupfrm3.fsta3.Text = stafreq
Exit Function
ElseIf dblFreqs(2, 3) < stafreq Or dblFreqs(2, 3) > stofreq Then
' SetupFrm3_onSubmit = False
' alert "You have entered an invalid stop frequency of " + fsto + " GHz"
MsgBox "You have entered an invalid stop frequency of " + fsto1 + " GHz"
setupfrm3.fsto3.Text = stofreq
Exit Function
ElseIf dblFreqs(2, 3) < dblFreqs(1, 3) Then
' SetupFrm3_onSubmit = False
' alert "You have entered an invalid frequency range"
MsgBox "You have entered an invalid frequency range"
setupfrm3.fsta3.Text = stafreq
setupfrm3.fsto3.Text = stofreq
Exit Function
End If
'Check frequencies dont conflict with ANA range AgM 10-07-2002
Jmacp
Mar 8th, 2004, 07:20 PM
'Check frequencies dont conflict with ANA range AgM 10-07-2002
If dblFreqs(1, 3) < ANAmin Or dblFreqs(1, 3) > ANAmax Then
' SetupFrm3_onSubmit = False
' alert "You have entered a start frequency outside the range of the ANA"
MsgBox "You have entered a start frequency outside the range of the ANA"
setupfrm3.fsta3.Text = stafreq
Exit Function
ElseIf dblFreqs(2, 3) > ANAmax Or dblFreqs(2, 3) < ANAmin Then
' SetupFrm3_onSubmit = False
' alert "You have entered a stop frequency outside the range of the ANA"
MsgBox "You have entered a stop frequency outside the range of the ANA"
setupfrm3.fsto3.Text = stofreq
Exit Function
End If
'Check for valid step intervals
If dblFreqs(1, 3) = dblFreqs(2, 3) And dblFreqs(3, 3) <> 0 Then
' alert "Start and Stop frequencies identical" + Chr(13) + Chr(10) + "Step size set to 0.0 GHz, please check."
MsgBox "Start and Stop frequencies identical" + Chr(13) + Chr(10) + "Step size set to 0.0 GHz, please check."
setupfrm3.fste3.Text = 0#
' SetupFrm3_onSubmit = False
Exit Function
ElseIf dblFreqs(1, 3) <> dblFreqs(2, 3) And dblFreqs(3, 3) = 0 Then
' alert "You have entered an invalid step size."
MsgBox "You have entered an invalid step size."
setupfrm3.fste3.Text = "##.##"
' SetupFrm3_onSubmit = False
Exit Function
ElseIf dblFreqs(1, 3) = dblFreqs(2, 3) And dblFreqs(3, 3) = 0 Then
' SetupFrm3_onSubmit = True
Exit Function
End If
'Dim newstop As Double
newstop = CDbl(CStr(CInt((dblFreqs(2, 3) - dblFreqs(1, 3)) / dblFreqs(3, 3)) * dblFreqs(3, 3) + dblFreqs(1, 3)))
If newstop <> dblFreqs(2, 3) Then
setupfrm3.fsto3.Text = newstop
' alert "Step size did not divide frequency range equally." + Chr(13) + Chr(10) + "Stop frequency changed, please check"
MsgBox "Step size did not divide frequency range equally." + Chr(13) + Chr(10) + "Stop frequency changed, please check"
' SetupFrm3_onSubmit = False
Exit Function
End If
Dim np As Double
Dim npts As Integer
np = ((dblFreqs(2, 1) - dblFreqs(1, 1)) / dblFreqs(3, 1)) + ((dblFreqs(2, 2) - dblFreqs(1, 2)) / dblFreqs(3, 2)) + ((dblFreqs(2, 3) - dblFreqs(1, 3)) / dblFreqs(3, 3))
npts = CInt(np)
If npts > 500 Then
' alert "Step size is too small." + vbCrLf + "Only 500 frequency points permitted in this version."
MsgBox "Too many points." + vbCrLf + "Only 500 frequency points permitted in this version."
setupfrm3.fste1.Text = "##.##"
setupfrm3.fste2.Text = "##.##"
setupfrm3.fste3.Text = "##.##"
' SetupFrm3_onSubmit = False
Exit Function
End If
End Function