AdvancedHMI Software
General Category => Support Questions => Topic started by: Darrell on August 03, 2016, 09:13:05 PM
-
I have built a Hmi that I use to read different modbus addresses from time to time on different PLC's
Added code to the button to read the text box and change modbus address in the corresponding PilotLight plc address along with the text label so I know what address is being read to turn on the pilot light ,
PilotLight1.PLCAddressValue = TextBox1.Text
PilotLight1.Text = PilotLight1.PLCAddressValue
my question is how can I easily add a button that would populate all my text boxes at once and increment each one by 1 or .1. 40001 , 40002, or 40001.1 , 40001.2 etc
Darrell
-
You want them to increment regularly once you pressed on the button, or increment only one time, each time you press the button ?
The base is the same, the difference is that in the first case the code will be with a timer, and pressing the button (click event) enables the timer.
In the second option, the code is directly at click event.
You should have to go through all you text boxes. If they are all directly included to your form it's quite simple with a For Each :
Now that you have every text box, I suppose that you have to go to a ToInt (or something like that..), so that you can increment the value. And then put it again as a String (of 5 digits, to be sure to get the 00001 PLC adresses OK too).
For Each txtzone in MyForm.Controls
If txtzone.type Is textboxe.type Then
Dim Address as Int = Convert.ToInt32(txtzone.text) + 1
Dim newText =Address.ToString("D5")
txtzone.txt = newText
End If
Next txtzone
-
What I would like to do is populate lets say textBox 1 through 15 with a number all at once , but increment each one by 1 or .1 . This HMI will not be left permanently on any machine , it is strictly for someone use to setup and monitor modbus comms during commissioning of systems . Trying to make something that can easily moved around without having to create new HMI's for every one.
Darrell
-
Ah okay understand now. :)
It's almost the same principle :
Dim baseAddressStr As String = "40000"
For Each txtzone in MyForm.Controls
If txtzone.type Is textbox.type Then
Dim newAddressInt as Int = Convert.ToInt32(baseAddress) + 1
baseAddressStr =Address.ToString("D5")
txtzone.txt = baseAddress
End If
Next txtzone
This is going to populate all you text boxes with an adress.
You can add a second button to change those addresses for a .1 increment easily :
Dim baseAddress As string = "40000"
For Each txtzone in MyForm.Controls
If txtzone.type Is textbox.type Then
Dim Address as Int = Convert.ToInt32(txtzone.text) + 0.1
txtzone.txt =Address.ToString("D5")
End If
Next txtzone
-
I get this error and really don't know what it means
-
Oh my bad, I should have opened Visual Studio to see the exact methods to call.
Here is the right way to right it :
If textzone.GetType = GetType(TextBox) Then
...
End If
... ".Type" do not exist actually. ^_^