UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> For Next Statement, Access 2010    
 
   
Pastor Del
post Oct 3 2017, 10:54 PM
Post#1



Posts: 329
Joined: 27-July 10



I'm putting together code to step through a string character by character. I'm using a For Next statement that's giving me problems.

The code:
CODE
For intCount = intCountStore To Len(strRefDes)

Code to deal with each character...
CODE
Next

With intCountStore = 22, Len(strRefDes) = 42, & strRefDes = "VR444,VR445,VR446,R15,R16,R17,R20,VR1-VR3," Next falls through instead of returning to For.
Can anyone point out the problem?
Go to the top of the page
 
cheekybuddha
post Oct 4 2017, 08:21 AM
Post#2


UtterAccess VIP
Posts: 9,281
Joined: 6-December 03
From: Telegraph Hill


Hmmm...

Perhaps show:

>> Code to deal with each character... <<

The problem probably lies there.

d

--------------------


Regards,

David Marten
Go to the top of the page
 
BuzyG
post Oct 4 2017, 08:26 AM
Post#3



Posts: 340
Joined: 20-September 12
From: Cornwall UK


Intcountstore is the start value of your count. Therefore you are starting half way through. Should Intcountstore not be 0.

--------------------
Live to Surf
Go to the top of the page
 
kfield7
post Oct 4 2017, 12:12 PM
Post#4



Posts: 775
Joined: 12-November 03
From: Iowa Lot


re: " Next falls through instead of returning to For."

Did you verify this with
debug.print "intCount: "; intCount
?

I suspect Cheeky's on point.
Go to the top of the page
 
Pastor Del
post Oct 4 2017, 06:19 PM
Post#5



Posts: 329
Joined: 27-July 10



I understand the need for seeing the code in the middle but there is a LOT of it & some is sensitive. Maybe I can add some light. intCountStore is changed many times, depending on the string of characters. This brings the following question to mind. When execution gets to Next does it look at intCountStore to decide to go back to For or is that decision made when For is executed?
Go to the top of the page
 
Pastor Del
post Oct 4 2017, 06:20 PM
Post#6



Posts: 329
Joined: 27-July 10



kfield7: I'm not sure what you mean or how to do it.
Go to the top of the page
 
cheekybuddha
post Oct 4 2017, 06:30 PM
Post#7


UtterAccess VIP
Posts: 9,281
Joined: 6-December 03
From: Telegraph Hill


If intCountStore is greater than 42 when it reaches Next, then it will end the For ... Next and code will continue.

If you're trying to deal with each comma separated string and perform actions on them, you might consider using Split() first, and looping through the array of each element.

But it's difficult to advise with nothing to go on!

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
BuzyG
post Oct 5 2017, 03:48 AM
Post#8



Posts: 340
Joined: 20-September 12
From: Cornwall UK


The way you appear to be doing it. if intcountstore is greater than 0. Then if you don't find what you are looking for early in the string you will reach the next statement with Intcountstore, plus loop iterations, being greater than Len(strRefDes). This would cause your problem.

When I'm splitting up data strings. I use Mid to isolate the character I wish to process next.

Take a look at this example. It may help. It searches for ";" every 40 characters, in a memo field and prints the record details, if it's not correct. That's not important. It's the use of Mid, within the for next loop that may help you.

CODE
Function NewFormat_tblAsset()
Dim LenStr As Integer
Dim TempStr As String
Dim q As Integer
Dim w As Integer
Dim e As Integer
Set DB = CurrentDb()
Set rst = DB.OpenRecordset("tblAsset", dbOpenDynaset)
q = 0
Do Until rst.EOF
   q = q + 1
   LenStr = Len(rst![AssetLog])
   TempStr = rst![AssetLog]
   w = 0
   For e = 1 To LenStr
     If Mid(TempStr, e, 1) = ";" Then
       w = w + 1
     End If
   Next e
   If ((LenStr + 1) / w) <> 40 Then
     Debug.Print q & "  " & rst![AssetNumber] & "  " & LenStr & "  " & w
   End If
   rst.MoveNext
Loop 'rst
rst.Close
Set rst = Nothing
DB.Close
End Function

--------------------
Live to Surf
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    17th December 2017 - 10:18 PM