Results 1 to 3 of 3

Thread: How to Compare a Range of Values with a Database

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    1

    Angry 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:
    1. Private Sub Command2_Click()
    2. Dim F_Cnt As Integer
    3. Dim Sto_Fr As String
    4. Dim i, Flag
    5. Start_F = Text1.Text
    6. End_F = Text2.Text
    7. NO_OF_FREQ = Val(Text3.Text)
    8. Dim Count_R
    9. Value = LowHiVal()
    10. 'MsgBox Val(Low_Val)'
    11. 'MsgBox Val(Hi_Val)'
    12.  
    13. If Start_F <> "" Or End_F <> "" Then
    14.     If Start_F < Val(Low_Val) Or End_F > Val(Hi_Val) Then
    15.         MsgBox "Value out of Range. Please Enter New Values"
    16.     Else
    17.         F_Cnt = 0
    18.         New_Check = Start_F
    19.         Do While F_Cnt <> NO_OF_FREQ
    20.             If Combo3.Text = "Simplex" Then
    21.                 New_Check = New_Check + Val(0.025)
    22.             End If
    23.             If Combo3.Text = "Duplex" Then
    24.                 New_Check = New_Check + Val(0.05)
    25.             End If
    26.             Sto_Fr = New_Check
    27.             'MsgBox New_Freq'
    28.             Place_Use = Combo9.Text
    29.             'Search the DB'
    30.             sqlExecuteVHFCheck
    31.             GoTo recordsetSql1
    32. recordsetSql1:
    33.    
    34.         On Error GoTo sqlError
    35.             Data1.RecordSource = sql1
    36.             Data1.Refresh
    37.            
    38.      
    39.      'If the resultset is empty add the value to the frequency table'
    40.        
    41.         'Data1.Recordset.Seek "=", New_Freq'
    42.  
    43.            
    44.             If Data1.Recordset.BOF = True And Data1.Recordset.EOF = True Then
    45.                 If Form14.Text1.Text <> "" Then
    46.                      Form14.Text1.Text = Form14.Text1.Text + "MHz, " + Sto_Fr
    47.                 ElseIf Form14.Text1.Text = "" Then
    48.                      Form14.Text1.Text = Form14.Text1.Text + Sto_Fr
    49.                 ElseIf F_Cnt = NO_OF_FREQ Then
    50.                      Form14.Text1.Text = Form14.Text1.Text + Sto_Fr + "MHz"
    51.                
    52.                 End If
    53.                 'MsgBox "Unable to Display Form14"'
    54.                 'Increment F_Cnt'
    55.                 'New_Freq = New_Check'
    56.                 For New_Freq = New_Check To (New_Check + 0.025)
    57.                     New_Freq = New_Freq + 0.001
    58.                     sqlExecuteVHF
    59.                     GoTo recordsetSql
    60. recordsetSql:
    61.    
    62.                     On Error GoTo sqlError
    63.                     Data1.RecordSource = sql
    64.                     Data1.Refresh
    65.                     If Data1.Recordset.BOF = True And Data1.Recordset.EOF = True Then
    66.                         'No record Exists'
    67.                         Flag = 1
    68.                     Else
    69.                         MsgBox "Frequency already Alloted."
    70.                         Flag = 0
    71.                         Exit For
    72.                     End If
    73.                 Next
    74.                 If Flag = 0 Then
    75.                     GoTo Skip
    76.                 End If
    77.                 'Move Left Side of the Sideband'
    78.            
    79.                 For New_Freq = New_Check To (New_Check - 0.025)
    80.                     New_Freq = New_Freq - 0.001
    81.                     sqlExecuteVHF
    82.                     GoTo recordsetSql2
    83. recordsetSql2:
    84.    
    85.                     On Error GoTo sqlError
    86.                     Data1.RecordSource = sql
    87.                     Data1.Refresh
    88.                     If Data1.Recordset.BOF = True And Data1.Recordset.EOF = True Then
    89.                         'No record Exists'
    90.                        
    91.                     Else
    92.                         MsgBox "Frequency in Range already Alloted."
    93.                         'get a new New_Check'
    94.                         Exit For
    95.                     End If
    96.                 Next
    97.                
    98. Skip:                F_Cnt = F_Cnt + 1
    99.             Else
    100.                 'MsgBox "record Exists"'
    101.             'If resultset is not empty, ignore the value'
    102.             End If
    103.         Loop
    104.     End If
    105.     Else
    106.         MsgBox "Enter Start and End Frequencies"
    107.    
    108.     End If
    109. Form14.Text1.Text = Form14.Text1.Text + "MHz"
    110. Form14.Visible = True
    111. 'MsgBox Sto_Fr'
    112. Exit Sub
    113. sqlError:
    114.    
    115.         MsgBox Err.Description
    116.         MsgBox "SQL Error"
    117.    
    118.  
    119. End Sub
    120.  
    121. Private Sub Command4_Click()
    122. Text13.Text = LF_B + LF_R + Amt_H
    123. End Sub




    Edit: Added [vbcode][/vbcode] tags for clairty. - Hack
    Last edited by Hack; Aug 11th, 2005 at 05:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width