Sign in to follow this  
Followers 0
jorgeng

Variable line

15 posts in this topic

#1 ·  Posted (edited)

I am reading a file with variable blocking and this causes me some problems since i am reading positions with example:

$var = StringMid($line, 1, 8)

Later on the text is changing positions depending on the length of indata wich can be 1 to 5 positions long and then the text i am writing to output-file looks strange.

First i am doing a regular file open

Anyone having an idea how to solve this?

:D

Edited by jorgeng

Share this post


Link to post
Share on other sites



Example, look at number after SEK, differs in length:

OMXS309D SE0002438606 OM Sweden SEK -9 -0.0136570561456753 649.750000 650.500000 650.000000 22940 645.750000 659.500000 653.000000 omxterminnow

OMXS309D SE0002438606 OM Sweden SEK -8.5 -0.0128983308042488 649.750000 650.250000 650.500000 22952 645.750000 659.500000 653.000000 omxterminnow

Share this post


Link to post
Share on other sites

jorgeng,

Which bit of the example lines are you trying to read? What is your required result when extracting from those lines?

M23


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

Use StringSplit($var, " ") and access the numbers in the array.

Share this post


Link to post
Share on other sites

jorgeng,

Which bit of the example lines are you trying to read? What is your required result when extracting from those lines?

M23

I am reading first 8 positions, got OMXS309D, write it to output-file,

then SE0002438606, write

then OM Sweden, write

and then my problems begins since the value sometimes is "SEK -9" sometimes "SEK -8.5" or "SEK -22.50" and then the positions begin to move one step to the right and my output-file is being corrupted.

Share this post


Link to post
Share on other sites

jorgeng,

With that requirement weaponx has already given you the solution. Split the string on the spaces and then use the array values to get the individual elements.

M23


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

#7 ·  Posted (edited)

jorgeng,

With that requirement weaponx has already given you the solution. Split the string on the spaces and then use the array values to get the individual elements.

M23

String split looks good, but not really sure how to do that.

I give some code examples:

$file_Omx_Termins_Kurs = FileOpen("C:\File\Omx_Termins_Kurs.htm", 1)

$var = StringMid($line, 1, 8)

; MsgBox(0, " Namn:", $var)

FileWrite($file_Omx_Termins_Kurs, " Namn: " & $var & "<br>")

$var = StringMid($line, 9, 13)

; MsgBox(0, "ISIN:", $var)

FileWrite($file_Omx_Termins_Kurs, "ISIN: " & $var & "<br>")

$var = StringMid($line, 22, 11)

; MsgBox(0, "Marknadstillhörighet:", $var)

FileWrite($file_Omx_Termins_Kurs, "Marknadstillhörighet: " & $var & "<br>")

$var = StringMid($line, 33, 9)

; MsgBox(0, "Diff sedan igår:", $var)

FileWrite($file_Omx_Termins_Kurs, "Diff sedan igår: " & $var & "<br>")

Edited by jorgeng

Share this post


Link to post
Share on other sites

Shall I do stringsplit on whole infile?

:D

Share this post


Link to post
Share on other sites

jorgeng,

You need to run StringSplit on each separate string. This code shows you the resulting array in the SciTE console:

$sString = "OMXS309D SE0002438606 OM Sweden SEK -9 -0.0136570561456753 649.750000 650.500000 650.000000 22940 645.750000 659.500000 653.000000 omxterminnow"

$aArray = StringSplit($sString, " ")

For $i = 1 To $aArray[0]
    ConsoleWrite($aArray[$i] & @CRLF)
Next

If you have a file which contains lots of these strings, then look at _FileReadToArray in the Help file. It automatically creates an array with one line of the file in each element. Then you can use another For...Next loop to StringSplit each of them in turn.

M23


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

#10 ·  Posted (edited)

jorgeng,

You need to run StringSplit on each separate string. This code shows you the resulting array in the SciTE console:

$sString = "OMXS309D SE0002438606 OM Sweden SEK -9 -0.0136570561456753 649.750000 650.500000 650.000000 22940 645.750000 659.500000 653.000000 omxterminnow"

$aArray = StringSplit($sString, " ")

For $i = 1 To $aArray[0]
    ConsoleWrite($aArray[$i] & @CRLF)
Next

If you have a file which contains lots of these strings, then look at _FileReadToArray in the Help file. It automatically creates an array with one line of the file in each element. Then you can use another For...Next loop to StringSplit each of them in turn.

M23

Thanks, it worked, never heared of consolewrite.

How do i do to get the headlines first on every column? for example ISIN, see example:

Namn: OMXS309D

ISIN: SE0002438606

Marknadstillhörighet: OM Sweden

Diff sedan igår: SEK -10 -

Diff procent: 0.0151745068285281 6

Köpkurs: 49.000000

Säljkurs: 649.250000

Senast betalt: 649.00000

Omsatt antal: 0 288

Dagens Low: 86 645.750

Dagens High: 000 659.50

Dagens öppningskurs: 0000 653.000000

I want to write new headline for every new array, first

Namn:

ISIN:

and so on..

:D

Edited by jorgeng

Share this post


Link to post
Share on other sites

When i read from file i don't get the values separated, just two arrays:

Why is it different reading from file than from variable input?

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Program Files\AutoIt3\Omx_Termins_Kurs-test.au3"

OMXS309D SE0002438606 OM

Sweden SEK -11.25 -0.0170713201820941 647.500000 647.750000 647.750000 35322 645.750000 659.500000 653.000000 omxterminnow

Share this post


Link to post
Share on other sites

jorgeng,

1. If you want to add text to a ConsoleWrite you just add it in as a string: ConsoleWrite("Namn: " & $aArray[1]). But you do not have to use ConsoleWrite - I only did it to show you the result of StringSplit. You can put the result into another array if you like:

#include <Array.au3>

Global $aResult[13][2] = [["", ""], ["Namn", ""], ["ISIN", ""], ["Marknadstillhörighet", ""], ["Diff sedan igår", ""], ["Diff procent", ""], _
["Köpkurs", ""], ["Säljkurs", ""], ["Senast betalt", ""], ["Omsatt antal", ""], ["Dagens Low", ""], ["Dagens High", ""], ["Dagens öppningskurs", ""]]


$sString = "OMXS309D SE0002438606 OM Sweden SEK -9 -0.0136570561456753 649.750000 650.500000 650.000000 22940 645.750000 659.500000 653.000000 omxterminnow"

$aArray = StringSplit($sString, " ")

For $i = 1 To 2
    $aResult[$i][1] = $aArray[$i]
Next
$aResult[3][1] = $aArray[3] & " " & $aArray[4]
$aResult[4][1] = $aArray[5] & " " & $aArray[6]
For $i = 5 to 12
    $aResult[$i][1] = $aArray[$i + 2]
Next

_ArrayDisplay($aResult)

2. Please upload the file you are using to read in the lines. What I suggested should work - but there are many reasons why it might not. ;-)

M23


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

#13 ·  Posted (edited)

Ok, i upload the file.

Great if we could get this working...

I had to rename nntermin.log to txt since restrictions in upload..

Oh, and I don't want to use console write i write to a new htm output-file to access in browser.

nntermin.txt

Edited by jorgeng

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

jorgeng,

The file uses "0x09" to separate the different elements. So if you use the following it should work (well it does for me!):

#include <Array.au3>

Global $aResult[13][2] = [["", ""], ["Namn", ""], ["ISIN", ""], ["Marknadstillhörighet", ""], ["Diff sedan igår", ""], ["Diff procent", ""], _
["Köpkurs", ""], ["Säljkurs", ""], ["Senast betalt", ""], ["Omsatt antal", ""], ["Dagens Low", ""], ["Dagens High", ""], ["Dagens öppningskurs", ""]]

$sString = FileRead(@ScriptDir & "\nntermin.txt")
$aArray = StringSplit($sString, @TAB)

For $i = 1 To 3
    $aResult[$i][1] = $aArray[$i]
Next
$aResult[4][1] = $aArray[4] & " " & $aArray[5]
For $i = 5 to 12
    $aResult[$i][1] = $aArray[$i + 1]
Next
_ArrayDisplay($aResult)

You may have to play with the final For...Next loops to get the results in the correct place, as I am not sure what should go where. I have based the current placings on your earlier post.

There is no need to use ConsoleWrite - I only used it in my earlier script because it is quick and dirty - as you can see, I have used _ArrayDisplay here. But I have not used htm much, so best if you get someone else to help if you want go that way.

I hope this has set you well on your way.

M23

Edit: speeling

Edited by Melba23

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

jorgeng,

The file uses "0x09" to separate the different elements. So if you use the following it should work (well it does for me!):

#include <Array.au3>

Global $aResult[13][2] = [["", ""], ["Namn", ""], ["ISIN", ""], ["Marknadstillhörighet", ""], ["Diff sedan igår", ""], ["Diff procent", ""], _
["Köpkurs", ""], ["Säljkurs", ""], ["Senast betalt", ""], ["Omsatt antal", ""], ["Dagens Low", ""], ["Dagens High", ""], ["Dagens öppningskurs", ""]]

$sString = FileRead(@ScriptDir & "\nntermin.txt")
$aArray = StringSplit($sString, @TAB)

For $i = 1 To 3
    $aResult[$i][1] = $aArray[$i]
Next
$aResult[4][1] = $aArray[4] & " " & $aArray[5]
For $i = 5 to 12
    $aResult[$i][1] = $aArray[$i + 1]
Next
_ArrayDisplay($aResult)

You may have to play with the final For...Next loops to get the results in the correct place, as I am not sure what should go where. I have based the current placings on your earlier post.

There is no need to use ConsoleWrite - I only used it in my earlier script because it is quick and dirty - as you can see, I have used _ArrayDisplay here. But I have not used htm much, so best if you get someone else to help if you want go that way.

I hope this has set you well on your way.

M23

Edit: speeling

Thanks, it worked.

I used your array to write every i to a new line in output html-file, works great.

:D

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
Sign in to follow this  
Followers 0