For Next Loop

dbh6

Lifetime Supporting Member
Join Date
Jan 2013
Location
Central, NJ
Posts
552
Hello All,

HMI application I'm using is GE's HMI/SCada Cimplicity. Im writing a basic program in the script to do as follows.

When the operator enters a value, the code will return a locations as to what screen to go to and what the index number is in plain text. In cimplicity you can specify what programming language to use from Basic, Visual Basic or C#. Since this is an existing project that i'm making additions to i did it in basic which is fairly similar to Visual basic because all the existing code is in basic.

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


So what basically happens is when an operator enters a value and presses a search button, my code just compares to find a match, if it does it outputs to the HMI the locations of whatever string you specify in this case i used F1 and an Index number, sounds simple. So below i highlighted what i did without a For Next Loop for two iterations as an example, and then i highlighted one with a For Next Loop.

In conclusion, without using the For next loop, it worked, but that would be tedious and overwhelming to do because i have to do the same to a whole bunch of stuff as well. So if you have the time of day, let me know if you can see the bug for the program using the For Next loop.

I keep getting a error in configurations for point for what i put in bold below, maybe my syntax is wrong
Var1 = PointGet("Letter"&"_PRODUCT_CODES"&"[Index]")









Without for next loop:

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

'Get the input that was entered by the operator
Operator_Entry = PointGet("PRODUCT_CODE_ENTRY")

'Compare the data coming from the database, if equal with the inputed data then display Letter and Index#
Var1 = PointGet("F1_PRODUCT_CODES[1]")
If Var1 = Operator_Entry Then
Screen_Location = "F1 Manifold"
Index_Number = 1

'Sets the current Values to the HMI
PointSet "SCREEN_LOCATION_HMI",Screen_Location
PointSet "INDEX_NUMBER_HMI",Index_Number

GoTo End_Check

End If


'Compare the data coming from the database, if equal with the inputed data then display Letter and Index#
Var1 = PointGet("F1_PRODUCT_CODES[2]")
If Var1 = Operator_Entry Then
Screen_Location = "F1 Manifold"
Index_Number = 2

'Sets the current Value the HMI
PointSet "SCREEN_LOCATION_HMI",Screen_Location
PointSet "INDEX_NUMBER_HMI",Index_Number

GoTo End_Check

End If



End_Check:


PointSet "SEARCH_BUTTON",0

End Sub




With for next loop:

Sub Main()

'Declare variables
Dim Var1 As String * 20
Dim Operator_Entry As String * 20
Dim Screen_Location As String * 80
Dim Index As Integer
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]")
If Var1 = Operator_Entry Then
Screen_Location = "Letter"&" "&"Manifold"
Index_Number = Index

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
 
@ Maxketcham

i moved the concatenation before the call, however the error still persists

Code with the edits is below



Sub Main()

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

'Initialize values and Get Values from HMI and set the product code from HMI to Var1
Max_Index_Number = 16
Operator_Entry = PointGet("PRODUCT_CODE_ENTRY")
Var1 = PointGet("Letter"&"_PRODUCT_CODES"&"[Index]")


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

Check_Test:

If Var1 = Operator_Entry Then
Screen_Location = "Letter"&" "&"Manifold"
Index_Number = Index

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
 
@dbh6
not quite what I meant, make a temp string call it Temp then

Temp = "Letter"&"_PRODUCT_CODES"&"[Index]"

then

Var1 = PointGet(Temp)
 
Last edited:
@ Max i made edits to Temp = "Letter"&"_PRODUCT_CODES"&"[Index]"
instead of using Index as the one in square brackets i put Index_number because thats the one incrementing in the loop, but still the error exists.

Here is the edited code:

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

'Initialize values and Get Values from HMI and set the product code from HMI to Var1
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:
Temp = "Letter"&"_PRODUCT_CODES"&"[Index_number]"
Var1 = PointGet(Temp)
If Var1 = Operator_Entry Then
Screen_Location = "Letter"&" "&"Manifold"
Index_Number = Index

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
 
does the system have a debug window? if it does look at what the variable Temp is actually containing. If it is exactly what you expect then I am at a loss here, the pointget function may only take a hard codeded string, do you have the code for pointget? Ive used gwbasic, qbasic, darkbasic, basic and VB. have not seen this function before, so not sure how or what it's call is supposed to contain.
 
@dbh6 sorry looked at the bmp and I think I saw it

"Letter"&"_PRODUCT_CODES"&"[Index_number]" needs to be
"Letter"&"_PRODUCT_CODES"&"["&Index_number&"]"
 
Last edited:
I tried what you said, i actually had high hopes it would work, but this time around it threw a different error when i complied it as opposed to running it, the posts prior to this were errors when i tried to run it, however the compiling was fine.

Their is a utility through which you can watch the value of a variable however you have to be running the script first. If your not running it won't work, so im kind of in the gutter cause the error is preventing it from running

I attached the latest pic
 
and the PointGet() function is specific to the HMI i'am using, i don't think its available as a function to the standard basic programming language, but all it does is get the current value from the HMI tags and brings it into a variable that you specific with the = sign in basic so in our case Var1 would have whatever value the PointGet got from the HMI tag specified in the argument in parenthesis, again in our case the value in the parenthesis would evaluate to F1_PRODUCT_CODES[1]..... depending on what iteration it is, but i'm sure you already know that
 
@dbh6 this is a bear, the index is a number and this version of basic will not convert it to a string. the quotes are now right, but you will have to do another temp conversion of Index. Try this where you have &Index& replace it with &str$(Index)&

here is the basic function reference I just found onlne

platforma.astor.com.pl/files/getfile/id/4671
 
I added the code to convert the Index which is an Integer to a string and do the code. On a positive note it complied, but threw a different error when trying to Run. Notice the error which points to the line where Var1 gets written to and also on the error it show that a point is not configured for Letter_PRODUCT_CODES ???

I attached the latest picture

Thanks on the reference manual, their is a help file within the software with that has the same info but thanks anyway, ill keep digging
 
@dbh6
"Letter"&"_PRODUCT_CODES"&"["&Index_number&"]" needs to be
Letter&"_PRODUCT_CODES"&"["&Index_number&"]"

this is why I hate concatenation, got to have those paragraph marks right!
 
Last edited:

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,204
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,444
Anyone know what the little green triangle on SCREEN 3 means ? See picture Thanks
Replies
2
Views
459
Back
Top Bottom