[SOLVED ]Maybe trivial, but I can't

Hi group, I have to take a currency value from a textbox, subtract it from another value obtained in the same way, and rewrite it on a third textbox. I thought it was easy, but somewhere I make a mistake and I don’t find the mistake.

Dim NFC as currency
Dim NFF as currency
Dim LFC as currency
Dim LFF as currency


NFC=textNettoCliente.Text.ToDouble
NFF=TextNettoFornitore.Text.ToDouble

LFC=TextLordoCliente.text.ToDouble
LFF=TextLordoFornitore.text.ToDouble

TextDifferenzaNetti.Text =currency.ToString(NFC-NFF).ToText
TextDifferenzaLordi.text =currency.ToString(LFC-LFF).ToText

It marks me error in the last two lines

You could try

currency(NFC-NFF).ToText

or use an intermediary variable like
var diff as currency
diff = NFC-NFF
TextDifferenzaNetti.Text =diff.ToText

Yes, I used an intermediate variable, but I’m sorry I can’t directly use the values ​​I need …

Dim a as currency
a=NFC-NFF
TextDifferenzaNetti.Text =a.ToText
a=LFC-LFF
TextDifferenzaLordi.text =a.ToText

TextDifferenzaNetti.Text = Ctype(NFC - NFF, Currency).ToString
TextDifferenzaLordi.text = Ctype(LFC - LFF, Currency).ToString

No need for NFC, NFF, LFC, LFF if you use this:

TextDifferenzaNetti.Text = CType(currency.FromString(textNettoCliente.Text) - currency.FromString(TextNettoFornitore.Text),currency).ToString
TextDifferenzaLordi.Text = CType(currency.FromString(TextLordoCliente.Text) - currency.FromString(TextLordoFornitore.Text),currency).ToString

Ok it’s work fine.

And the winner for most unmaintainable, hardest to debug source code goes to…!

(I have every respect for you and only make this joke because I know you were just trying to make it as short as possible)

3 Likes

Hahaha, thank you Tim :rofl:

I read:

so I guessed Federico didn’t want to use any variable and just use the text from the TextFields.

Of course I will never use code like this :innocent:

2 Likes