Barthezz88 Posted February 3, 2020 Share Posted February 3, 2020 Hello everybody, First of all my apologies for my english writing. I'm new to AutoIt3 and I have a question. I want to use a excel value in a external program. I created this code: #Include <MsgBoxConstants.au3> #Include <Excel.au3> #include <AutoItConstants.au3> $oExcel = _Excel_Open() $oWorkbook = $oExcel.ActiveWorkbook$fData = _Excel_RangeRead($oWorkbook,Default,"B2",4) MsgBox(0,"",$fData,1) ;just to check the value If Not WinExists("D-Sheet Piling") Then MsgBox($MB_ICONINFORMATION,"D-Sheet Piling","Er is geen D-Sheet model geopend") EndIf If WinExists("D-Sheet Piling") Then WinActivate("D-Sheet Piling") WinWaitActive("D-Sheet Piling") Send("!l") Send ("h") WinWaitActive("Horizontal Forces") Send("{TAB 3}") Send("{END}") Send("{RIGHT 2}") Send($fData) Send("{TAB}") Send("{ENTER}") WinWait("[CLASS:TSHMainForm]") Send("{F9}") WinActive("[CLASS:TSHCalculationProgressForm]") Sleep(2000) Send("c") ;$oExcel = ObjGet("", "Excel.Application") ;$oExcel.Run("Error_1") EndIf Exit I read the value from cell "B2" out of Excel. I convert the value in a variable ($fData). Then I send this variable to a external program using 'Send'. Now there is the problem, if the value in "B2" is for example '201.6', and I send the value to my external program (using the presented code). Then the value '2016' is copied on the specific location in the external program. Wich is obvious wrong, I miss the comma in the value. Excel: External program: Can someone tell me what I'm doing wrong? I want to use a second variable en copied this one also in the external program. This is a much smaller (Level) value, so the margin of error is much bigger. I hope someone can help me with this problem.. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 3, 2020 Developers Share Posted February 3, 2020 Looks like you have a regional issue where the other program uses a decimal comma en excel a decimal point? Maybe try replacing the "." in the variable $fData with a ","? (Je Engels is prima hoor ) Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
water Posted February 3, 2020 Share Posted February 3, 2020 Your Excel uses "." and the other application needs a ",". Use something like this: #include <Excel.au3> Global $oExcel = _Excel_Open() Global $oWorkbook = $oExcel.ActiveWorkbook Global $fData = _Excel_RangeRead($oWorkbook, Default, "B2", 4) MsgBox(0, "", $fData & @CRLF & VarGetType($fData)) $fData = StringReplace($fData, ".", ",") MsgBox(0, "", $fData & @CRLF & VarGetType($fData)) Thes MsgBox statements are just for debugging - can be removed when everything works as expected. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted February 3, 2020 Share Posted February 3, 2020 BTW: When posting code, please use the AutoIt code tags in the editor (the "<>" button) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Barthezz88 Posted February 3, 2020 Author Share Posted February 3, 2020 The solution supplied by water does the trick. Thanks for the help. Can you explain what exactly happen in the code? @Jos, bedankt hoor.. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 3, 2020 Developers Share Posted February 3, 2020 4 minutes ago, Barthezz88 said: Can you explain what exactly happen in the code? This was described by both me and Water already. Just look at the statements and press F1 in SciTE on any function you do not understand or want to know more about. Js SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nine Posted February 3, 2020 Share Posted February 3, 2020 (edited) If you prefer, you can change the workbook settings globally so you don't have to do lots of StringReplace : #include <Constants.au3> #include <Excel.au3> Opt ("MustDeclareVars", 1) Local $oExcel = _Excel_Open() Local $sWorkbook = @ScriptDir & "\Test.xls" Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error open") $oExcel.DecimalSeparator = "," $oExcel.ThousandsSeparator = "" $oExcel.UseSystemSeparators = False Edited February 3, 2020 by Nine water 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 3, 2020 Moderators Share Posted February 3, 2020 Moved to the appropriate forum. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! 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