Jump to content

need some advice on filewiteline ?


n9mfk9
 Share

Recommended Posts

Hi everyone i need some advice

here my code were i need the help is im try to get all the data back in my output file

I have included my input output an what im looking for thanks

#include <String.au3>
#include <array.au3>
Dim $tag
Dim $tagname

$file = FileOpen("tagslist.txt", 0)
$fileout = FileOpen("myphp3.txt", 2)
;Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
   
    
    $aArray1 = _StringBetween($line,  '\%','\%', -1, 1)
        If Not @error Then
; _ArrayDisplay($aArray1, 'Default Search')
    
        For $a = 0 To UBound($aArray1) - 1
            $tag =  '"'&'%'& $aArray1[$a]&'%'&'"'&';'& ' // '
            $tag1 = '%'& $aArray1[$a]&'%'
            $tagname = $aArray1[$a]
            $tagname = StringReplace($tagname,'-','_')
            $tagname = StringReplace($tagname,'<','LT')
            $tagname= StringReplace($tagname,'>','GT')
            $tagname = StringReplace($tagname,'=','')
            $tagname = StringReplace($tagname,'/','_')
            $tagname = StringReplace($tagname,',','CM')
            $new = '$'&$tagname& ' = '& $tag 
            $line = StringReplace($line,$tag1,$new)
            
            $line= StringRegExpReplace($line,"\.{2,10}","")
;MsgBox(0,'', $output)              
            
            FileWriteLine($fileout,$line  )
            
       Next
    EndIf

WEnd    

FileClose($fileout)
FileClose($file)

here my input

tagslist.txt

what_i_looking_for.txt

myphp3.txt

Edited by n9mfk9
Link to comment
Share on other sites

I pulled the first few lines of the input file (tagslist.txt) as sample input, and formatted it like your desired output (what_i_looking_for.txt). Since I can't see what you think the significant differences are between the desire output and what you are getting, and you didn't bother to say, I can't do any better:

#include <array.au3>

$sInput = "General OR Non Weather Specific/SUN/MOON" & @CRLF & _
        "(note, to turn off having units included, go to control panel, webfiles/web page setup, custom web page setup)" & @CRLF & _
        "========================================" & @CRLF & _
        "%customscreenownlabelusethistag%  Use this tag for a title/description label on the custom screen" & @CRLF & _
        "%loadfile%..................Loads a text file into this location, e.g %loadfile%c:\wdisplay\webfiles\test.txt#  the # is needed at the end of the full path and file name" & @CRLF & _
        "%loadfile1% ................uses only the 1st line in the file" & @CRLF & _
        "%loadfilenocrlf%............does not add any CR or LF" & @CRLF & _
        "%time% .....................current time"

$avInput = StringSplit($sInput, @CRLF, 1)
_ArrayDisplay($avInput, "$avInput")

Global $avOutput[$avInput[0] + 1] = [$avInput[0]]
For $n = 1 To $avInput[0]
    $sFormatted = ""
    $avField = StringRegExp($avInput[$n], "%.*?%", 1)
    If @error = 0 Then
        ConsoleWrite("Debug: " & $n & ":  " & $avField[0] & @LF)
        $sFormatted = "$" & StringReplace($avField[0], "%", "") & ' = "' & $avField[0] & '" '
        ConsoleWrite("Debug: $sFormatted = " & $sFormatted & @LF)
    EndIf
    $avOutput[$n] = $sFormatted & "\\ " & StringRegExpReplace($avInput[$n], "\.{2,}", "", 0)
    ConsoleWrite("Debug: Output " & $n & ":  " & $avOutput[$n] & @LF)
Next

_ArrayDisplay($avOutput, "$avOutput")

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi, PsaltyDS

that code works great

I do have one ?

is there a away to make an array into a new array

im trying to add tss sep for the old code

$tagname = $aArray1[$a]
            $tagname = StringReplace($tagname,'-','_')
            $tagname = StringReplace($tagname,'<','LT')
            $tagname= StringReplace($tagname,'>','GT')
            $tagname = StringReplace($tagname,'=','')
            $tagname = StringReplace($tagname,'/','_')
            $tagname = StringReplace($tagname,',','CM')

#include <array.au3>
 Dim $avField1 
$ext =".txt"
$sInput = ""


$FileIn = @ScriptDir & "\tagslist"&$ext
$sInput = FileRead($FileIn, FileGetSize($FileIn))
        If @error = 1 Then
        MsgBox(0, "Error", "Unable to open file."&$FileIn)
    Exit
EndIf

;MsgBox(0,"test", $FileIn)
$avInput = StringSplit($sInput, @CRLF, 1)
;_ArrayDisplay($avInput, "$avInput")

Global $avOutput[$avInput[0] + 1] = [$avInput[0]]
For $n = 1 To $avInput[0]
    $sFormatted = ""
    $avField = StringRegExp($avInput[$n], "%.*?%", 1)
    If @error = 0 Then
        $avField1[0] =  $avField[0]
        MsgBox(0,"",$avField1[0])
      ; ConsoleWrite("Debug: " & $n & ":  " & $avField[0] & @LF)
        $sFormatted = "$" & StringReplace($avField[0], "%", "") & ' = "' & $avField[0] & '" '
       ;MsgBox(0,"",$sFormatted)
    ;ConsoleWrite("Debug: $sFormatted = " & $sFormatted & @LF)
    EndIf
    $avOutput[$n] = $sFormatted & "\\ " & StringRegExpReplace($avInput[$n], "\.{2,}", "", 0)
  ; ConsoleWrite("Debug: Output " & $n & ":  " & $avOutput[$n] & @LF)
Next

_ArrayDisplay($avOutput, "$avOutput")
Link to comment
Share on other sites

If you mean take the $aArray1 as input and work those string replace operations on each element while copying to another array, I think this should work:

Global $aOutput[UBound($aArray1)]
For $a = 0 To UBound($aArray1) - 1
    $tagname = StringReplace($aArray1[$a], '-', '_')
    $tagname = StringReplace($tagname, '<', 'LT')
    $tagname = StringReplace($tagname, '>', 'GT')
    $tagname = StringReplace($tagname, '=', '')
    $tagname = StringReplace($tagname, '/', '_')
    $aOutput[$a] = StringReplace($tagname, ',', 'CM')
Next

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

no what im trying to do is make one array $avField1[0] in to $avfield3[0]

so i tried $avField3[0] = $avField[0] but i did not work

so my question is how to make an array in to a new array

Thanks beau

This will make a copy of the entire array:
$avField3 = $avField1oÝ÷ Ù8b³¥Ê)Ê;¬¶Ø^Ñé^éí~º&¢w®¶²¶azaz¶î¶Øb³
'ßÛ­æ­zØ^jºÚÊ+fºËZ·w&Þ¶«y«­¢+ØÀÌØíÙ¥±ÍlÁtôÀÌØíÙ¥±ÅlÁt

When you say "did not work", how did it fail?

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This will make a copy of the entire array:

$avField3 = $avField1oÝ÷ Ù8b³¥Ê)Ê;¬¶Ø^Ñé^éí~º&¢w®¶²¶azaz¶î¶Øb³
'ßÛ­æ­zØ^jºÚÊ+fºËZ·w&Þ¶«y«­¢+ØÀÌØíÙ¥±ÍlÁtôÀÌØíÙ¥±ÅlÁt

When you say "did not work", how did it fail?

:D

I got C:\Documents and Settings\beau thompson\My Documents\au3\test\weatherpage\mytagmaker4.au3 (25) : ==> Subscript used with non-Array variable.:

$avField3[0] = $avField[0]

$avField3^ ERROR

->14:38:31 AutoIT3.exe ended.rc:1

Beau

Link to comment
Share on other sites

I got C:\Documents and Settings\beau thompson\My Documents\au3\test\weatherpage\mytagmaker4.au3 (25) : ==> Subscript used with non-Array variable.:

$avField3[0] = $avField[0]

$avField3^ ERROR

->14:38:31 AutoIT3.exe ended.rc:1

Beau

That means you need to declare the target array before copying elements to it:

Global $avField3[Ubound($avField)] ; create another array the same size
$avField3[0] = $avField[0] ; copy element [0]

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...