Bert Posted January 2, 2007 Share Posted January 2, 2007 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%%9014 sec13.9They 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? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
seandisanti Posted January 2, 2007 Share Posted January 2, 2007 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%%9014 sec13.9They 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 More sharing options...
Zedna Posted January 2, 2007 Share Posted January 2, 2007 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. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
seandisanti Posted January 2, 2007 Share Posted January 2, 2007 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 More sharing options...
Bert Posted January 2, 2007 Author Share Posted January 2, 2007 Thanks for the suggestions. Hopefully I can make this work without too much trouble. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted January 2, 2007 Author Share Posted January 2, 2007 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 suggestionThat is exactly what I need to do. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Valik Posted January 2, 2007 Share Posted January 2, 2007 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 More sharing options...
Bert Posted January 2, 2007 Author Share Posted January 2, 2007 That will help alot. Thank you Valik. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted January 3, 2007 Author Share Posted January 3, 2007 (edited) 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. expandcollapse popup#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 January 3, 2007 by Volly The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now