Jump to content

0,1 instead of 0.1


Zerosurf
 Share

Recommended Posts

if you type 15,5 then everything after the "," will be ignored - how can I change that?

so if I type 15,5 or 15.5 the result should be the same!

here´s the script:

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Marco Torskyj
; Script Function:
;   Umrechnung von Konzentrationen in Flüssigkeiten
;
; ----------------------------------------------------------------------------


#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

GuiCreate("Konzentrations-Umrechner", 290, 195,(@DesktopWidth-392)/2, (@DesktopHeight-311)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$ml = GUICtrlCreateInput("", 15, 5, 100, 20)
GUICtrlCreateLabel("- Gewünschte Menge", 125, 8, 200, 20)

$h = GUICtrlCreateInput("", 15, 30, 100, 20)
GUICtrlCreateLabel("% - Ausgangskonzentration", 125, 33, 200, 20)

$n = GUICtrlCreateInput("", 15, 55, 100, 20)
GUICtrlCreateLabel("% - Gewünschte Konzentration", 125, 58, 200, 20)

GUICtrlCreateLabel("(Bitte Dezimalpunkt 0.0 verwenden - kein Beistrich 0,0!)", 15, 80, 290, 25)

GUICtrlCreateLabel("Menge der Ausgangskonzentration:", 15, 110, 200, 25)
$hml = GUICtrlCreateLabel("", 190, 110, 200, 25)

GUICtrlCreateLabel("Menge des Lösungsmittels:", 15, 140, 200, 25)
$nml = GUICtrlCreateLabel("", 190, 140, 200, 25)


$calc = GUICtrlCreateButton("Berechnen", 40, 165, 80, 20)
GUICtrlSetOnEvent(-1, "calculate")

$cancel = GUICtrlCreateButton("Ende", 160, 165, 80, 20)
GUICtrlSetOnEvent(-1, "close")

func calculate()
   if GUICtrlRead($ml) = "" then
      msgbox(0, "Achtung!!!", "Keine Angabe der gewünschten Menge!", 10)
   Elseif GUICtrlRead($h) = "" then
      msgbox(0, "Achtung!!!", "Keine Angabe der Ausgangskonzentration!", 10)
   Elseif GUICtrlRead($n) = "" then
      msgbox(0, "Achtung!!!", "Keine Angabe der gewünschten Konzentration!", 10)
   Elseif GUICtrlRead($n) > GUICtrlRead($h) then
      msgbox(0, "Achtung!!!", "Gewünschte Konzentration muß kleiner sein!", 10)
   Else
      $calhml = GUICtrlRead($ml) * GUICtrlRead($n)
      $calchml = $calhml / GUICtrlRead($h)
      $calcnml = GUICtrlRead($ml) - $calchml
      
      GUICtrlSetData($hml, "" & Round($calchml,3))
      GUICtrlSetData($nml, "" & round($calcnml,3))
   EndIf
EndFunc   

func close()
   msgbox(64, "Thanks...", "for using Konzentrations-Umrechner" & @CRLF & "" & @CRLF & "Written by Marco TORSKYJ" & @CRLF & "" & @CRLF & "Supported by" & @CRLF & "Dr. Karl-Heinz STADLBAUER", 5)
   Exit
endfunc

GuiSetState()
While 1
   $msg = GuiGetMsg()
   Select
   Case $msg = $GUI_EVENT_CLOSE
      ExitLoop
   Case Else
    ;;;
   EndSelect
WEnd
Exit

thx.i.a. Zerosurf

Link to comment
Share on other sites

Fixed origional code:

CODE

; ----------------------------------------------------------------------------

;

; AutoIt Version: 3.1.0

; Author: Marco Torskyj

; Script Function:

; Umrechnung von Konzentrationen in Flüssigkeiten

;

; ----------------------------------------------------------------------------

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

GuiCreate("Konzentrations-Umrechner", 290, 195,(@DesktopWidth-392)/2, (@DesktopHeight-311)/2

, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$ml = GUICtrlCreateInput("", 15, 5, 100, 20)

GUICtrlCreateLabel("- Gewünschte Menge", 125, 8, 200, 20)

$h = GUICtrlCreateInput("", 15, 30, 100, 20)

GUICtrlCreateLabel("% - Ausgangskonzentration", 125, 33, 200, 20)

$n = GUICtrlCreateInput("", 15, 55, 100, 20)

GUICtrlCreateLabel("% - Gewünschte Konzentration", 125, 58, 200, 20)

GUICtrlCreateLabel("(Bitte Dezimalpunkt 0.0 verwenden - kein Beistrich 0,0!)", 15, 80, 290,

25)

GUICtrlCreateLabel("Menge der Ausgangskonzentration:", 15, 110, 200, 25)

$hml = GUICtrlCreateLabel("", 190, 110, 200, 25)

GUICtrlCreateLabel("Menge des Lösungsmittels:", 15, 140, 200, 25)

$nml = GUICtrlCreateLabel("", 190, 140, 200, 25)

$calc = GUICtrlCreateButton("Berechnen", 40, 165, 80, 20)

GUICtrlSetOnEvent(-1, "calculate")

$cancel = GUICtrlCreateButton("Ende", 160, 165, 80, 20)

GUICtrlSetOnEvent(-1, "close")

func calculate()

GUICtrlSetData ( $ml, _2903(GUICtrlRead($ml)))

GUICtrlSetData ( $n, _2903(GUICtrlRead($n)))

GUICtrlSetData ( $h, _2903(GUICtrlRead($h)))

if GUICtrlRead($ml) = "" then

msgbox(0, "Achtung!!!", "Keine Angabe der gewünschten Menge!", 10)

Elseif GUICtrlRead($h) = "" then

msgbox(0, "Achtung!!!", "Keine Angabe der Ausgangskonzentration!", 10)

Elseif GUICtrlRead($n) = "" then

msgbox(0, "Achtung!!!", "Keine Angabe der gewünschten Konzentration!", 10)

Elseif GUICtrlRead($n) > GUICtrlRead($h) then

msgbox(0, "Achtung!!!", "Gewünschte Konzentration muß kleiner sein!", 10)

Else

$calhml = GUICtrlRead($ml) * GUICtrlRead($n)

$calchml = $calhml / GUICtrlRead($h)

$calcnml = GUICtrlRead($ml) - $calchml

GUICtrlSetData($hml, "" & Round($calchml,3))

GUICtrlSetData($nml, "" & round($calcnml,3))

EndIf

EndFunc

func close()

msgbox(64, "Thanks...", "for using Konzentrations-Umrechner" & @CRLF & "" & @CRLF & "Written

by Marco TORSKYJ" & @CRLF & "" & @CRLF & "Supported by" & @CRLF & "Dr. Karl-Heinz

STADLBAUER", 5)

Exit

endfunc

func _2903($0)

Return StringReplace($0, ",", ".")

endfunc

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

;;;

EndSelect

WEnd

Exit

(Unfixed code) Translated into engrish:

CODE

; ----------------------------------------------------------------------------

;

; AutoIt Version: 3.1.0

; Author: Marco Torskyj

; Script Function:

; Conversion of concentrations in liquids

;

; ----------------------------------------------------------------------------

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

GuiCreate("Konzentrations-Umrechner", 290, 195,(@DesktopWidth-392)/2, (@DesktopHeight-311)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$ml = GUICtrlCreateInput("", 15, 5, 100, 20)

GUICtrlCreateLabel("- Desired quantity", 125, 8, 200, 20)

$h = GUICtrlCreateInput("", 15, 30, 100, 20)

GUICtrlCreateLabel("% - Initial concentration", 125, 33, 200, 20)

$n = GUICtrlCreateInput("", 15, 55, 100, 20)

GUICtrlCreateLabel("% - Desired concentration", 125, 58, 200, 20)

GUICtrlCreateLabel("(Please use decimal point 0,0 - no comma 0,0!)", 15, 80, 290, 25)

GUICtrlCreateLabel("Quantity of the initial concentration:", 15, 110, 200, 25)

$hml = GUICtrlCreateLabel("", 190, 110, 200, 25)

GUICtrlCreateLabel("Quantity of the solvent:", 15, 140, 200, 25)

$nml = GUICtrlCreateLabel("", 190, 140, 200, 25)

$calc = GUICtrlCreateButton("Compute", 40, 165, 80, 20)

GUICtrlSetOnEvent(-1, "calculate")

$cancel = GUICtrlCreateButton("End", 160, 165, 80, 20)

GUICtrlSetOnEvent(-1, "close")

func calculate()

if GUICtrlRead($ml) = "" then

msgbox(0, "Achtung!!!", "No indication of the desired quantity!", 10)

Elseif GUICtrlRead($h) = "" then

msgbox(0, "Achtung!!!", "No indication of the initial concentration!", 10)

Elseif GUICtrlRead($n) = "" then

msgbox(0, "Achtung!!!", "No indication of the desired concentration!", 10)

Elseif GUICtrlRead($n) > GUICtrlRead($h) then

msgbox(0, "Achtung!!!", "Desired concentration must be smaller!", 10)

Else

$calhml = GUICtrlRead($ml) * GUICtrlRead($n)

$calchml = $calhml / GUICtrlRead($h)

$calcnml = GUICtrlRead($ml) - $calchml

GUICtrlSetData($hml, "" & Round($calchml,3))

GUICtrlSetData($nml, "" & round($calcnml,3))

EndIf

EndFunc

func close()

msgbox(64, "Thanks...", "for using Konzentrations-Umrechner" & @CRLF & "" & @CRLF & "Written by Marco TORSKYJ" & @CRLF & "" & @CRLF & "Supported by" & @CRLF & "Dr. Karl-Heinz STADLBAUER", 5)

Exit

endfunc

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

;;;

EndSelect

WEnd

Exit

Edited by ligenza
Link to comment
Share on other sites

Does ligenza's code work for you?

As an alternative to converting the values in all GUI fields to use decimal points before performing calculations, you could create new variables holding the data in a format that AutoIt can manipulate:

; $mlVal holds the value entered into the $ml text field, etc.
 $mlVal = number(stringReplace(GUICtrlRead($ml), ",", "."))
 $hVal = number(stringReplace(GUICtrlRead($h), ",", "."))
$nVal = number(stringReplace(GUICtrlRead($n), ",", "."))
 
; Perform the calculations
 $calhml = $mlVal * $nVal
      $calchml = $calhml / $hVal
      $calcnml = $mlVal - $calchml
      
; Compute the data to be *displayed*
; (round the result and convert periods to commas)
 $hmlVal = stringReplace(string(round($calchml, 3)), ".", ",")
 $nmlVal = stringReplace(string(round($calcnml, 3)), ".", ",")
 
; Update the GUI
 guiCtrlSetData($hml, $hmlVal)
      guiCtrlSetData($nml, $nmlVal)
Edited by LxP
Link to comment
Share on other sites

Does ligenza's code work for you?

As an alternative to converting the values in all GUI fields to use decimal points before performing calculations, you could create new variables holding the data in a format that AutoIt can manipulate:

$mlVal = number(stringReplace(GUICtrlRead($ml), ",", "."))
 $hVal = number(stringReplace(GUICtrlRead($h), ",", "."))
$nVal = number(stringReplace(GUICtrlRead($n), ",", "."))
 
 $calhml = $mlVal * $nVal
      $calchml = $calhml / $hVal
      $calcnml = $mlVal - $calchml
      
$hmlVal = stringReplace(string(round($calchml, 3)), ".", ",")
 $nmlVal = stringReplace(string(round($calcnml, 3)), ".", ",")
 
 guiCtrlSetData($hml, $hmlVal)
      guiCtrlSetData($nml, $nmlVal)
That´s exactly what I was looking for!

Could you please explain the addon "Val" and the "number"

Many Thx!

Zerosurf

Edited by Zerosurf
Link to comment
Share on other sites

No problem -- I used (for an example) $mlVal to hold the value of $ml (I did this to entirely separate the data from the GUI). The Number() and String() functions perform internal conversion of the data to the appropriate type. (You may find that these calls are not necessary because AutoIt should automatically do this according to the situation. I added them just to be sure.) ;)

Edit: I have added comments to the code from my previous post if you are interested.

Edited by LxP
Link to comment
Share on other sites

@LxP:

You´re the best!

Many THX again!

Now I´m starting to understand... ;-)

Zerosurf

No problem -- I used (for an example) $mlVal to hold the value of $ml (I did this to entirely separate the data from the GUI). The Number() and String() functions perform internal conversion of the data to the appropriate type. (You may find that these calls are not necessary because AutoIt should automatically do this according to the situation. I added them just to be sure.) ;)

Edit: I have added comments to the code from my previous post if you are interested.

Link to comment
Share on other sites

@LxP:

You´re the best!

Many THX again!

Now I´m starting to understand... ;-)

Zerosurf

You are a total idiot. My code did exactly what LxP's code did. Did you EVEN try to run it? Wow.

GUICtrlSetData ( $ml, _2903(GUICtrlRead($ml)))

GUICtrlSetData ( $n, _2903(GUICtrlRead($n)))

GUICtrlSetData ( $h, _2903(GUICtrlRead($h)))

func _2903($0)

Return StringReplace($0, ",", ".")

endfunc

This is NO different from what he posted..

$mlVal = number(stringReplace(GUICtrlRead($ml), ",", "."))
$hVal = number(stringReplace(GUICtrlRead($h), ",", "."))
$nVal = number(stringReplace(GUICtrlRead($n), ",", "."))

Mine is just more modular and doesn't use variables.

Edited by ligenza
Link to comment
Share on other sites

This is NO different from what he posted..

It's actually completely different. LxP stated that he was using a different paradigm, one where the storage of the data was de-coupled from the display of the data. This is a perfect acceptable approach and a good approach because it doesn't force the storage into relying on the display. The data is stored how the data needs to be stored and its displayed how it needs to be displayed. Being the programming expert you tout yourself to be, you should realize this and be enthralled that somebody is using good design paradigms.
Link to comment
Share on other sites

It's actually completely different. LxP stated that he was using a different paradigm, one where the storage of the data was de-coupled from the display of the data. This is a perfect acceptable approach and a good approach because it doesn't force the storage into relying on the display. The data is stored how the data needs to be stored and its displayed how it needs to be displayed. Being the programming expert you tout yourself to be, you should realize this and be enthralled that somebody is using good design paradigms.

Way to misquite me idiot.

Mine is just more modular and doesn't use variables.

You're amazingly unintelligent.

As I've said before, examples are just that examples. If you want good code I'll direct you to my paypal account. What I posted was what the OP asked for, a (quick) solution to a problem. You should be enthralled by your ignorance.

I don't "tout" myself to be anything. I still get a nice fat paycheck with or without your holy approval. The entertainment value is lost without a little baiting however. Thanks for biting.

Edited by ligenza
Link to comment
Share on other sites

Way to misquite me idiot.

You're amazingly unintelligent.

As I've said before, examples are just that examples. If you want good code I'll direct you to my paypal account. What I posted was what the OP asked for, a solution to a problem. You should be enthralled by your ignorance.

I don't "tout" myself to be anything. I still get a nice fat paycheck with or without your holy approval. The entertainment value is lost without a little baiting however. Thanks for biting.

are you this much of a dick in real life to?

[right][font="Courier New"]...Run these streets all day, I can sleep when I die.[/font] [/right]

Link to comment
Share on other sites

As I've said before, examples are just that examples.

It's perfect that you say that. You see, you went off bashing LxP's code as doing the same thing as yours but LxP's code was an example of a different approach. To even question it was pointless because as you've said before, examples are just that examples. LxP demonstrated a different way to do the same thing and without people doing that, nobody would be learning new things.

What I posted was what the OP asked for, a (quick) solution to a problem.

Is there a point to this? So you provided a solution. LxP provided a different solution. I don't recall reading the rule "Only one solution conforming exactly to the OP's request". After all, I didn't see the OP asking for attitude with the answer and you provided quite a bit of that in this thread.

I don't "tout" myself to be anything.

Oh really? Then what's that PayPal comment supposed to mean? What about all your comments that people are idiots? In your world, do such comments not imply some form of superiority complex?

I still get a nice fat paycheck with or without your holy approval.

Again with the "fat paycheck" comment. I've seen this from you before. Does this have some sort of bearing on... anything?

The entertainment value is lost without a little baiting however. Thanks for biting.

Yes, entertainment is lost. You grew boring days ago. I thought perhaps there was some redeeming quality to your presence on the forum in the form of the brand of entertainment I enjoy, however, I like a little sport and you just shoot caged animals. No fun at all.
Link to comment
Share on other sites

It's perfect that you say that. You see, you went off bashing LxP's code as doing the same thing as yours but LxP's code was an example of a different approach.

I said it did the same thing and yes it was a different approach. I never bashed LxP. I accused the origonal poster of being an idiot. You are a #$*(#. Can't understand what I type eh? Maybe I should stop translating it into english.

To even question it was pointless because as you've said before, examples are just that examples. LxP demonstrated a different way to do the same thing and without people doing that, nobody would be learning new things.

Hence why I never said anything bad about LxP? #(*$

Is there a point to this? So you provided a solution. LxP provided a different solution. I don't recall reading the rule "Only one solution conforming exactly to the OP's request". After all, I didn't see the OP asking for attitude with the answer and you provided quite a bit of that in this thread.

My answer had nothing except a translated into english version so morons like you could understand and my solution tot he program. So yeah *(#$ you. You provided the attitude. Go back to your cage.

Oh really? Then what's that PayPal comment supposed to mean?

It means I am better than you. Sorry.

What about all your comments that people are idiots? In your world, do such comments not imply some form of superiority complex?

Yeah they don't. You are an idiot.

Again with the "fat paycheck" comment. I've seen this from you before. Does this have some sort of bearing on... anything?

No.

Yes, entertainment is lost.

It was lost, you revived it. Thanks.

You grew boring days ago. I thought perhaps there was some redeeming quality to your presence on the forum in the form of the brand of entertainment I enjoy

Sadly the entertainment is at your expense, I'm amazed you lasted this long.

, however, I like a little sport and you just shoot caged animals. No fun at all.

I agree, go back to your cage.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...