Sign in to follow this  
Followers 0
drdre

GUI set data issues.

6 posts in this topic

#1 ·  Posted (edited)

I have finished what I thought was the complicated bit of my program and now Im struggling with the basics!

This part of my program is just reading data from Excel to inputs in my GUI. Each column works fine individually, however when done one after another, it deletes the data in the bottom 2 rows.

I have just put the first 2 columns below, I would really appreciate if anyone could point out where I’m going wrong.

Thanks,

#include <Excel.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$EFilepath = @ScriptDir & "\PData2.xlsx"
$oExcel = _ExcelBookOpen($efilepath)

$Form1 = GUICreate("Form1", 553, 452, 272, 120)


$Input1 = GUICtrlCreateInput("Input1", 16, 80, 65, 21)
$Input2 = GUICtrlCreateInput("Input2", 16, 104, 65, 21)
$Input3 = GUICtrlCreateInput("Input3", 16, 128, 65, 21)
$Input4 = GUICtrlCreateInput("Input4", 16, 152, 65, 21)
$Input5 = GUICtrlCreateInput("Input5", 16, 176, 65, 21)
$Input6 = GUICtrlCreateInput("Input6", 16, 200, 65, 21)
$Input7 = GUICtrlCreateInput("Input7", 16, 224, 65, 21)
$Input8 = GUICtrlCreateInput("Input8", 16, 248, 65, 21)
$Input9 = GUICtrlCreateInput("Input9", 16, 272, 65, 21)
$Input10 = GUICtrlCreateInput("Input10", 16, 296, 65, 21)
$Input11 = GUICtrlCreateInput("Input11", 16, 320, 65, 21)
$Input12 = GUICtrlCreateInput("Input12", 16, 344, 65, 21)
$Input13 = GUICtrlCreateInput("Input13", 16, 368, 65, 21)
$Input14 = GUICtrlCreateInput("Input14", 16, 392, 65, 21)
$Input15 = GUICtrlCreateInput("Input15", 16, 416, 65, 21)

$Input16 = GUICtrlCreateInput("Input16", 88, 80, 100, 21)
$Input17 = GUICtrlCreateInput("Input17", 88, 104, 100, 21)
$Input18 = GUICtrlCreateInput("Input18", 88, 128, 100, 21)
$Input19 = GUICtrlCreateInput("Input19", 88, 152, 100, 21)
$Input20 = GUICtrlCreateInput("Input20", 88, 176, 100, 21)
$Input21= GUICtrlCreateInput("Input21", 88, 200, 100, 21)
$Input22 = GUICtrlCreateInput("Input22", 88, 224, 100, 21)
$Input23 = GUICtrlCreateInput("Input23", 88, 248, 100, 21)
$Input24 = GUICtrlCreateInput("Input24", 88, 272, 100, 21)
$Input25 = GUICtrlCreateInput("Input25", 88, 296, 100, 21)
$Input26 = GUICtrlCreateInput("Input26", 88, 320, 100, 21)
$Input27 = GUICtrlCreateInput("Input27", 88, 344, 100, 21)
$Input28 = GUICtrlCreateInput("Input28", 88, 368, 100, 21)
$Input29 = GUICtrlCreateInput("Input29", 88, 392, 100, 21)
$Input30 = GUICtrlCreateInput("Input30", 88, 416, 100, 21)

GUISetState(@SW_SHOW)



_Read2Form()


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


Func _Read2Form()

For $i = 1 To 17
    $sCellValue = _ExcelReadCell($oExcel, $i, 1)
    $controlID = $i
    GUICtrlSetData($controlID, $sCellValue)
    Sleep(10)
Next

For $a = 1 To 17
    $sCellValue = _ExcelReadCell($oExcel, $a, 2)
    $controlID = 15 + $a
    GUICtrlSetData($controlID, $sCellValue)
    Sleep(10)
Next


EndFunc
Edited by drdre

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have finished what I thought was the complicated bit of my program and now Im struggling with the basics!

This part of my program is just reading data from Excel to inputs in my GUI. Each column works fine individually, however when done one after another, it deletes the data in the bottom 2 rows.

I have just put the first 2 columns below, I would really appreciate if anyone could point out where I’m going wrong.

Thanks,

WelCome to the forum.

This is looking good!

You wrongfully assumed your Input ID starts @ 1. It actually started at 3.

I also introduced you to Arrays below. This should help a lot in future:(You could do that with the creation proccess as well)

#include <Excel.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$EFilepath = @DesktopDir & "\Test2.xls";<< Change
$oExcel = _ExcelBookOpen($EFilepath)
$aArray = _ExcelReadSheetToArray($oExcel, 2) ; ignoring header row
_ArrayDisplay($aArray)
$Form1 = GUICreate("Form1", 553, 452, 272, 120)
$Input1 = GUICtrlCreateInput("Input1", 16, 80, 65, 21); GuiControll start @ 3
$Input2 = GUICtrlCreateInput("Input2", 16, 104, 65, 21)
$Input3 = GUICtrlCreateInput("Input3", 16, 128, 65, 21)
$Input4 = GUICtrlCreateInput("Input4", 16, 152, 65, 21)
$Input5 = GUICtrlCreateInput("Input5", 16, 176, 65, 21)
$Input6 = GUICtrlCreateInput("Input6", 16, 200, 65, 21)
$Input7 = GUICtrlCreateInput("Input7", 16, 224, 65, 21)
$Input8 = GUICtrlCreateInput("Input8", 16, 248, 65, 21)
$Input9 = GUICtrlCreateInput("Input9", 16, 272, 65, 21)
$Input10 = GUICtrlCreateInput("Input10", 16, 296, 65, 21)
$Input11 = GUICtrlCreateInput("Input11", 16, 320, 65, 21)
$Input12 = GUICtrlCreateInput("Input12", 16, 344, 65, 21)
$Input13 = GUICtrlCreateInput("Input13", 16, 368, 65, 21)
$Input14 = GUICtrlCreateInput("Input14", 16, 392, 65, 21)
$Input15 = GUICtrlCreateInput("Input15", 16, 416, 65, 21)

$Input16 = GUICtrlCreateInput("Input16", 88, 80, 100, 21)
$Input17 = GUICtrlCreateInput("Input17", 88, 104, 100, 21)
$Input18 = GUICtrlCreateInput("Input18", 88, 128, 100, 21)
$Input19 = GUICtrlCreateInput("Input19", 88, 152, 100, 21)
$Input20 = GUICtrlCreateInput("Input20", 88, 176, 100, 21)
$Input21 = GUICtrlCreateInput("Input21", 88, 200, 100, 21)
$Input22 = GUICtrlCreateInput("Input22", 88, 224, 100, 21)
$Input23 = GUICtrlCreateInput("Input23", 88, 248, 100, 21)
$Input24 = GUICtrlCreateInput("Input24", 88, 272, 100, 21)
$Input25 = GUICtrlCreateInput("Input25", 88, 296, 100, 21)
$Input26 = GUICtrlCreateInput("Input26", 88, 320, 100, 21)
$Input27 = GUICtrlCreateInput("Input27", 88, 344, 100, 21)
$Input28 = GUICtrlCreateInput("Input28", 88, 368, 100, 21)
$Input29 = GUICtrlCreateInput("Input29", 88, 392, 100, 21)
$Input30 = GUICtrlCreateInput("Input30", 88, 416, 100, 21)
GUISetState(@SW_SHOW)

_Read2Form()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _Read2Form()
    For $i = 1 To 15
        $controlID = $i + 2
        GUICtrlSetData($controlID, $aArray[$i][1])
        GUICtrlSetData($controlID + 15, $aArray[$i][2])
        Sleep(10)
    Next
EndFunc   ;==>_Read2Form
Edited by JoHanatCent

Share this post


Link to post
Share on other sites

WelCome to the forum.

This is looking good!

You wrongfully assumed your Input ID starts @ 1. It actually started at 3.

I also introduced you to Arrays below. This should help a lot in future:(You could do that with the creation proccess as well)

#include <Excel.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$EFilepath = @DesktopDir & "\Test2.xls";<< Change
$oExcel = _ExcelBookOpen($EFilepath)
$aArray = _ExcelReadSheetToArray($oExcel, 2) ; ignoring header row
_ArrayDisplay($aArray)
$Form1 = GUICreate("Form1", 553, 452, 272, 120)
$Input1 = GUICtrlCreateInput("Input1", 16, 80, 65, 21); GuiControll start @ 3
$Input2 = GUICtrlCreateInput("Input2", 16, 104, 65, 21)
$Input3 = GUICtrlCreateInput("Input3", 16, 128, 65, 21)
$Input4 = GUICtrlCreateInput("Input4", 16, 152, 65, 21)
$Input5 = GUICtrlCreateInput("Input5", 16, 176, 65, 21)
$Input6 = GUICtrlCreateInput("Input6", 16, 200, 65, 21)
$Input7 = GUICtrlCreateInput("Input7", 16, 224, 65, 21)
$Input8 = GUICtrlCreateInput("Input8", 16, 248, 65, 21)
$Input9 = GUICtrlCreateInput("Input9", 16, 272, 65, 21)
$Input10 = GUICtrlCreateInput("Input10", 16, 296, 65, 21)
$Input11 = GUICtrlCreateInput("Input11", 16, 320, 65, 21)
$Input12 = GUICtrlCreateInput("Input12", 16, 344, 65, 21)
$Input13 = GUICtrlCreateInput("Input13", 16, 368, 65, 21)
$Input14 = GUICtrlCreateInput("Input14", 16, 392, 65, 21)
$Input15 = GUICtrlCreateInput("Input15", 16, 416, 65, 21)

$Input16 = GUICtrlCreateInput("Input16", 88, 80, 100, 21)
$Input17 = GUICtrlCreateInput("Input17", 88, 104, 100, 21)
$Input18 = GUICtrlCreateInput("Input18", 88, 128, 100, 21)
$Input19 = GUICtrlCreateInput("Input19", 88, 152, 100, 21)
$Input20 = GUICtrlCreateInput("Input20", 88, 176, 100, 21)
$Input21 = GUICtrlCreateInput("Input21", 88, 200, 100, 21)
$Input22 = GUICtrlCreateInput("Input22", 88, 224, 100, 21)
$Input23 = GUICtrlCreateInput("Input23", 88, 248, 100, 21)
$Input24 = GUICtrlCreateInput("Input24", 88, 272, 100, 21)
$Input25 = GUICtrlCreateInput("Input25", 88, 296, 100, 21)
$Input26 = GUICtrlCreateInput("Input26", 88, 320, 100, 21)
$Input27 = GUICtrlCreateInput("Input27", 88, 344, 100, 21)
$Input28 = GUICtrlCreateInput("Input28", 88, 368, 100, 21)
$Input29 = GUICtrlCreateInput("Input29", 88, 392, 100, 21)
$Input30 = GUICtrlCreateInput("Input30", 88, 416, 100, 21)
GUISetState(@SW_SHOW)

_Read2Form()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _Read2Form()
    For $i = 1 To 15
        $controlID = $i + 2
        GUICtrlSetData($controlID, $aArray[$i][1])
        GUICtrlSetData($controlID + 15, $aArray[$i][2])
        Sleep(10)
    Next
EndFunc   ;==>_Read2Form

Thank you so much. This solved my problem and is much quicker! Also thanks for the intro to arrays, have been reading the help file for about 15 mins. Excel read sheet to array has made my life much easier for the other part of my program.

Once again thanks for your help, I really appreciate it!

Share this post


Link to post
Share on other sites

Thank you so much. This solved my problem and is much quicker! Also thanks for the intro to arrays, have been reading the help file for about 15 mins. Excel read sheet to array has made my life much easier for the other part of my program.

Once again thanks for your help, I really appreciate it!

Pleasure is all myne!

Share this post


Link to post
Share on other sites

Hie JoHanatCent, drdre,

this is an example of using arrays instead of having all the controls defined "manually":

#include <Excel.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$EFilepath = @DesktopDir & "\Test2.xls";<< Change
$oExcel = _ExcelBookOpen($EFilepath)
$aArray = _ExcelReadSheetToArray($oExcel, 2) ; ignoring header row
_ArrayDisplay($aArray)
$Form1 = GUICreate("Form1", 553, 452, 272, 120)
Dim $a_controls[31]
$a_controls[0] = 30
$x = 16
$y = 80
$l = 65
For $i = 1 To $a_controls[0]
    $a_controls[$i] = GUICtrlCreateInput("Input" & $i, $x, $y, $l, 21)
    $y = $y + 24
    If $i = 15 Then
        $x = 88
        $y = 80
        $l = 100
    EndIf
Next
GUISetState(@SW_SHOW)

_Read2Form()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _Read2Form()
    For $i = 1 To 15
        GUICtrlSetData($a_controls[$i], $aArray[$i][1])
        GUICtrlSetData($a_controls[$i + 15], $aArray[$i][2])
        Sleep(10)
    Next
EndFunc   ;==>_Read2Form

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Hie JoHanatCent, drdre,

this is an example of using arrays instead of having all the controls defined "manually":

#include <Excel.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$EFilepath = @DesktopDir & "\Test2.xls";<< Change
$oExcel = _ExcelBookOpen($EFilepath)
$aArray = _ExcelReadSheetToArray($oExcel, 2) ; ignoring header row
_ArrayDisplay($aArray)
$Form1 = GUICreate("Form1", 553, 452, 272, 120)
Dim $a_controls[31]
$a_controls[0] = 30
$x = 16
$y = 80
$l = 65
For $i = 1 To $a_controls[0]
    $a_controls[$i] = GUICtrlCreateInput("Input" & $i, $x, $y, $l, 21)
    $y = $y + 24
    If $i = 15 Then
        $x = 88
        $y = 80
        $l = 100
    EndIf
Next
GUISetState(@SW_SHOW)

_Read2Form()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _Read2Form()
    For $i = 1 To 15
        GUICtrlSetData($a_controls[$i], $aArray[$i][1])
        GUICtrlSetData($a_controls[$i + 15], $aArray[$i][2])
        Sleep(10)
    Next
EndFunc   ;==>_Read2Form

Thanks for this.

Mind blown, didnt even think of doing this and it solves my resizing issue. I feel like an idiot after copy/pasting all my GUI inputs! lol.

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