Floating-point to hmi to SQL (convert float to??)

kasperV

Member
Join Date
Jul 2007
Location
århus
Posts
8
Hi.
If this is the wrong forum i apologize..
inserting a Float value to sql...

I Got an Error in my scada system (indusoft, VBscripting)

I got the Error: Error to convert varchar to float. ive been reading alot of solution since its not?? possible to insert a float into sql, but none of them fits the syntax of VBscripting..

here is my insert script:

Dim sql
sql = "INSERT IGNORE INTO Table_1 VALUES(" & $TEST_C1_A & "," & $TEST_C2_A & ",'" & $TEST_C3_A & "','" & $TEST_C4_A & "','" & $TEST_C5_A & " Km/t" & "','" & $TEST_C6_A & "')"
$DBExecute("DB", sql,"",1000000000,"Status")
$reload = $reload+1

this tag ($TEST_C5_A) is a float how to convert it o_O
 
Why it would be not possible to insert Float to SQL? Is that some application dependent restriction as SQL has float datatype (float of some lenght) and better in plc use REAL datatype that is single precision floating point.
 
My best advice, is format everything explicitly for SQL first, paying attention to decimal/integer fields. I always format everything into a string:

Dim m_Min_Val_Act As String ' Float Value
Dim m_Min_Val_Ftg As String ' Integer Value

Set HMITag = {...} 'Float/Numeric SQL Field
m_Min_Val_Act = Format(HMITag.Value, #######0.####")

Set HMITag = {...} 'Integer SQL Field
m_Min_Val_Ftg = Format(HMITag.Value, "#######0")

sql = "INSERT IGNORE INTO MYTABLE VALUES(" & m_Min_Val_Act & "," & m_Min_Val_Ftg & ")"

The VB Format command is used above to force values into an appropriate representation for an ODBC (or OLE / ADO) driver to hand off to SQL without choking. For the float, it will always be presented as (at least) "0.0000", the integer will always be presented as (at least) "0" with no decimal points.
 
Couldnt get it to work that way, probely me..
So i tryid to change the tag in the tag database to a string

but it still see the "string" as a float??!!

Database: Error: Error converting data type varchar to float.(SQL: INSERT IGNORE INTO Table_1 VALUES(0,0,'','','232.3 Km/t','')) [03/22/2011, 12:07:33.964ms]
 
Well, what is SQL going to do with "km/t" ?

This is the correct question. "km/t" cannot be converted to a float. If you need the units included, then the data must be put in a field that will accept strings (after converting everything to strings).
 
i figured it out, I have a grid view that automatic creates the the sql table, and the specific column was set to decimal and not text as my string..

the km/h is just the unit i wanted
 

Similar Topics

How do you configure a basic label to read a pair of Modbus registers that contain a floating point number thanks in advance
Replies
4
Views
4,311
I have 2 RedLion Graphite HMI's where one is communicating with some remote I/O using Modbus TCP/IP protocol. I have a second Graphite that will...
Replies
2
Views
2,995
I need to check an axis actual travel position, and to compare it to the master travel position. To do this I have to multiply the axis travel...
Replies
6
Views
2,559
We have AOIs for projects, which handle material dosing (by hand or by pipes and pumps), obviously they have comparison between setpoint and...
Replies
50
Views
14,196
Hi eveyone. I need transfer signal from system 1 to DCS via modbus. System 1 only can send 32 bit floating point. DCS receive 16 bit integer. How...
Replies
20
Views
10,565
Back
Top Bottom