Jump to content

[Solved] Variable in string doesn't work


HAA
 Share

Recommended Posts

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

  • Moderators

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 $

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • Developers
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 etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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

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

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

  • Developers
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 etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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

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...