Jump to content

Read Text from 2 Arrays


Recommended Posts

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

 

Link to comment
Share on other sites

  • Moderators

abdulrahmanok,

Quote

this is my try

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

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

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
Link to comment
Share on other sites

  • Moderators

abdulrahmanok,

And what should happen if, as in this case, the arrays do not have the same number of elements?

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

  • Moderators

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

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

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
Link to comment
Share on other sites

  • Moderators

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.

 

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

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

 

Link to comment
Share on other sites

  • Moderators

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

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