HAA Posted November 3, 2017 Share Posted November 3, 2017 (edited) I'm trying to write a line, which includes a variable to a file. I do get an answer via MsgBox but when I open the file and look at the line, variable has not been written into the file. #include <File.au3> AutoItSetOption("ExpandVarStrings", 1) $valuefile = @UserName $result = StringRegExp(FileRead("C:\tmp\Test.txt"),$valuefile & "\s=\s(.*)", 1) MsgBox(0, "", $result[0]) _FileWriteToLine("Q:\test\assi.config", 102, ' <setting name="PhoneInterfaceServiceProvider">$result$ (Aastra2380ip)</setting>', True) Edited November 15, 2017 by HAA Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 3, 2017 Moderators Share Posted November 3, 2017 (edited) HAA, Welcome to the AutoIt forums. You need to concatenate the strings like this: FileWriteToLine("Q:\test\assi.config", 102, ' <setting name="PhoneInterfaceServiceProvider">' & $result & ' (Aastra2380ip)</setting>', True) M23 Edited November 3, 2017 by Melba23 Removed extraneous $ Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
HAA Posted November 3, 2017 Author Share Posted November 3, 2017 Hi M23, I've also tried that, but it's actually same and does not work HAA Link to comment Share on other sites More sharing options...
Developers Jos Posted November 3, 2017 Developers Share Posted November 3, 2017 (edited) 11 minutes ago, HAA said: I've also tried that, but it's actually same No it isn't the same so show us the code you have now that still doesn't work. Jos Edited November 3, 2017 by 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...
SlackerAl Posted November 3, 2017 Share Posted November 3, 2017 I think you will also find that _FileWriteToLine("Q:\test\assi.config", 102, "whatever") requires that file to exist and to have at least the number of lines already in it that you have specified for the insert. Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
HAA Posted November 3, 2017 Author Share Posted November 3, 2017 Jos, I tried both ways and they are not working, besides I also removed a $ in the string from M23. here are the both: #include <File.au3> AutoItSetOption("ExpandVarStrings", 1) $valuefile = @UserName $result = StringRegExp(FileRead("C:\tmp\Test.txt"),$valuefile & "\s=\s(.*)", 1) MsgBox(0, "", $result[0]) _FileWriteToLine("Q:\test\assi.config", 102, ' <setting name="PhoneInterfaceServiceProvider">$result$ (Aastra2380ip)</setting>', True) and #include <File.au3> AutoItSetOption("ExpandVarStrings", 1) $valuefile = @UserName $result = StringRegExp(FileRead("C:\tmp\Test.txt"),$valuefile & "\s=\s(.*)", 1) MsgBox(0, "", $result[0]) _FileWriteToLine("Q:\test\assi.config", 102, ' <setting name="PhoneInterfaceServiceProvider">' & $result & ' (Aastra2380ip)</setting>', True) Link to comment Share on other sites More sharing options...
HAA Posted November 3, 2017 Author Share Posted November 3, 2017 4 minutes ago, SlackerAl said: I think you will also find that _FileWriteToLine("Q:\test\assi.config", 102, "whatever") requires that file to exist and to have at least the number of lines already in it that you have specified for the insert. the problem is I have the line withot the variable, which looks like that in the line 102 of my file: <setting name="PhoneInterfaceServiceProvider"> (Aastra2380ip)</setting> the line has been written without the variable Link to comment Share on other sites More sharing options...
Developers Jos Posted November 3, 2017 Developers Share Posted November 3, 2017 (edited) 21 minutes ago, HAA said: they are not working What isn't working? There's not much we can do with that statement. Post a running code snippet we can play with that demonstrates the issue so we can really help you. Jos Edited November 3, 2017 by 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...
Moderators Melba23 Posted November 3, 2017 Moderators Share Posted November 3, 2017 HAA, I missed it the first time, but StringRegExp with the $STR_REGEXPARRAYMATCH returns an array of matches - so just using the array name will not work. You need to define which element of that array you need - probably something like this: FileWriteToLine("Q:\test\assi.config", 102, ' <setting name="PhoneInterfaceServiceProvider">' & $result[0] & ' (Aastra2380ip)</setting>', True) M23 HAA 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
HAA Posted November 3, 2017 Author Share Posted November 3, 2017 2 minutes ago, Melba23 said: HAA, I missed it the first time, but StringRegExp with the $STR_REGEXPARRAYMATCH returns an array of matches - so just using the array name will not work. You need to define which element of that array you need - probably something like this: FileWriteToLine("Q:\test\assi.config", 102, ' <setting name="PhoneInterfaceServiceProvider">' & $result[0] & ' (Aastra2380ip)</setting>', True) M23 Thanks a lot M23 it worked great. 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