KaneLives

Help in Reading from Arrays

3 posts in this topic

I have been fighting with this program for over a week now, and still can't figure it out.  I wanted to create a form to enter in a series of data inputs and then write those inputs into a series of data files for later review.  The form has two input fields and 4 combo box drop downs to read and write from.  Essentially I want to select a part number from a drop down, fill out the data fields I need, write them to their files by the chosen part num

ber, and then be able to retrieve the data from the file when I select the desired part number and refresh the form.

The problem I am running into is that the information is not writing to their text files correctly.  I have tried _ArrayToClip, _FileWriteFromArray, and GUICtrlRead in various configurations in order to write the text from the input fields and combo boxes to the text files, but all I keep getting is a series of numbers instead of anything resembling the data I am inputting.

 

Here is the code I am currently using for my form:

Spoiler
#include <GUIConstantsEx.au3> ;Constants for GUI Events
#include <WindowsConstants.au3>
#include <EditConstants.au3> ;Edit constants.  Required for the styles we used.
#include <ColorConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <GuiComboBox.au3>
#include <FontConstants.au3>
#include <StaticConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <SendMessage.au3>
#include <GUIScrollBars_Ex.au3>
#include <Array.au3>

;Declare any variables/opts.
Opt("GUIOnEventMode", 1);We need this otherwise our GUI will not be OnEvent Mode.

;Create a cute little splash screen icon for our GUI
SplashImageOn("Splash Screen", "L:\Astroseal-Logo-New.jpg", 430, 100, -1, -1, 1)
Sleep(1000)
SplashOff()

;Create the GUI
$hGUI = GUICreate("MMCL Part Checker", 750, 960)
_GUIScrollBars_Generate($hGUI, 740, 2000)


;---------------------------ARRAYS DATA------------------------------


Dim $Components[74]

For $i = 0 to UBound($Components) - 1
    $Components[$i] = GUICtrlCreateInput("", 25, 150 + $i * 25, 125, 21)
Next
For $i = 0 to UBound($Components) - 1
    $Components = $Components & $i
Next

Dim $VistaRev[74]

For $i = 0 to UBound($VistaRev) - 1
    $VistaRev[$i] = GUICtrlCreateCombo("", 160, 150 + $i * 25, 60, 25)
    GUICtrlSetData(-1, "NC|A|B|C|D|E|F|G|H|J|K|L|M|N|P|Q|R|S|T|U|V|W|X|Y|Z")
    _GUICtrlComboBox_SetMinVisible(-1, 8)
Next
For $i = 0 to UBound($VistaRev) - 1
    $VistaRev = $VistaRev & $i
Next

Dim $ProDoc[74]

For $i = 0 to UBound($ProDoc) - 1
    $ProDoc[$i] = GUICtrlCreateCombo("", 230, 150 + $i * 25, 65, 25)
    GUICtrlSetData(-1, "Yes|No")
Next
For $i = 0 to UBound($ProDoc) - 1
    $ProDoc = $ProDoc & $i
Next

Dim $DocMgr[74]

For $i = 0 to UBound($DocMgr) - 1
    $DocMgr[$i] = GUICtrlCreateCombo("", 305, 150 + $i * 25, 75, 25)
    GUICtrlSetData(-1, "NC|A|B|C|D|E|F|G|H|J|K|L|M|N|P|Q|R|S|T|U|V|W|X|Y|Z")
    _GUICtrlComboBox_SetMinVisible(-1, 8)
Next
For $i = 0 to UBound($DocMgr) - 1
    $DocMgr = $DocMgr & $i
Next

Dim $Complete[74]

For $i = 0 to UBound($Complete) - 1
    $Complete[$i] = GUICtrlCreateCombo("", 390, 150 + $i * 25, 75, 25)
    GUICtrlSetData(-1, "Yes|No")
Next
For $i = 0 to UBound($Complete) - 1
    $Complete = $Complete & $i
Next

Dim $Details[74]

For $i = 0 to UBound($Details) - 1
    $Details[$i] = GUICtrlCreateInput("", 475, 150 + $i * 25, 250, 21)
Next
For $i = 0 to UBound($Details) - 1
    $Details = $Details & $i
Next


$DefPart = IniRead(@ScriptDir & "\partnumbers.ini", "Part Numbers", "DefaultPart", "NotFound")
$OtherParts = IniRead(@ScriptDir & "\partnumbers.ini", "Part Numbers", "OtherParts", "NotFound")

$hPartNumber = GUICtrlCreateCombo($DefPart, 615, 20, 80, 18)
GUICtrlSetData(-1, $OtherParts, $DefPart)

$hPartNumberAdd = GUICtrlCreateButton("Add Part #", 615, 57, 80, 23)
GUICtrlSetOnEvent($hPartNumberAdd, "AddPartNum")

Func AddPartNum()
   $sNewPN = InputBox("New Part", "Enter a new Part Number, then click 'OK'.")
   FileWrite(@ScriptDir & "\partnumbers.ini", "|" & $sNewPN)
   _GUICtrlComboBox_AddString($hPartNumber, $sNewPN)

EndFunc

$hInputData = GUICtrlCreateButton("Input Data", 530, 57, 80, 23)
GUICtrlSetOnEvent($hInputData, "WriteData")

Func WriteData()
    Local $sCurrentPart = GUICtrlRead($hPartNumber)
    If NOT FileExists("L:\DATA\Engineering\NoteCheck\Components\" & $sCurrentPart & ".txt") THEN
     _FileCreate("L:\DATA\Engineering\NoteCheck\Components\" & $sCurrentPart & ".txt")
    EndIf
    If NOT FileExists("L:\DATA\Engineering\NoteCheck\VistaRev\" & $sCurrentPart & ".txt") THEN
     _FileCreate("L:\DATA\Engineering\NoteCheck\VistaRev\" & $sCurrentPart & ".txt")
    EndIf
    If NOT FileExists("L:\DATA\Engineering\NoteCheck\ProDoc\" & $sCurrentPart & ".txt") THEN
     _FileCreate("L:\DATA\Engineering\NoteCheck\ProDoc\" & $sCurrentPart & ".txt")
    EndIf
    If NOT FileExists("L:\DATA\Engineering\NoteCheck\DocMgr\" & $sCurrentPart & ".txt") THEN
     _FileCreate("L:\DATA\Engineering\NoteCheck\DocMgr\" & $sCurrentPart & ".txt")
    EndIf
    If NOT FileExists("L:\DATA\Engineering\NoteCheck\Complete\" & $sCurrentPart & ".txt") THEN
     _FileCreate("L:\DATA\Engineering\NoteCheck\Complete\" & $sCurrentPart & ".txt")
    EndIf
    If NOT FileExists("L:\DATA\Engineering\NoteCheck\Details\" & $sCurrentPart & ".txt") THEN
     _FileCreate("L:\DATA\Engineering\NoteCheck\Details\" & $sCurrentPart & ".txt")
    EndIf

    Local $sOpenDataFile = FileOpen("L:\DATA\Engineering\NoteCheck\Components\" & $sCurrentPart & ".txt", $FO_OVERWRITE)
    Local $sOpenDataFile = FileOpen("L:\DATA\Engineering\NoteCheck\VistaRev\" & $sCurrentPart & ".txt", $FO_OVERWRITE)
    Local $sOpenDataFile = FileOpen("L:\DATA\Engineering\NoteCheck\ProDoc\" & $sCurrentPart & ".txt", $FO_OVERWRITE)
    Local $sOpenDataFile = FileOpen("L:\DATA\Engineering\NoteCheck\DocMgr\" & $sCurrentPart & ".txt", $FO_OVERWRITE)
    Local $sOpenDataFile = FileOpen("L:\DATA\Engineering\NoteCheck\Complete\" & $sCurrentPart & ".txt", $FO_OVERWRITE)
    Local $sOpenDataFile = FileOpen("L:\DATA\Engineering\NoteCheck\Details\" & $sCurrentPart & ".txt", $FO_OVERWRITE)

    ;INPUT DATA BELOW

For $1=74 to 1 Step -1
    GUICtrlRead($Components & $i)
    FileWriteLine("L:\DATA\Engineering\NoteCheck\Components\" & $sCurrentPart & ".txt", $i)
Next

For $i=74 to 1 Step -1
    GUICtrlRead($VistaRev & $i)
    FileWriteLine("L:\DATA\Engineering\NoteCheck\VistaRev\" & $sCurrentPart & ".txt", $i)
Next

For $i=74 to 1 Step -1
    GUICtrlRead($ProDoc & $i)
    FileWriteLine("L:\DATA\Engineering\NoteCheck\ProDoc\" & $sCurrentPart & ".txt", $i)
Next

For $i=74 to 1 Step -1
    GUICtrlRead($DocMgr & $i)
    FileWriteLine("L:\DATA\Engineering\NoteCheck\DocMgr\" & $sCurrentPart & ".txt", $i)
Next

For $i=74 to 1 Step -1
    GUICtrlRead($Complete & $i)
    FileWriteLine("L:\DATA\Engineering\NoteCheck\Complete\" & $sCurrentPart & ".txt", $i)
Next

For $i=74 to 1 Step -1
    GUICtrlRead($Details & $i)
    FileWriteLine("L:\DATA\Engineering\NoteCheck\Details\" & $sCurrentPart & ".txt", $i)
Next

;   $Clip1 = _ArrayToClip($Components)
;   FileWrite("L:\DATA\Engineering\NoteCheck\Components\" & $sCurrentPart & ".txt", $Clip1)
;   $Clip2 = _ArrayToClip($VistaRev)
;   FileWrite("L:\DATA\Engineering\NoteCheck\VistaRev\" & $sCurrentPart & ".txt", $Clip2)
;   $Clip3 = _ArrayToClip($ProDoc)
;   FileWrite("L:\DATA\Engineering\NoteCheck\ProDoc\" & $sCurrentPart & ".txt", $Clip3)
;   $Clip4 = _ArrayToClip($DocMgr)
;   FileWrite("L:\DATA\Engineering\NoteCheck\DocMgr\" & $sCurrentPart & ".txt", $Clip4)
;   $Clip5 = _ArrayToClip($Complete)
;   FileWrite("L:\DATA\Engineering\NoteCheck\Complete\" & $sCurrentPart & ".txt", $Clip5)
;   $Clip6 = _ArrayToClip($Details)
;   FileWrite("L:\DATA\Engineering\NoteCheck\Details\" & $sCurrentPart & ".txt", $Clip6)

;   _FileWriteFromArray("L:\DATA\Engineering\NoteCheck\Components\" & $sCurrentPart & ".txt", $Components)
;   _FileWriteFromArray("L:\DATA\Engineering\NoteCheck\VistaRev\" & $sCurrentPart & ".txt", $VistaRev)
;   _FileWriteFromArray("L:\DATA\Engineering\NoteCheck\ProDoc\" & $sCurrentPart & ".txt", $ProDoc)
;   _FileWriteFromArray("L:\DATA\Engineering\NoteCheck\DocMgr\" & $sCurrentPart & ".txt", $DocMgr)
;   _FileWriteFromArray("L:\DATA\Engineering\NoteCheck\Complete\" & $sCurrentPart & ".txt", $Complete)
;   _FileWriteFromArray("L:\DATA\Engineering\NoteCheck\Details\" & $sCurrentPart & ".txt", $Details)

EndFunc

$hRefreshPage = GUICtrlCreateButton("Refresh", 615, 82, 80, 23)
GUICtrlSetOnEvent($hRefreshPage, "RefreshPage")

Func RefreshPage()

    Local $sCurrentPart = GUICtrlRead($hPartNumber)
    ;If NOT FileExists("L:\DATA\Engineering\NoteCheck\" & $sCurrentPart & ".txt") THEN
    ; _FileCreate("L:\DATA\Engineering\NoteCheck\" & $sCurrentPart & ".txt")
    ;EndIf

    ;OUTPUT DATA BELOW

    _FileReadToArray("L:\DATA\Engineering\NoteCheck\Components\" & $sCurrentPart & ".txt", $Components)
    _FileReadToArray("L:\DATA\Engineering\NoteCheck\VistaRev\" & $sCurrentPart & ".txt", $VistaRev)
    _FileReadToArray("L:\DATA\Engineering\NoteCheck\ProDoc\" & $sCurrentPart & ".txt", $ProDoc)
    _FileReadToArray("L:\DATA\Engineering\NoteCheck\DocMgr\" & $sCurrentPart & ".txt", $DocMgr)
    _FileReadToArray("L:\DATA\Engineering\NoteCheck\Complete\" & $sCurrentPart & ".txt", $Complete)
    _FileReadToArray("L:\DATA\Engineering\NoteCheck\Details\" & $sCurrentPart & ".txt", $Details)

EndFunc


;---------------------------LABEL DATA-----------------------------------

GUICtrlCreateLabel("Components", 25, 120, 75)
GUICtrlSetFont(-1, 9, $FW_BOLD)

GUICtrlCreateLabel("Vista Rev.", 160, 120, 60)
GUICtrlSetFont(-1, 9, $FW_BOLD)

GUICtrlCreateLabel("In ProDoc?", 230, 120, 65)
GUICtrlSetFont(-1, 9, $FW_BOLD)

GUICtrlCreateLabel("DocMgr Rev.", 305, 120, 75)
GUICtrlSetFont(-1, 9, $FW_BOLD)

GUICtrlCreateLabel("Completed?", 390, 120, 75)
GUICtrlSetFont(-1, 9, $FW_BOLD)

GUICtrlCreateLabel("Details", 475, 120, 100)
GUICtrlSetFont(-1, 9, $FW_BOLD)


GUISetOnEvent($GUI_EVENT_CLOSE, "ExitGUI") ; What function to call when we try close the GUI
;Show the GUI.  We need this line, or our GUI will NOT be displayed!
GUISetState(@SW_SHOW)

;Endless While loop to keep the GUI Open
While 1
    Sleep(10); So we don't use heaps of CPU
 WEnd

 Func ExitGui ()
    Exit ; Exit the program
EndFunc

 

And here is an example of the output I am receiving in one of the text files:

Spoiler

74
73
72
71
70
69
68
67
66
65
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
 

Apologies in advance for the sloppiness of my code.

Share this post


Link to post
Share on other sites



What are you trying to do with "arrayvar = arrayvar & incr variable"?  This sequence is repeated several times.

kylomas


Forum Rules         Procedure for posting code

Share this post


Link to post
Share on other sites

I am trying to increment the variables I am inputting to so that the data can be saved to  external files.

I have attached a picture of what the form looks like.  Essentially I want to be able to read from each input and combo box and write it to an external source.  Incrementing the variables is intended to allow me to not have to create so many input field and combo box variables.

 

I hope I am describing what I want to do properly.

 

mmclautoitform.png

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