Jump to content

Long variable file


Recommended Posts

Hi.

I have a new file I want to read and write to an html-file.

My last file was handle with success thanks to you folks in forum, see: http://www.autoitscript.com/forum/index.ph...&hl=jorgeng

This file is a little bit trickier since i can't manage to see where file starts and ends for every post.

Sometimes there is no data in position 1 and sometimes it is.

Everywhere I want to have this data on one row:

OMXS309D

0

20090330

17:19:33

2

620.25

361

Buy

20090330

17:20:17

The thought is to write output to an html-file which i can access in web-browser.

Edited by jorgeng
Link to comment
Share on other sites

My try to code this:

#include <Array.au3>

#Include <Date.au3>

$j = 0

While $j <= 0

; Global $aResult[14][2] = [["", ""], ["Namn", ""], ["Siffra", ""], ["Datum", ""], ["Klockslag", ""], ["Antal Kontrakt", ""], _;

; ["Kurs", ""], ["Siffra", ""], ["Händelse", ""], ["Datum", ""], ["Klockslag", ""], ["Klockslag", ""], ["Klockslag", ""], ["Klockslag", ""]]

Global $aResult[24][2] = [["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], _;

["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""]]

FileWrite($file_Omx_Termins_Avslut, " " & "<br>")

$Time = _NowTime()

FileWrite($file_Omx_Termins_Avslut, "Time: " & $Time & "<br>")

_ArrayDisplay($aResult)

FileClose($sString)

FileClose($file_Omx_Termins_Avslut)

Sleep(30000)

Wend

Edited by jorgeng
Link to comment
Share on other sites

  • Moderators

jorgeng,

This code gets your file into a neat array from which you should be able to extract what you need for your HTML page:

#include <Array.au3>

Local $sData = FileRead(@ScriptDir & "\nntransl.txt")
Local $aArray = StringSplit($sData, @TAB)
Local $iLines = Int($aArray[0] / 29) + 1

Local $a2D_Array[$iLines][30]

Local $k = 1
For $i = 1 To $iLines 
    For $j = 1 to 29
        $a2D_Array[$i][$j] = $aArray[$k]
        $k += 1
        If $k = $aArray[0] Then Exitloop(2)
    Next
Next

Local $aResult[$iLines][10] = [["Namn", "Siffra", "Datum", "Klockslag", "Antal Kontrakt", "Kurs", "Siffra", "Händelse", "Datum", "Klockslag"]]

For $i = 1 To $iLines -1 
    $aResult[$i][0] = $a2D_Array[$i][4]
    $aResult[$i][1] = $a2D_Array[$i][5]
    $aResult[$i][2] = $a2D_Array[$i][7]
    $aResult[$i][3] = $a2D_Array[$i][8]
    $aResult[$i][4] = $a2D_Array[$i][11]
    $aResult[$i][5] = $a2D_Array[$i][13]
    $aResult[$i][6] = $a2D_Array[$i][18]
    $aResult[$i][7] = $a2D_Array[$i][21]
    $aResult[$i][8] = $a2D_Array[$i][23]
    $aResult[$i][9] = $a2D_Array[$i][24]
Next

_ArrayDisplay($aResult)

I hope I have extracted the correct elements of the file. if not, then use _ArrayDisplay on $2D_Array to see which elements to change in the final For...Next loop.

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

jorgeng,

This code gets your file into a neat array from which you should be able to extract what you need for your HTML page:

#include <Array.au3>

Local $sData = FileRead(@ScriptDir & "\nntransl.txt")
Local $aArray = StringSplit($sData, @TAB)
Local $iLines = Int($aArray[0] / 29) + 1

Local $a2D_Array[$iLines][30]

Local $k = 1
For $i = 1 To $iLines 
    For $j = 1 to 29
        $a2D_Array[$i][$j] = $aArray[$k]
        $k += 1
        If $k = $aArray[0] Then Exitloop(2)
    Next
Next

Local $aResult[$iLines][10] = [["Namn", "Siffra", "Datum", "Klockslag", "Antal Kontrakt", "Kurs", "Siffra", "Händelse", "Datum", "Klockslag"]]

For $i = 1 To $iLines -1 
    $aResult[$i][0] = $a2D_Array[$i][4]
    $aResult[$i][1] = $a2D_Array[$i][5]
    $aResult[$i][2] = $a2D_Array[$i][7]
    $aResult[$i][3] = $a2D_Array[$i][8]
    $aResult[$i][4] = $a2D_Array[$i][11]
    $aResult[$i][5] = $a2D_Array[$i][13]
    $aResult[$i][6] = $a2D_Array[$i][18]
    $aResult[$i][7] = $a2D_Array[$i][21]
    $aResult[$i][8] = $a2D_Array[$i][23]
    $aResult[$i][9] = $a2D_Array[$i][24]
Next

_ArrayDisplay($aResult)

I hope I have extracted the correct elements of the file. if not, then use _ArrayDisplay on $2D_Array to see which elements to change in the final For...Next loop.

M23

Thank you very much, it works great...

:D

Link to comment
Share on other sites

I have problems to get the output result on output-file in an array-like structure like you has.

Any idea how to format the output-file so it looks like the array display?

Now it looks messy like:

Rankor System Omx Termins Avslut

-------------------------------------

Namn Siffra Datum Klockslag Antal Kontrakt Kurs Siffra Händelse Datum Klockslag

OMXS309D 1 20090331 17:25:01 2 643.25 s 20090331 17:25:02

OMXS309D 1 20090331 17:23:05 7 643.25 s 20090331 17:23:05

OMXS309D 1 20090331 17:20:19 2 643.25 s 20090331 17:20:19

OMXS309D 0 20090331 17:19:56 0 643.75 k 20090331 17:19:56

OMXS309D 1 20090331 17:19:32 0 642.50 s 20090331 17:19:32

OMXS309D 0 20090331 17:19:04 0 642.25 k 20090331 17:19:04

OMXS309D 1 20090331 17:18:44 7 642 273 Sell 20090331 17:19:02

OMXS309D 1 20090331 17:18:41 7 641.75 s 20090331 17:18:41

OMXS309D 0 20090331 17:18:17 0 642.75 k 20090331 17:18:17

I would to have it like this:

Rankor System Omx Termins Avslut

-------------------------------------

Namn Siffra Datum Klockslag Antal Kontrakt Kurs Siffra Händelse Datum Klockslag

OMXS309D 1 20090331 17:25:01 2 643.25 s 20090331 17:25:02

Hmm, formatting doesn't work but everywhere, every value in separate column.

:D

Edited by jorgeng
Link to comment
Share on other sites

I tried this, but it doesn't work:

Local $aResult[$iLines][10] = [["Namn", "Siffra", "Datum", "Klockslag", "Antal Kontrakt", "Kurs", "Siffra", "Händelse", "Datum", "Klockslag"]]

MsgBox(0, "_ArrayToString() getting $aResult items 1 to 10", _ArrayToString($aResult[$iLines][10], @TAB, 1, 10))

:D

Edited by jorgeng
Link to comment
Share on other sites

If your current intention is still to write this out to HTML then I would think that you'll be using an HTML <table> wouldn't you?

If you just want to put it up on screen quickly then _ArrayDisplay() will help you.

Link to comment
Share on other sites

If your current intention is still to write this out to HTML then I would think that you'll be using an HTML <table> wouldn't you?

If you just want to put it up on screen quickly then _ArrayDisplay() will help you.

Yes, I will write to file later, but first see how it looks in a messge-box and I can't get it working.

:D

Link to comment
Share on other sites

  • Moderators

jorgeng,

You need to put your text between code tags if you want any sort of formatting in this forum - and even then it is not perfect. :-(

This code puts your data in a nice array in a GUI. You cannot use a MsgBox because it will not expand above a certain width and your lines wrap regardless:

Local $sData = FileRead(@ScriptDir & "\nntransl.txt")
Local $aArray = StringSplit($sData, @TAB)
Local $iLines = Int($aArray[0] / 29) + 1

Local $a2D_Array[$iLines][30]

Local $k = 1
For $i = 1 To $iLines - 1
    For $j = 1 to 29
        $a2D_Array[$i][$j] = $aArray[$k]
        $k += 1
        If $k = $aArray[0] Then Exitloop(2)
    Next
Next

$sResult = "Namn" & @TAB & @TAB & "Siffra" & @TAB & "Datum" & @TAB & @TAB & "Klockslag" & @TAB & "Antal Kontrakt" & @TAB & "Kurs" _
            & @TAB & @TAB & "Siffra" & @TAB & @TAB & "Händelse" & @TAB & "Datum" & @TAB & @TAB & "Klockslag" & @CRLF

For $i = 1 To $iLines -1 
    $sResult &= $a2D_Array[$i][4] & @TAB
    $sResult &= $a2D_Array[$i][5] & @TAB
    $sResult &= $a2D_Array[$i][7] & @TAB
    $sResult &= $a2D_Array[$i][8] & @TAB
    $sResult &= $a2D_Array[$i][11] & @TAB & @TAB
    $sResult &= $a2D_Array[$i][13] & @TAB
    $sResult &= $a2D_Array[$i][18] & @TAB
    $sResult &= $a2D_Array[$i][21] & @TAB
    $sResult &= $a2D_Array[$i][23] & @TAB
    $sResult &= $a2D_Array[$i][24] & @CRLF
Next

GUICreate("Result", 800, 200)
GUICtrlCreateLabel($sResult, 10, 10, 780, 180)
GUISetState()

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

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

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