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 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
672
Hello all, First post here. Hitting a wall with finding info on this topic online, and none of my coworkers have a clue. I have a PanelView...
Replies
10
Views
1,290
Hello, We monitor the temperature of a pipe via a 4-20mA temperature transducer. This goes into DB135(Read Analog Inputs). The issue I have is the...
Replies
0
Views
615
5069 IF8 with a 4-20ma 0-100psi, sealed fixed, no calibration, transducer attached. IF8 is scaled 4ma= 0 psi, 20ma=100psi. If over time the...
Replies
12
Views
2,484
I have 1769-IF4 module and 1766 micrologix 1400 series B controller, when connecting Analogue input in module it's showing maximum values of...
Replies
4
Views
1,629
Back
Top Bottom