Scaling in Visual Basic...

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Hi,

I wrote this in VB:


Dim AI As Integer
Dim Range As Double
Dim Offset As Double
Dim Resultaat As Double

Private Sub Calc_Click()
AI = Inpu.Text
Range = Rang.Text
Offset = Offs.Text
If AI = "" Or Range = "" Or Offset = "" Then Exit Sub
Resultaat = (AI / 27648) * Range + Offset
Resu.Text = Resultaat
End Sub


I try to run it and get:
Member allready exists in a object module from wich this object module derives

This is my first programm in Visual basic btw...

Tnx for any help
 
The first thing I see is that you are comparing a double with a string value where you check to see if the text boxes are empty.

Try it this way

if inpu.text="" OrElse Rang.text="" OrElse Offs.text="" then Exit sub

This should also be the first line in your calc_click sub.

I am assuming you are using VB.net
 
Try it this way...

Validate inputs, then convert the "text" (Strings) to the data type.



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

' validate input
If Inpu.Text <> "" And rang.Text <> "" And offst.Text <> "" Then

'convert to data type
AI = CInt(Inpu.Text)

Range =
CDbl(rang.Text)

Offset =
CDbl(offst.Text)

Resultaat = (AI / 27648) * Range + Offset

result.Text = Resultaat

Else

MessageBox.Show("Invalid input", "Whatcha doing")

End If





End Sub

 

Similar Topics

Hi, having some issues with scalings (SCP commands) with some Vegapuls 65 guided wave radar level transmitters. I've set the min/max in the...
Replies
5
Views
174
I want to measure the tank level and get the sensor output to the PLC. Below are the details : Tank Height =0 - 3m, the sensor is stalled 0,2m...
Replies
15
Views
630
Hi, I have a ControlLogix system with 1756-IF16 analogue inputs. I can't scale the inputs at the card as there is a requirement to facilitate...
Replies
14
Views
367
I know nothing about simaticnet OPC server. I do know Kepware. I would only ever scale raw to engineering in the PLC, but it is possible to scale...
Replies
5
Views
219
Hi all. I'm working on a rehab and I'm trying to figure stuff out. See screenshot at the bottom. Local:5:I.Data[6] in BTD instruction is a...
Replies
6
Views
715
Back
Top Bottom