Need Some Help Please
Need Some Help Please
Need Some Help Please
Need Some Help Please
Need Some Help Please
Need Some Help Please Need Some Help Please Need Some Help Please Need Some Help Please Need Some Help Please Need Some Help Please Need Some Help Please Need Some Help Please
Need Some Help Please Need Some Help Please
Need Some Help Please
Go Back  Xtreme Visual Basic Talk > > > Need Some Help Please


Reply
 
Thread Tools Display Modes
  #1  
Old 09-03-2017, 01:28 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default Need Some Help Please


I get this output from the code below:
Code:
1 [0]

2 [2]
3 [2]
4 [2]

5 [3]
6 [3]
7 [3]
8 [3]

9 [2]

10 [4]
11 [4]
12 [4]
13 [4]
14 [4]
15 [4]

16 [2]
17 [2]
18 [2]
19 [2]
20 [2]
I would like instead this output.
In other words, the objCode groups to be grouped in multiples of the value of objCode
Code:
1 [0]

2 [2]
3 [2]

4 [2]

5 [3]
6 [3]
7 [3]

8 [3]

9 [2]

10 [4]
11 [4]
12 [4]
13 [4]

14 [4]
15 [4]

16 [2]
17 [2]

18 [2]
19 [2]

20 [2]
This is my code
Code:
Option Explicit

Dim obj() As Long


Private Sub Form_Load()

    ReDim obj(1 To 20)
    
    obj(1) = 0
    obj(2) = 2
    obj(3) = 2
    obj(4) = 2
    obj(5) = 3
    obj(6) = 3
    obj(7) = 3
    obj(8) = 3
    obj(9) = 2
    obj(10) = 4
    obj(11) = 4
    obj(12) = 4
    obj(13) = 4
    obj(14) = 4
    obj(15) = 4
    obj(16) = 2
    obj(17) = 2
    obj(18) = 2
    obj(19) = 2
    obj(20) = 2

End Sub


Private Sub Command1_Click()

    Dim i As Long
    Dim j As Long
    Dim numObjCode As Long
    Dim prevObjCode As Long
    Dim thisObjCode As Long
    
    For i = 1 To UBound(obj)
        
        numObjCode = 0
        
        If obj(i) <> prevObjCode Then

            For j = i To UBound(obj)

                thisObjCode = obj(i)

                If obj(j) <> thisObjCode Then
                    Exit For
                End If
                
                numObjCode = numObjCode + 1
                
            Next j

            Debug.Print ""

        End If
        
        If obj(i) <> prevObjCode Then
            prevObjCode = obj(i)
        End If
        
        Debug.Print i & " [" & obj(i) & "]"
 
    Next i

End Sub
Can anyone offer any help?
Reply With Quote
  #2  
Old 09-04-2017, 08:47 AM
Daigon Ali Daigon Ali is offline
Regular
 
Join Date: Aug 2014
Location: London
Posts: 59
Default

Hi, Perhaps something like this?

Code:
Private Sub Command1_Click()
    Dim i As Long
    Dim j As Long
    Dim numObjCode As Long
    Dim prevObjCode As Long
    Dim thisObjCode As Long
    
    For i = 1 To UBound(obj)
        numObjCode = 0
        If obj(i) <> prevObjCode Then
            For j = i To UBound(obj)
                thisObjCode = obj(i)
                If obj(j) <> thisObjCode Then
                    Exit For
                End If
                numObjCode = numObjCode + 1
            Next j
            Debug.Print ""
            Counter = 0
        End If
        If obj(i) <> prevObjCode Then
            prevObjCode = obj(i)
        End If
        If IsNumeric(obj(i)) = True and Counter > 0 Then
            If Counter = obj(i) Then
                Debug.Print ""
                Counter = 0
            End If
        End If
        Debug.Print i & " [" & obj(i) & "]"
        Counter = Counter + 1
    Next i
End Sub
Reply With Quote
  #3  
Old 09-05-2017, 09:45 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

Thanks Daigon Ali

That most definitely works!!

Now to incorporate this methodology into my main program.
Reply With Quote
Reply

Tags
[2], [4], [3], dim, obji, numobjcode, prevobjcode, thisobjcode, uboundobj, objcode, obj1, debug.print, private, [0], output, code, obj26, obj25, obj27, obj28, obj30, obj29, obj24, obj20, obj19


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Need Some Help Please
Need Some Help Please
Need Some Help Please Need Some Help Please
Need Some Help Please
Need Some Help Please
Need Some Help Please Need Some Help Please Need Some Help Please Need Some Help Please Need Some Help Please Need Some Help Please Need Some Help Please
Need Some Help Please
Need Some Help Please
 
Need Some Help Please
Need Some Help Please
 
-->