UBound Limit in for statment (1 Viewer)

Dreamweaver

Well-known member
Local time
Today, 05:22
Joined
Nov 28, 2005
Messages
2,466
Code:
    DDArray = Split(Str, " ")                                                       'copy OpenArgs values to array
For I = LBound(DDArray) To UBound(DDArray)

I'm sure there's a way of doing this but I just can't remember, I just know I'm going to kick myself.
Want I want Is to loop trough the DDarray to stop in the 3rd loop if there are more than 3 words, I know I can test I to make sure it's I<4 but my head keeps telling me to limit the UBound but it wont remember how to do it for me.

mick
 

Isaac

Lifelong Learner
Local time
Yesterday, 22:22
Joined
Mar 14, 2017
Messages
8,738
Ok I'm not 100% sure I understand your question - especially since you seem to have posted sort of what my answer would be already (?)
Not sure.

Code:
dim x as long

if ubound(ddarray)>3 then
   x=3
else
  x=ubound(ddarray)
end if

for i = lbound(ddarray) to x
   ...........
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 05:22
Joined
Sep 21, 2011
Messages
14,048
Another member just posted this
Code:
If Not Trim(Me.OpenArgs & " ") = "" Then
   Me.cboSelectAccount = Split(Me.OpenArgs, ";")(0)
    If UBound(Split(Me.OpenArgs, ";")) = 1 Then
     Me.cboEntryNo = Split(Me.OpenArgs, ";")(1)
    End If
End If
 

cheekybuddha

AWF VIP
Local time
Today, 05:22
Joined
Jul 21, 2014
Messages
2,237
You can also:
Code:
    DDArray = Split(Str, " ")                                                       'copy OpenArgs values to array
    For I = LBound(DDArray) To UBound(DDArray)
        ' Do Stuff
        If I = 2 Then Exit For
    Next I
 

Cronk

Registered User.
Local time
Today, 16:22
Joined
Jul 4, 2013
Messages
2,770
Or
Code:
   i = LBound(DDArray)
   while i < 3 And i <= uBound(DDArray)
      i = i + 1
   wend
 

Dreamweaver

Well-known member
Local time
Today, 05:22
Joined
Nov 28, 2005
Messages
2,466
Cool Nice @Cronk but using exit for, I was having a mick moment you know when you know how to do something but bashing your head against a wall doesn't help.

For this interested I was creating a product code like the old Northind just updated it.

Code:
Function GenCode(Str As String, ID) As String
Dim IntProdNum As Long
Dim StrSQL As String
Dim recCode As Recordset
Dim Db As Database
Dim StrSet As String
Dim DDArray() As String
Dim CUS As String
Dim I As Integer
On Error GoTo HandleErr

StrSQL = "SELECT * FROM StblSystemID WHERE [ID]=" & ID

    DDArray = Split(Str, " ")                                                       'copy Item value to array
For I = LBound(DDArray) To UBound(DDArray)
    'looping through array here
    If Len(DDArray(I)) > 1 Then CUS = CUS & Left(DDArray(I), 3)
    If I = 2 Then Exit For '0 Based
Next I

Set Db = CurrentDb()
Set recCode = Db.OpenRecordset(StrSQL)

IntProdNum = recCode("LastNumber")

GenCode = UCase(DoReplaceData(CUS)) & IntProdNum & Forms!frmDetectIdleTime!txtUser

IntProdNum = IntProdNum + 1

StrSet = "UPDATE StblSystemID SET [LastNumber] =" & IntProdNum & " WHERE [ID]=" & ID
    'UpDate The Last Number + 1
        Db.Execute StrSet

recCode.Close
Set recCode = Nothing

HandleExit:
    Exit Function
   
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox Err.Number & vbCrLf & Err.Description
            Resume HandleExit
        Resume
    End Select
End Function

The result is in the product code top of form
 

Users who are viewing this thread

Top Bottom