For Next Loop

ok, i found few more syntax error so not describe what and where i'll summarize the changes and you can compare differences:

Sub Main()

'Declare variables
Dim Var1 As String * 20
Dim Operator_Entry As String * 20
Dim Screen_Location As String * 80
Dim Index_Number As Integer
Dim Letter As String * 20
Dim Max_Index_Number As Integer

'Initialize values and Get Values from HMI
Max_Index_Number = 16
Operator_Entry = PointGet("PRODUCT_CODE_ENTRY")

'When Letter is equal to F1
Letter = "F1"
For Index_number = 1 To Max_Index_Number
GoSub Check_Test
Next Index_number

Check_Test:

Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_number & "]")
If Var1 = Operator_Entry Then
Screen_Location = Letter & " Manifold"

PointSet "SCREEN_LOCATION_HMI",Screen_Location
PointSet "INDEX_NUMBER_HMI",Index_Number

GoTo Found_Match

End If

Found_Match:

PointSet "SEARCH_BUTTON",0

End Sub
 
@ balash i used what you posted with a minor syntax fix where the "n" in Index_number should be uppercase "N" so it will be Index_Number, because that is what is declared as a variable,you can see the updated code below. I have attached a picture of the error. when i run the program somehow it does not like whats going on here Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]") I have attached the picture for you to see.


Sub Main()

'Declare variables
Dim Var1 As String * 20
Dim Operator_Entry As String * 20
Dim Screen_Location As String * 80
Dim Index_Number As Integer
Dim Letter As String * 20
Dim Max_Index_Number As Integer

'Initialize values and Get Values from HMI
Max_Index_Number = 16
Operator_Entry = PointGet("PRODUCT_CODE_ENTRY")

'When Letter is equal to F1
Letter = "F1"
For Index_Number = 1 To Max_Index_Number
GoSub Check_Test
Next Index_Number

Check_Test:

Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")
If Var1 = Operator_Entry Then
Screen_Location = Letter & " Manifold "

PointSet "SCREEN_LOCATION_HMI",Screen_Location
PointSet "INDEX_NUMBER_HMI",Index_Number

GoTo Found_Match

End If

Found_Match:

PointSet "SEARCH_BUTTON",0

End Sub
 
@ Balash
I did three different test with different syntax for the line that has the issue. I have attached the pictures for all three, this is getting annoying as it is a simple task. Once again let me know if you see something
 
I don't believe it is possible to use the PointGet() to fetch a single element of an array point. You have to dimension an array in the script and transfer the entire Cimplicity array point to it.

There is an example somewhere in the help files. I have done it in the past and when I get a chance later today I'll try to find an example. The project file is on a different computer than the one I'm using right now.
 
good point Calisto !!
now i notice that Gosub missing a Return command
so now, i've come up with 2 solution to try:
---------------------------------------------

Sub Main()

(bla bla bla, stays the same)

Dim Match_Found As Boolean

Match_Found=FALSE

For Index_Number = 1 To Max_Index_Number
GoSub Check_Test
If Match_Found Then Exit For
End If
Next Index_Number

Exit Sub

Check_Test:

Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")
If Var1 = Operator_Entry Then
Screen_Location = Letter & " Manifold "

PointSet "SCREEN_LOCATION_HMI",Screen_Location
PointSet "INDEX_NUMBER_HMI",Index_Number

Match_Found=TRUE

GoTo Found_Match

End If

GoTo Not_Found_Match

Found_Match:

PointSet "SEARCH_BUTTON",0

Not_Found_Match:

Return

End Sub

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

more appropriate and cleaner would be to replace whole GOSUB in For loop:
Code:
Sub Main()

(bla bla bla, stays the same)

For Index_Number = 1 To Max_Index_Number
  Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")
  If Var1 = Operator_Entry Then
    Screen_Location = Letter & " Manifold "

    PointSet "SCREEN_LOCATION_HMI",Screen_Location
    PointSet "INDEX_NUMBER_HMI",Index_Number
[B]
    PointSet "SEARCH_BUTTON",0[/B]
    Exit For

  End If
Next Index_Number

End Sub

of course what steve said:
I don't believe it is possible to use the PointGet() to fetch a single element of an array point. You have to dimension an array in the script and transfer the entire Cimplicity array point to it.
still remains to be cleared...
 
Last edited:
@ Calistodwt you are right i just check the syntax and the GoSub needs a return.

@ balash, i will try what you suggested and will post my findings in a bit
 
I believe that you will need to remove the parenthesis in front of the index variable.

Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")

So it should look like this:

Var1 = PointGet(Letter & "_PRODUCT_CODES" & [" & Index_Number & "]")
 
I believe that you will need to remove the parenthesis in front of the index variable.

Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")

So it should look like this:

Var1 = PointGet(Letter & "_PRODUCT_CODES" & [" & Index_Number & "]")

ahahha, interesting, but then he also don't need paragraph marks around index_number because it is integer so it coculd be:

Var1 = PointGet(Letter & "_PRODUCT_CODES" & [Index_Number])

but looking at that i do not know how array name would pass as string. hmmm
 
@ balash, so i tried your first solution, Goodnews it compiled and when i ran it it ran. However here are my findings. I ommited the EndIF after the If statement that pertains to the Match_Found because it gave me an error when trying to complie it with the Endif, and since their is an EXit For
command if the match is found that should take care of it. I added in the Initial values for Letter which is "F1" and the PointGet for the PRODUCT_CODE_ENTRY which is the code that the user enters.

So i happen to enter a value 80355 into PRODUCT_CODE_ENTRY from the HMI. And in the comparison once the PointGet
gives Var1 a value which is equal to F1_PRODUCT_CODES[1], that will be a match in the first iteration
of the loop, then the variables SCREEN_LOCATION_HMI and INDEX_NUMBER_HMI should have values, but when
i checked the values for them in the HMI, they have no values (currently reading ***) although if the code executed correctly they should read for SCREEN_LOCATION_HMI as F1 Manifold and the INDEX_NUMBER_HMI as 1.

Code i used is below, in the meantime i will try your second solution.


Sub Main()

'Declare variables
Dim Var1 As String * 20
Dim Operator_Entry As String * 20
Dim Screen_Location As String * 80
Dim Index_Number As Integer
Dim Letter As String * 20
Dim Max_Index_Number As Integer
Dim Match_Found As Boolean


'Initialize values and get required variables
Match_Found=FALSE
Letter = "F1"
Operator_Entry = PointGet("PRODUCT_CODE_ENTRY")

'Execute the for loop and if matching condition is found exit the loop, if no match found return back to loop till it is found
For Index_Number = 1 To Max_Index_Number
GoSub Check_Test
If Match_Found = TRUE Then Exit For

Next Index_Number

Exit Sub

Check_Test:

Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")
If Var1 = Operator_Entry Then
Screen_Location = Letter & " Manifold "

PointSet "SCREEN_LOCATION_HMI",Screen_Location
PointSet "INDEX_NUMBER_HMI",Index_Number

Match_Found=TRUE

GoTo Found_Match

End If

GoTo Not_Found_Match

Found_Match:

PointSet "SEARCH_BUTTON",0


Not_Found_Match:

Return

End Sub
 
Last edited:
ahahha, interesting, but then he also don't need paragraph marks around index_number because it is integer so it coculd be:

Var1 = PointGet(Letter & "_PRODUCT_CODES" & [Index_Number])

but looking at that i do not know how array name would pass as string. hmmm


Ah yes you are correct. You would need the parenthesis in front of Letter to make it a complete string:

Var1 = PointGet("Letter & "_PRODUCT_CODES" & [" & Index_Number & "]")
 
ok @ balash i tried your second solution, that to complied successfully and ran, however still same issue where SCREEN_LOCATION_HMI and INDEX_NUMBER_HMI have no value.

Obviously the
Var1 = PointGet("Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")
is causing the issue because if Var1 gets a value and the comparison is true then i don't see a reason as to why SCREEN_LOCATION_HMI and INDEX_NUMBER_HMI can't have values

I tried adjusting the syntax to
Var1 = PointGet("Letter & "_PRODUCT_CODES" & [" & Index_Number & "]")

and also to
Var1 = PointGet(Letter & "_PRODUCT_CODES" & [Index_Number])

both wouldn't compile, but
Var1 = PointGet("Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")
compiled which is what we currently have in the code.

Index_Number is defined as an Integer, but Var1 is defined as a String but since we are just Concatenating and viewing the whole thing as a string and doing the compares as strings between Var1 and Operator_Entry which are both strings it should have worked.

I even tried Maxketcham's suggestion to convert the Index_Number to a string as below

Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" &str$(Index)& "]")

and although that compiled and ran still, SCREEN_LOCATION_HMI and INDEX_NUMER_HMI had no values

Here is the Code Below for the second solution that Balash mentioned:


Sub Main()

'Declare variables
Dim Var1 As String * 20
Dim Operator_Entry As String * 20
Dim Screen_Location As String * 80
Dim Index_Number As Integer
Dim Letter As String * 20
Dim Max_Index_Number As Integer

'Initialize values and get required variables
Letter = "F1"
Operator_Entry = PointGet("PRODUCT_CODE_ENTRY")


For Index_Number = 1 To Max_Index_Number
Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")
If Var1 = Operator_Entry Then
Screen_Location = Letter & " Manifold "

PointSet "SCREEN_LOCATION_HMI",Screen_Location
PointSet "INDEX_NUMBER_HMI",Index_Number

PointSet "SEARCH_BUTTON",0
Exit For

End If
Next Index_Number

End Sub
 
I figured out the problem with this dreaded issue, and as it turns out it was a pretty simple one.

Their is a Variable that i declared in the beginning called
Letter As String * 20, the *20 means max number of characters is 20

So when i looked up the syntax for a String data type it mentioned that
if your value for the Letter which in our case was F1 happensto be less than the fixed String length which is 20 in our case then the value of Letter is going to be padded with spaces up to its declared length thats why i kept getting the PRODUCT_CODES error.

So as a simple solution unless your are absolutely certain that you need a specific fixed length if characters omit the *20 and your good to go, well at least in this version of basic that's what it does.


Nonetheless Thanks to everyone's input i truly appreciate it.
 
Ok so in my case their exists a String Variable that has an array size of 17 (0-16), lets call this string F1_PRODUCT_CODES. Each array index starting from array index 1 (Yes im not starting at array index 0) has a preset value so for example F1_PRODUCT_CODES[1] = 80344F

Where is the array for the product codes declared in your code? Or is it not necessary to declare the array?
 
@ Calistodwt those values are not declared in the code because they are coming from outside the code which is HMI tags, thats why i have a
Var1 = PointGet(Letter & "_PRODUCT_CODES" & "[" & Index_Number & "]")
to get those values so that i can do the necessary comparisons
 

Similar Topics

Hi all. (this is no homework) For a couple of day I've been practicing on a Mitshi plc. All went fine including data registers etc until I tried...
Replies
24
Views
6,118
Hello All, I read so many posts where individuals utilize the practice of for-next loops. And I was hoping to find some example code, so that I...
Replies
5
Views
6,201
N
In a processor like the MicroLogix 1500 which does not have a built-in FOR..NEXT loop instruction (I've seen some web sites that indicate that...
Replies
26
Views
28,629
New2PLCs
N
I've got this start screen where the user has to enter their username and password. The username and password feature works fine. However, I want...
Replies
7
Views
1,443
Anyone know what the little green triangle on SCREEN 3 means ? See picture Thanks
Replies
2
Views
459
Back
Top Bottom