How to Compare a Range of Values with a Database
Please Help
I am working on an application for allocating the unallocated frequency from a given frequency range, say 138MHz-138.5MHz. The Gap Between two frequencies should be atleast 0.025MHz. for simplex mode and 5MHz for Duplex mode. Now the problem is that some frequency in this range is already been alloted to the customers. So while allocating a frequency i need to check whether the other allocated frequency falls within the 0.025MHz range to the left or right of the present frequency and discard them if they Do. The unallocated frequency can then be found out and allocated accordingly. But I am finding some problem and my code is not getting Executed. Can somebody help me?? Below is my code snippet.
VB Code:
Private Sub Command2_Click()
Dim F_Cnt As Integer
Dim Sto_Fr As String
Dim i, Flag
Start_F = Text1.Text
End_F = Text2.Text
NO_OF_FREQ = Val(Text3.Text)
Dim Count_R
Value = LowHiVal()
'MsgBox Val(Low_Val)'
'MsgBox Val(Hi_Val)'
If Start_F <> "" Or End_F <> "" Then
If Start_F < Val(Low_Val) Or End_F > Val(Hi_Val) Then
MsgBox "Value out of Range. Please Enter New Values"
Else
F_Cnt = 0
New_Check = Start_F
Do While F_Cnt <> NO_OF_FREQ
If Combo3.Text = "Simplex" Then
New_Check = New_Check + Val(0.025)
End If
If Combo3.Text = "Duplex" Then
New_Check = New_Check + Val(0.05)
End If
Sto_Fr = New_Check
'MsgBox New_Freq'
Place_Use = Combo9.Text
'Search the DB'
sqlExecuteVHFCheck
GoTo recordsetSql1
recordsetSql1:
On Error GoTo sqlError
Data1.RecordSource = sql1
Data1.Refresh
'If the resultset is empty add the value to the frequency table'
'Data1.Recordset.Seek "=", New_Freq'
If Data1.Recordset.BOF = True And Data1.Recordset.EOF = True Then
If Form14.Text1.Text <> "" Then
Form14.Text1.Text = Form14.Text1.Text + "MHz, " + Sto_Fr
ElseIf Form14.Text1.Text = "" Then
Form14.Text1.Text = Form14.Text1.Text + Sto_Fr
ElseIf F_Cnt = NO_OF_FREQ Then
Form14.Text1.Text = Form14.Text1.Text + Sto_Fr + "MHz"
End If
'MsgBox "Unable to Display Form14"'
'Increment F_Cnt'
'New_Freq = New_Check'
For New_Freq = New_Check To (New_Check + 0.025)
New_Freq = New_Freq + 0.001
sqlExecuteVHF
GoTo recordsetSql
recordsetSql:
On Error GoTo sqlError
Data1.RecordSource = sql
Data1.Refresh
If Data1.Recordset.BOF = True And Data1.Recordset.EOF = True Then
'No record Exists'
Flag = 1
Else
MsgBox "Frequency already Alloted."
Flag = 0
Exit For
End If
Next
If Flag = 0 Then
GoTo Skip
End If
'Move Left Side of the Sideband'
For New_Freq = New_Check To (New_Check - 0.025)
New_Freq = New_Freq - 0.001
sqlExecuteVHF
GoTo recordsetSql2
recordsetSql2:
On Error GoTo sqlError
Data1.RecordSource = sql
Data1.Refresh
If Data1.Recordset.BOF = True And Data1.Recordset.EOF = True Then
'No record Exists'
Else
MsgBox "Frequency in Range already Alloted."
'get a new New_Check'
Exit For
End If
Next
Skip: F_Cnt = F_Cnt + 1
Else
'MsgBox "record Exists"'
'If resultset is not empty, ignore the value'
End If
Loop
End If
Else
MsgBox "Enter Start and End Frequencies"
End If
Form14.Text1.Text = Form14.Text1.Text + "MHz"
Form14.Visible = True
'MsgBox Sto_Fr'
Exit Sub
sqlError:
MsgBox Err.Description
MsgBox "SQL Error"
End Sub
Private Sub Command4_Click()
Text13.Text = LF_B + LF_R + Amt_H
End Sub
Edit: Added [vbcode][/vbcode] tags for clairty. - Hack
Re: How to Compare a Range of Values with a Database
1. What is LowHiVal()? Is it a function or an array? What is its data type.
2. What are Low_Val and Hi_Val?
3. Please add the "Option Explicit" statement at the top of your code module and make sure you have declared all the variables then post your code again.
Re: How to Compare a Range of Values with a Database
By the way, please use [ vbcode ][ /vbcode ] tags when posting code and use TABs to indent.