Scaling in Visual Basic...

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 everyone, I am currently trying to communicate a Rockwell Automation 1756-L81E ControlLogix PLC with an Omron DRT1-COM RTU through a 1756-DNB...
9
Replies
348
Views
I need to scale a photo cell 1/5v 250 FC TO a P2-04AD 0/5 volt. And I’m missing something. Can anyone help? Thanks.
11
Replies
447
Views
Hi there! I can't quite seem to make the APR function work. Just as a proof of concept, I have made it scale from 4-20mA to 0-100%. The function...
4
Replies
437
Views
Not sure what I’m doing wrong I’m using the scp to scale my vfd and my pv is my analog signal from my level transmitter and set point is 50...
6
Replies
554
Views
I am hoping I can get help for a better understanding on servo scaling. I have done a few servos, but they were always simple rotary's with...
6
Replies
719
Views
Top