abdulrahmanok

Read Text from 2 Arrays

13 posts in this topic

Welcome to all , I'm trying read 2 text file to array and then show it to listbox gui like this:

line 1 from text file 1

line 1 from text file 2

this is my try :

$aArray2 = FileReadToArray(@ScriptDir & "\DaysArray.qu")
    
    If @error Then
    
    Else
        For $ok = 0 To UBound($aArray2) - 1 ; Loop through the array.
                _GUICtrlListBox_AddString($idListBox, $aArray2[$ok]) ; should look more like this
    Next

EndIf
    $aArray = FileReadToArray(@ScriptDir & "\Calc.qu")
    If @error Then
    Else
        For $y = 0 To UBound($aArray) - 1 ; Loop through the array.
            
            _GUICtrlListBox_AddString($idListBox, StringFormat($aArray[$y])) ; should look more like this
            

            ; Read File To Array is Done
;~         ExitLoop  Dont exit loop unless there is an error handler
        Next
        
    EndIf

 

Share this post


Link to post
Share on other sites



abdulrahmanok,

Quote

this is my try

And what about that script does not work as you wish?

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

#3 ·  Posted (edited)

yes,sorry i didn't explained it clearly :
Calc.qu contains :

5
1.5

DaysArray.qu contains :

Your Hours For 26/10/2016 Is :
Your Hours For 27/10/2016 Is :
Your Hours For 29/10/2016 Is :

The script Show this in listbox :

Your Hours For 26/10/2016 Is :
Your Hours For 27/10/2016 Is :
Your Hours For 29/10/2016 Is :

5
1.5

And what is want is :

Your Hours For 26/10/2016 Is :

5

Your Hours For 27/10/2016 Is :

1.5

Edited by abdulrahmanok

Share this post


Link to post
Share on other sites

abdulrahmanok,

And what should happen if, as in this case, the arrays do not have the same number of 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

#5 ·  Posted (edited)

I just want to recognize them if array doesn't equal just add available lines :)

Edited by abdulrahmanok

Share this post


Link to post
Share on other sites

abdulrahmanok,

How about this?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>

$hGUI = GUICreate("Test", 500, 500)

$idListBox = GUICtrlCreateList("", 10, 10, 400, 400, BitOr($WS_BORDER, $WS_VSCROLL)) ; Ensure no auto sort style

GUISetState()

;$aArray = FileReadToArray(@ScriptDir & "\Calc.qu")
Global $aArray[] = [5, 1.5]
If @error Then

Else

    ;$aArray2 = FileReadToArray(@ScriptDir & "\DaysArray.qu")
    Global $aArray2[] = ["Your Hours For 26/10/2016 Is :", "Your Hours For 27/10/2016 Is :", "Your Hours For 29/10/2016 Is :"]

    If @error Then

    Else
        For $ok = 0 To UBound($aArray2) - 1 ; Loop through the array.
            _GUICtrlListBox_AddString($idListBox, $aArray2[$ok])

            If $ok <= UBound($aArray) - 1 Then
                _GUICtrlListBox_AddString($idListBox, $aArray[$ok])
            Else
                _GUICtrlListBox_AddString($idListBox, "-")
            EndIf

        Next
    EndIf

EndIf

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

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)

That good but the can't read from text file in this case .. I tried to add txtfile in you code :

$try = FileReadToArray(@ScriptDir & "\Calc.qu")
Global $aArray[] = [$try]
If @error Then

Else

    $try2 = FileReadToArray(@ScriptDir & "\DaysArray.qu")
    Global $aArray2[] = [$try2]

    If @error Then

    Else
        For $ok = 0 To UBound($aArray2) - 1 ; Loop through the array.
            _GUICtrlListBox_AddString($idListBox, $aArray2[$ok])

            If $ok <= UBound($aArray) - 1 Then
                _GUICtrlListBox_AddString($idListBox, $aArray[$ok])
            Else
                _GUICtrlListBox_AddString($idListBox, "-")
            EndIf

        Next
    EndIf

EndIf

but it gives me nothing :(

 

Edit: I need to read from text because this date and this calc are created by another variable

and it changes to much

Edited by abdulrahmanok

Share this post


Link to post
Share on other sites

abdulrahmanok,

Comment out the 2 Global lines - they were just to simulate reading the files.

M23

P.S. When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.

 


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

#9 ·  Posted (edited)

ok I will ... but is there is any way to read both of text files one by one ?

Edit: all extra Quote are removed now :)

Edited by abdulrahmanok

Share this post


Link to post
Share on other sites

#10 ·  Posted

omg You already solved this Thank you very much for your code :)

$aArray = FileReadToArray(@ScriptDir & "\Calc.qu")
;Global $aArray[] = [5, 1.5]
If @error Then

Else

    $aArray2 = FileReadToArray(@ScriptDir & "\DaysArray.qu")
 ;  Global $aArray2[] = ["Your Hours For 26/10/2016 Is :", "Your Hours For 27/10/2016 Is :", "Your Hours For 29/10/2016 Is :"]

    If @error Then

    Else
        For $ok = 0 To UBound($aArray2) - 1 ; Loop through the array.
            _GUICtrlListBox_AddString($idListBox, $aArray2[$ok])

            If $ok <= UBound($aArray) - 1 Then
                _GUICtrlListBox_AddString($idListBox, $aArray[$ok])
            Else
                _GUICtrlListBox_AddString($idListBox, "-")
            EndIf

        Next
    EndIf

EndIf

Appreciate this to you

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

Solved , I understood all code except this :

If $ok <= UBound($aArray) - 1 Then

Can you Explain to me what the job of this code ?

Share this post


Link to post
Share on other sites

#12 ·  Posted

abdulrahmanok,

If the "calc" array is smaller than the "DaysArray" array (as in your example above) you will get an error if you try to access a non-existent element - this just makes sure that there is an element to write to the list and to just print a dash if 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)

Thaaaaaanks for this I was already getting this Error and tried to solve it for days but nothing

thank you again :drool:

Full Solved B)

Edited by abdulrahmanok
Delete Quote :)

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