Author Topic: write to a file test.txt in a specific location ?  (Read 2400 times)

ALFADELTA

  • Newbie
  • *
  • Posts: 19
write to a file test.txt in a specific location ?
« on: February 21, 2021, 09:08:28 AM »
Hi

write in a file test.txt , but what I want to do is to write in a specific location

example:

when I say : sol sur [0..9]

wrto(------,236) 

when I say " sol sur 121.25" VA change "------" by 121.25

it can be ------- or any other number

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4758
  • RTFM
Re: write to a file test.txt in a specific location ?
« Reply #1 on: February 21, 2021, 03:24:35 PM »
If at all possible, a much simpler option would be to write all values in one go.

Slightly more complex would be to replace the exact existing value (assuming you have that value stored somewhere by itself), E.G. using the "Replace with" option of the "Set a Text Value" action.

Otherwise, you're going to need to get the text before and after the section you want to replace (using the "{TXTPOS:}" token to get the locations of the "(" and "," characters, for example), so you can insert the new value between them (assuming you're using native actions).

ALFADELTA

  • Newbie
  • *
  • Posts: 19
Re: write to a file test.txt in a specific location ?
« Reply #2 on: February 22, 2021, 02:32:59 AM »
Otherwise, you're going to need to get the text before and after the section you want to replace (using the "{TXTPOS:}" token to get the locations of the "(" and "," characters, for example), so you can insert the new value between them (assuming you're using native actions).

sorry Pfile but how to do that?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4758
  • RTFM
Re: write to a file test.txt in a specific location ?
« Reply #3 on: February 22, 2021, 02:48:17 AM »
Could be done using something like
Code: [Select]
Set text [~fileContents] to [C:\text.txt]
Set text [~textToInsert] to '121.25'
Write (overwrite), '{TXTSUBSTR:~fileContents:0:{EXP:{TXTPOS:"(":~fileContents:0}+1}}{TXT:~textToInsert}{TXTSUBSTR:~fileContents:{TXTPOS:",":~fileContents:0}:}' to file 'C:\...


You'll want to read up on more advanced topics like tokens, especially if you have further need for them.

Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, which contains information on VoiceAttack's features.

These topics may also be of use:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up

ALFADELTA

  • Newbie
  • *
  • Posts: 19
Re: write to a file test.txt in a specific location ?
« Reply #4 on: February 22, 2021, 03:38:46 AM »
Could be done using something like
Code: [Select]
Set text [~fileContents] to [C:\text.txt]
Set text [~textToInsert] to '121.25'
Write (overwrite), '{TXTSUBSTR:~fileContents:0:{EXP:{TXTPOS:"(":~fileContents:0}+1}}{TXT:~textToInsert}{TXTSUBSTR:~fileContents:{TXTPOS:",":~fileContents:0}:}' to file 'C:\...

with this instead of replacing (------, by (121.25,

this is the whole file that is erased replace by 121.25

what I want to do also is not only change with 121.25 but all that I will "order" when i say [0..9]

121.25 135.75 125.00 etc.....



Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4758
  • RTFM
Re: write to a file test.txt in a specific location ?
« Reply #5 on: February 22, 2021, 04:06:42 AM »
If the contents of your file are getting removed entirely, check that you have the command set up correctly.
"~fileContents" need to be set to, as the name suggests, the contents of the file you're writing to.


The value of "~textToInsert" will be inserted (again, as the name suggests) into the file, so you need to set that variable to the appropriate value.

To get a number from a spoken phrase, you can look into the "{TXTNUM:}" and "{CMD}" tokens.


Again, read the documentation on the features you're trying to use.

ALFADELTA

  • Newbie
  • *
  • Posts: 19
Re: write to a file test.txt in a specific location ?
« Reply #6 on: February 22, 2021, 12:16:13 PM »
it work when i say 110.25

but why is there a space

wrto(110 . 25,236)

Code: [Select]
Set text [~fileContents] to [C:\texte.txt]
Set text [~textToInsert] to '{CMD}'
Set integer [~textToInsert] value to the converted value of {TXTNUM:~textToInsert}
Quick Input, '{TXTNUM:~textToInsert}'
Write (overwrite), '{TXTSUBSTR:~fileContents:0:{EXP:{TXTPOS:"(":~fileContents:0}+1}}{TXT:~textToInsert}{TXTSUBSTR:~fileContents:{TXTPOS:",":~fileContents:0}:}' to file 'C:\...

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4758
  • RTFM
Re: write to a file test.txt in a specific location ?
« Reply #7 on: February 22, 2021, 01:59:32 PM »
You're writing the value of "{CMD}" to the file, instead of the value of '{TXTNUM:"{CMD}"}', which should parse it into a numeric value and remove the spaces.

VoiceAttack automatically inserts spaces between dynamic command sections, E.G. "[1].[1]" would be recognized as "1 . 1", not "1.1", so you need to remove those spaces, which the "{TXTNUM:}" token can do for you given that the input can be parsed as a number.

ALFADELTA

  • Newbie
  • *
  • Posts: 19
Re: write to a file test.txt in a specific location ?
« Reply #8 on: February 23, 2021, 11:22:30 AM »
Sorry Pfeil, but I'm mistaken about what I want to change.
I would like when i say COM1 sur 110.250 and VA would have to write in the file "text.txt" 10250 without the 1 "110.250" or the dot "."

or Is it possible to force voice attack to ignore some words, numbers ?

ps: I'm looking for voice attack help in French  :'(
« Last Edit: February 23, 2021, 01:10:59 PM by ALFADELTA »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4758
  • RTFM
Re: write to a file test.txt in a specific location ?
« Reply #9 on: February 23, 2021, 02:37:33 PM »
If you want to remove the period character, you can do exactly that using the "Replace with" feature of the "Set a Text Value" action, or the "{TXTREPLACEVAR:}" token, by replacing "." with "" (I.E. nothing)

Likewise, you could use the "{TXTSUBSTR:}" token remove the first character, by getting the remaining characters

E.G.
Code: [Select]
{TXTSUBSTR:"{TXTREPLACEVAR:"{TXTNUM:"{CMD}"}":".":""}":1:}

ALFADELTA

  • Newbie
  • *
  • Posts: 19
Re: write to a file test.txt in a specific location ?
« Reply #10 on: February 26, 2021, 07:25:59 AM »
Code: [Select]
{TXTSUBSTR:"{TXTREPLACEVAR:"{TXTNUM:"{CMD}"}":".":""}":1:}
sorry but how to do that, it's been two days that I've been looking for how I didn't find

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4758
  • RTFM
Re: write to a file test.txt in a specific location ?
« Reply #11 on: February 26, 2021, 07:58:41 AM »
You'd use that to set the value of "~textToInsert"...

ALFADELTA

  • Newbie
  • *
  • Posts: 19
Re: write to a file test.txt in a specific location ?
« Reply #12 on: February 26, 2021, 08:52:31 AM »
thank you very much