Create Vb Script For Total Price With Scale 追蹤

0

I am trying to create a VB script to calculate the Total Price from data coming from a scale connected through a serial port and a price per lb entered in an access database.  Both the Total Price and Price Per Lb are setup as Currency as the data type in text properties. 

 

If I set the data type as number in the text properties of the weight coming from the scale, I get a type mismathc error "string" when doing the calculation "value = weight * priceperlb" in the VB script under data source of the total price.

 

If I set the data type to text in the text properties of the weight coming in from the scale, I don't get a type mismatch error, but instead I lose the second digit after the decimal.  A weight of 1.25 becomes 1.3 and calculates the total price based on 1.3.

 

I am at a lose.  I have tried convert to strings and other types of formats with no success.  I'm not fluent in Visual Basic scripting, but I am sure there is a way to do it. 

 

Any help would be appreciated.

1 意見

0
Avatar
Fernando Ramos Miracle
版主
評論操作 永久連結

Hello Fubolz,

 

*Could you attach a simplified version of your document so I can take a look at what exactly you are trying to do?

 

In any case, from your description I've got a couple suggestions for your to try:

 

1. When referencing a named data source (named substring in old versions) please try using the full reference, not only its name: Format.NamedSubStrings("<Name>").Value

 

2. If you are multiplying different values that are initially strings of text, you'll need to convert them to a numeric value. As you want to maintain the decimal values you'll need to convert the value to a "double" type number using the CDbl() function.

 

Regards.

登入寫評論。