Jump to content

Need advice on setting up the logic for script


Bert
 Share

Recommended Posts

I have a 4 tab GUI with 64 input controls on each tab laid out in a grid. They are named "yesterday", Today", Month to date", and "Year to date"

I have a button that is called "transfer data". When this button is pressed the following will happen:

  • All data from the 64 input controls in "Today" will be moved to "Yesterday".
  • All data from "Today" will be added to the "Month to date", unless it is the first of the Month. If it is the first, the data will be erased from "Month to date", then replaced by the data from "Today"
  • All data from "Today" will be added to the "Year to date", unless it is the first of the year. If it is the first, the data will be erased from "Year to date", then replaced by the data from "Today"
Normally they will be populated with numbers. In that scenario, it is easy to do. However they hit me with a requirement that has me puzzled. Here is my problem.

My client plans to use %, . , and other characters in the fields. I figure I can use stringinstr, along with other things to do it, but I'm stumped as far as the best way to go.

Some examples of what they might enter:

90%

%90

14 sec

13.9

They may put the % in different places, and may use letters. I need to be able to add the numbers, but keep the rest intact when the information is handled from one field to another.

Thoughts?

Link to comment
Share on other sites

I have a 4 tab GUI with 64 input controls on each tab laid out in a grid. They are named "yesterday", Today", Month to date", and "Year to date"

I have a button that is called "transfer data". When this button is pressed the following will happen:

  • All data from the 64 input controls in "Today" will be moved to "Yesterday".
  • All data from "Today" will be added to the "Month to date", unless it is the first of the Month. If it is the first, the data will be erased from "Month to date", then replaced by the data from "Today"
  • All data from "Today" will be added to the "Year to date", unless it is the first of the year. If it is the first, the data will be erased from "Year to date", then replaced by the data from "Today"
Normally they will be populated with numbers. In that scenario, it is easy to do. However they hit me with a requirement that has me puzzled. Here is my problem.

My client plans to use %, . , and other characters in the fields. I figure I can use stringinstr, along with other things to do it, but I'm stumped as far as the best way to go.

Some examples of what they might enter:

90%

%90

14 sec

13.9

They may put the % in different places, and may use letters. I need to be able to add the numbers, but keep the rest intact when the information is handled from one field to another.

Thoughts?

you could use a regular expression test to identify the non numeric (except decimal) characters, and one that grabs the numeric/decimal characters. do the math on the numbers obviously, then do a stringinstr() to find out where to replace the rest... if the stringinstr() returns a 1, put them at the beginning, anything greater, concatenate to the end of the result...
Link to comment
Share on other sites

you could use a regular expression test to identify the non numeric (except decimal) characters, and one that grabs the numeric/decimal characters. do the math on the numbers obviously, then do a stringinstr() to find out where to replace the rest... if the stringinstr() returns a 1, put them at the beginning, anything greater, concatenate to the end of the result...

As cameronsdad said.

Here is clarify tip:

Use StringRegExpReplace() for eliminating non numeric chars.

I'm not RegExp expert so nothing more from me.

Link to comment
Share on other sites

As cameronsdad said.

Here is clarify tip:

Use StringRegExpReplace() for eliminating non numeric chars.

I'm not RegExp expert so nothing more from me.

actually, i don't think the OP wants to eliminate the non-numeric, just identify them, and then replace them after necessary additions etc. there's a tutorial in the help file (i'm sorry i don't remember who wrote it) that's a very good one on using regular expressions, that can help with building the expressions for my suggestion
Link to comment
Share on other sites

actually, i don't think the OP wants to eliminate the non-numeric, just identify them, and then replace them after necessary additions etc. there's a tutorial in the help file (i'm sorry i don't remember who wrote it) that's a very good one on using regular expressions, that can help with building the expressions for my suggestion

That is exactly what I need to do.
Link to comment
Share on other sites

This doesn't sound that hard if I understand you correctly. What I'd suggest is using StringRegExp() to pull out the numbers. Once you have the numbers, add them or do whatever it is you need to do to them. Then use StringReplace() or something to replace the original number in the string with the newly calclated number.

Something like this should get you started in the right direction:

Main()

Func Main()
    Local $sOld = "52%"
    Local $sNew = "43%"
    Local $sPattern = "(\d*)"

    ConsoleWrite("Old Before: " & $sOld & @CRLF)
    ConsoleWrite("New Before: " & $sNew & @CRLF)
    ConsoleWrite(@CRLF)
    Local $aOld = StringRegExp($sOld, $sPattern, 1)
    Local $aNew = StringRegExp($sNew, $sPattern, 1)

    If UBound($aOld) = 1 And UBound($aNew) = 1 Then
        $sOld = StringReplace($sOld, $aOld[0], $aOld[0] + $aNew[0])
        $sNew = StringReplace($sNew, $aNew[0], $aOld[0] + $aNew[0])
    EndIf
    ConsoleWrite("Old After: " & $sOld & @CRLF)
    ConsoleWrite("New After: " & $sNew & @CRLF)
EndFunc ; Main()
Link to comment
Share on other sites

This is what I came up with when I designed a test script. It seems to do what I need. Thanks again for the suggestions.

#include <GuiConstants.au3>
GuiCreate("MyGUI", 327, 215,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$Input_1 = GuiCtrlCreateInput("", 40, 40, 80, 20)
$Input_2 = GuiCtrlCreateInput("", 180, 40, 90, 20)
$Button_3 = GuiCtrlCreateButton("add the 2 input boxes", 70, 100, 180, 20)
GUICtrlCreateLabel("string to search for",115, 175, 120, 20) 
$Input_4 = GuiCtrlCreateInput("", 110, 150, 90, 20)
$var = String(10)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_3
            $a = GUICtrlRead($Input_1)
            $b = GUICtrlRead($Input_2)
            $c = GUICtrlRead($Input_4)
            $len1 = StringLen($a)
            $len2 = StringLen($B)
            $len3 = StringLen($c)
            $str1 = StringInStr($a, $c)
            $str2 = StringInStr($b, $c)
            $d = StringRegExpReplace($a,$c,"")
            $e = StringRegExpReplace($b,$c,"")
            Select
                case $str1 >0 and $str2 = 0
                    if $str1=1 then MsgBox(0, "",$c&" "&$d+ $e )
                    if $str1>2 then MsgBox(0, "",$d + $e& " "&$c)
                case $str1 =0 and $str2 > 0 
                    if $str2=1 then MsgBox(0, "",$c&" "&$d+ $e )
                    if $str2>2 then MsgBox(0, "",$d + $e& " "&$c)
                case $str1 >0 and $str2 > 0 
                    if $str1=1 and $str2=1 then MsgBox(0, "",$c&" "&$d+ $e )
                    if $str1>2 and $str2>2 then MsgBox(0, "",$d + $e& " "&$c)
                    if $str1=1 and $str2>2 then MsgBox(0, "Error","Cell Formatting Mismatch. "&'"'&$c&'"'&" needs to be in the same place in both cells.")  
                    if $str1>2 and $str2=1 then MsgBox(0, "Error","Cell Formatting Mismatch. "&'"'&$c&'"'&" needs to be in the same place in both cells.")                      
                Case $str1 =0 and $str2 = 0 and $len3 > 0
                    MsgBox(0, "",$a + $b & @CRLF _
                    &@CRLF _
                    &"Possible adding error due to incorrect formatting")
                case $str1 =0 and $str2 = 0 and $len3 = 0                       
                    MsgBox(0, "",$a + $B)                   
            EndSelect
        Case Else
            ;;;
    EndSelect
WEnd
Exit
Edited by Volly
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...