Wrox Programmer Forums
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 22nd, 2008, 04:08 PM
Authorized User
 
Join Date: Nov 2007
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default ubound and array

I've used and array to perform a search for records (SQL).
Once filtered how do I use "Ubound" to count them?
I'm already using ubound in the array.
heres my code:
Private Sub TogFilter_Click()
    Dim strFilt(0 To 10) As String
    Dim aryIdx As Integer
    Dim FiltStr As String
    Dim intCo As Integer

    If TogFilter.Value = -1 Then
        If cboDwgNo.Value <> "" Then strFilt(0) = "[DwgNo] = '" & cboDwgNo.Value & "'"
        If cboLineNo.Value <> "" Then strFilt(1) = "[LineNo] = '" & cboLineNo.Value & "'"
        If cboDwgType.Value <> "" Then strFilt(2) = "[DwgType] = '" & cboDwgType.Value & "'"
        If cboPIDNo.Value <> "" Then strFilt(3) = "[PIDNo] = '" & cboPIDNo.Value & "'"
        If cboPipeSpec.Value <> "" Then strFilt(4) = "[PipeSpec] = '" & cboPipeSpec.Value & "'"
        If cboProjNo.Value <> "" Then strFilt(5) = "[ProjNo] = '" & cboProjNo.Value & "'"
        If cboRev.Value <> "" Then strFilt(6) = "[Rev] = '" & cboRev.Value & "'"
        If cboModule.Value <> "" Then strFilt(7) = "[Module] = '" & cboModule.Value & "'"
        If cboArea.Value <> "" Then strFilt(9) = "[Area] = '" & cboArea.Value & "'"
        If cboStress.Value <> "" Then strFilt(9) = "[StressRel] = '" & cboStress.Value & "'"
        If cboTracing.Value <> "" Then strFilt(10) = "[tracing] = '" & cboTracing.Value & "'"

        For aryIdx = LBound(strFilt) To UBound(strFilt)
            If strFilt(aryIdx) <> "" Then
                If FiltStr <> "" Then
                    FiltStr = FiltStr & " and " & strFilt(aryIdx)
                Else
                    FiltStr = strFilt(aryIdx)
                End If
            End If
        Next aryIdx
    End If

    If FiltStr = "" Then FiltStr = "[DwgNo] <> ''"
    FiltStr = "(" & FiltStr & ")"
    Me.Filter = FiltStr
    DoCmd.ApplyFilter , FiltStr
    Me.Refresh


End SubPrivate Sub TogFilter_Click()
    Dim strFilt(0 To 10) As String
    Dim aryIdx As Integer
    Dim FiltStr As String
    Dim intCo As Integer

    If TogFilter.Value = -1 Then
        If cboDwgNo.Value <> "" Then strFilt(0) = "[DwgNo] = '" & cboDwgNo.Value & "'"
        If cboLineNo.Value <> "" Then strFilt(1) = "[LineNo] = '" & cboLineNo.Value & "'"
        If cboDwgType.Value <> "" Then strFilt(2) = "[DwgType] = '" & cboDwgType.Value & "'"
        If cboPIDNo.Value <> "" Then strFilt(3) = "[PIDNo] = '" & cboPIDNo.Value & "'"
        If cboPipeSpec.Value <> "" Then strFilt(4) = "[PipeSpec] = '" & cboPipeSpec.Value & "'"
        If cboProjNo.Value <> "" Then strFilt(5) = "[ProjNo] = '" & cboProjNo.Value & "'"
        If cboRev.Value <> "" Then strFilt(6) = "[Rev] = '" & cboRev.Value & "'"
        If cboModule.Value <> "" Then strFilt(7) = "[Module] = '" & cboModule.Value & "'"
        If cboArea.Value <> "" Then strFilt(9) = "[Area] = '" & cboArea.Value & "'"
        If cboStress.Value <> "" Then strFilt(9) = "[StressRel] = '" & cboStress.Value & "'"
        If cboTracing.Value <> "" Then strFilt(10) = "[tracing] = '" & cboTracing.Value & "'"

        For aryIdx = LBound(strFilt) To UBound(strFilt)
            If strFilt(aryIdx) <> "" Then
                If FiltStr <> "" Then
                    FiltStr = FiltStr & " and " & strFilt(aryIdx)
                Else
                    FiltStr = strFilt(aryIdx)
                End If
            End If
        Next aryIdx
    End If

    If FiltStr = "" Then FiltStr = "[DwgNo] <> ''"
    FiltStr = "(" & FiltStr & ")"
    Me.Filter = FiltStr
    DoCmd.ApplyFilter , FiltStr
    Me.Refresh


End Sub
:===============
Thanks

 
Old January 22nd, 2008, 05:26 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Look: UBound(srtFilt) will always be 10, because you have dimensioned the array from 0 to 10.

If you are dedicated to the basic methodology you have here, I suggest making a Type having the 11 elements that you want, say tpRecord, and make a [u]d</u>y[u]namic</u> array of that type(Dim MyArray() As tpRecord).

Then, for each record, ReDim Preserve(MyArray) that array to add a new element.

When you are done, your array will now be sized in accordance with the number of records.
Code:
Type tpRecord
    DwgNo    As String
    LineNo   As String
    DwgType  As String
    ' Etc.
End Type
If you use this type to create an array, the way you would address each element would be
Code:
    MyArray(indexNo).DwgNo = "Some value"
 
Old January 28th, 2008, 06:12 PM
Authorized User
 
Join Date: Nov 2007
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm a little confused on this. Can you give me a little more info.
Also Look at my other entry on the record.count problem.
Thanks:)

 
Old January 28th, 2008, 07:14 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

It would help if you could narrow where the confusion creeps in.

first of all, do you understand the difference between a dynamic array, and one that is not?
 
Old January 29th, 2008, 01:48 PM
Authorized User
 
Join Date: Nov 2007
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nevermind, solved problem. Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Convering a String Array to an Integer array nkrust C# 9 November 17th, 2010 12:02 PM
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
error when sorting an Array of Array nancy VBScript 2 February 17th, 2005 12:57 PM
Assigning value to array within array janise Beginning VB 6 23 January 11th, 2005 11:38 AM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.