Jump to content
HAA

[Solved] Variable in string doesn't work

Recommended Posts

HAA

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 by HAA

Share this post


Link to post
Share on other sites
Melba23

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 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
HAA

Hi M23,

I've also tried that, but it's actually same and does not work 

HAA

Share this post


Link to post
Share on other sites
Jos
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 by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
SlackerAl

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.

Share this post


Link to post
Share on other sites
HAA

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)

 

Share this post


Link to post
Share on other sites
HAA
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 

Share this post


Link to post
Share on other sites
Jos
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 by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Melba23

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

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
HAA
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. 

 

Share this post


Link to post
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

×