Jump to content

Recommended Posts

Posted (edited)

Hi.

For 2 nights now I have been trying to get a script to work but I am struggling so I thought I would post it here and see if anyone can help...

I've been using AutoIT for a few years now but I would say at a basic level. I have understanding of how some of it works but I'm trying to do something that goes a bit deeper and I can't get my head around it. What I want to do is create a form for entering and viewing customers within my business. I want to have a continuous form that allows me to enter customer records one after the other and scroll through them all to access their data at the push of a button.

I have a parent form, a child form that sits in the middle which is what I want to hold the data and be scrollable and I have put in code that allows me to dynamically add records at the push of a button. I have taken some scripts I have found in my time and tried to paste them altogether to work for me. I can do most of it but my stumbling block now is when I get to the bottom of the child form I can extend the scroll bar but not actually add any more than a set number of records...

This is a basic form that will lead to other forms and have some SQL behind it but, for now, I am just trying to get the form to add fields and scroll through them.

I have added the script so you can see what I have, any ideas are gratefully received!

The workflow is - open the form and click the "Add Customer" button to keep creating rows that will eventually store/enter data.

Thanks in advance.

Customer.au3

Edited by toot
  • Moderators
Posted

toot,

Welcome to the AutoIt forums.

I would suggest using the other of my Scrollbar UDFs like this:

#include <Array.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ColorConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

#include <GUIScrollbars_Ex.au3>

#comments-start Versioning and future development thoughts
-------------------------------------------------------------------------------------------------------------------
PMDB

Written by Christopher O'leary - 11/11/2016

Updates :

    Version 1.0.0.0
    11/11/2016  -   Initial version

    Future Updates....

This application is designed to allow the setup and management of customers and their projects
-------------------------------------------------------------------------------------------------------------------
#comments-end

Global $i, $k

$i = 0 ; Array Index
$k = 1 ; Array Size

Global $iEventError = 0 ; to be checked to know if com error occurs. Must be reset after handling.
Global $userID, $userInitials, $userName, $userGroup, $userCustomer, $userProject, $userNotifications, $userStartupReport, $userEmail, $userLastLogin, $userRegistration ;Declares global user parameters
Global $lstObject, $lstAuth, $reRegister, $guiCustomerCHILD
Global $inpCustomerID[$k], $inpCustomer[$k], $imgLogo[$k], $btnAddLogo[$k], $btnAddCustomer[$k], $btnProjectView[$k], $NewLinePos, $BeginPos, $PlusTop, $InstanceCounter ;Declares dynamic controls

$oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler

Opt("GUIDataSeparatorChar", ",")

LoadCustomerList()

Func LoadCustomerList()
    #REGION ; GUI CREATION
    ;--------------------------------------------------------------------------
    ;Creates the Customer main GUI
    ;--------------------------------------------------------------------------
    $guiCustomerMAIN = GUICreate("PMDB Customer",500, 600,-1,-1) ;W,H,L,T
    GUISetFont(13)
    GUICtrlCreateLabel("ID", 10, 10, 50, 20, $SS_CENTER) ;L,T,W,H
    GUICtrlCreateLabel("Customer", 70, 10, 200, 20) ;L,T,W,H
    GUISetFont(11)

   $btnNewLine = GUICtrlCreateButton("Add Customer", 340, 10, 140, 30)
    $btnExit = GUICtrlCreateButton("Exit", 340, 550, 140, 40) ;L,T,W,H

    ControlFocus("PMDB Customer", "", $btnExit)

    GUISetState(@SW_SHOW, $guiCustomerMAIN) ; Display the main GUI

   ;--------------------------------------------------------------------------
   ;Creates the Customer child GUI
   ;--------------------------------------------------------------------------
   $BeginPos = 0 ; Startposition of the controls
   $NewLinePos = 64
   $PlusTop = 30 ; Moving distance for the controls


   $guiCustomerCHILD = GUICreate("", 500, 490, 0, 50, $WS_CHILD, -1, $guiCustomerMAIN) ;W,H,L,T
   GUISetFont(11)
   ; Create the 1st line of controls and write every single control in each array at index 0
   $inpCustomerID[$i] = GUICtrlCreateInput("", 10, 0, 50, 20, $ES_CENTER) ;L,T,W,H
      GUICtrlSetState($inpCustomerID[$i], $GUI_DISABLE)
   $inpCustomer[$i] = GUICtrlCreateInput("", 70, 0, 200, 20) ;L,T,W,H
   $imgLogo[$i] = GUICtrlCreateInput("", 280, 0, 50, 20) ;L,T,W,H
   $btnProjectView[$i] = GUICtrlCreateButton("View Project", 390, 0, 90, 20) ;L,T,W,H
   ;$btnAddCustomer[$i] = GUICtrlCreateButton("Save", 384, $BeginPos, 41, 20) ;L,T,W,H

   ;$aRet = _GUIScrollbars_Size(0, 490, 500, 490)  ;L,T,W,H

   GUISetState(@SW_SHOW, $guiCustomerCHILD) ; Display the child GUI

   _WinAPI_SetParent($guiCustomerCHILD, $guiCustomerMAIN)

   ;DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($guiCustomerMAIN), "hwnd", WinGetHandle($guiCustomerCHILD))
   ;--------------------------------------------------------------------------
   ;Sets up the scroll bars
   ;--------------------------------------------------------------------------

    ; Not needed now

   ;--------------------------------------------------------------------------
   ;Displays the GUI and sets the button functions
   ;--------------------------------------------------------------------------

   #EndRegion

   $InstanceCounter = 1 ; Counter to count the amount of renderinstances needed to be opened

   While 1
      $msg = GUIGetMsg()
      Select
          Case $msg = $btnExit
               Exit

         Case $msg = $btnNewLine
            AddLine()

        Case $msg > 0
            For $iIndex = 0 To UBound($btnProjectView) - 1
                If $btnProjectView[$iIndex] = $msg Then
                    ;MsgBox(0, "", "You clicked one of the choose buttons")
                    GUICtrlSetState($inpCustomer[$iIndex], $GUI_DISABLE)
                    GUICtrlSetState($btnAddCustomer[$iIndex], $GUI_DISABLE)
                    GUICtrlSetState($inpCustomerID[$iIndex], $GUI_DISABLE)
                    GUICtrlSetState($imgLogo[$iIndex], $GUI_DISABLE)
                    GUICtrlSetState($btnProjectView[$iIndex], $GUI_DISABLE)
                    ContinueLoop
                Endif
            Next
            For $iIndex = 0 To UBound($btnAddCustomer) - 1
                If $btnAddCustomer[$iIndex] = $msg Then
                    ;MsgBox(0, "", "You clicked one of the open buttons")
                    MsgBox(0, "", GUICtrlRead($inpCustomer[$iIndex]))
                    ContinueLoop
                Endif
            Next

      EndSelect
   WEnd
EndFunc

Func AddLine()
    GUISetFont(11)

    _GUIScrollBars_SetScrollInfoPos($guiCustomerCHILD, $SB_VERT, 0)

    ; Push NewLineButton down
    $NewLinePos = $NewLinePos + $PlusTop
    ;GUICtrlSetPos($NewLineButton, 80, $NewLinePos)
    $InstanceCounter = $InstanceCounter + 1 ; Count InstanceCounter up
    $BeginPos = $BeginPos + $PlusTop ; Update the top positions of the controls
    $i = $i + 1 ; Count index variable up
    $k = $k + 1 ; Count array size up
    ; Resize the array / get more room in each array
    ReDim $inpCustomer[$k]
    ReDim $btnAddCustomer[$k]
    ReDim $inpCustomerID[$k]
    ReDim $imgLogo[$k]
    ReDim $btnProjectView[$k]

    ; Amend control posn if scrollbars used
    $iChild_Height = $k * $PlusTop
    $iAdjust = 0
    If $iChild_Height > 520 Then
        $iAdjust = -10
    EndIf

    ; Create a new line of controls and store them in the specific array
    $inpCustomerID[$i] = GUICtrlCreateInput("", 10, $BeginPos, 50, 20, $ES_CENTER)
      GUICtrlSetState($inpCustomerID[$i], $GUI_DISABLE)
    $inpCustomer[$i] = GUICtrlCreateInput("", 70 + $iAdjust, $BeginPos, 200, 20)
    $imgLogo[$i] = GUICtrlCreateInput("", 280 + $iAdjust, $BeginPos, 50, 20)
    $btnProjectView[$i] = GUICtrlCreateButton("View Project", 390 + (1.5 * $iAdjust), $BeginPos, 90, 20)

    ; Generate scrollbars
    If $iChild_Height > 490 Then
        _GUIScrollbars_Generate($guiCustomerCHILD, 0, $iChild_Height)
    EndIf

EndFunc

Please ask if you have any questions.

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

 

Posted

Oh.My.God. Melba, that works brilliantly!!

 

Thank you so much for helping me on this, I've been scratching my head for 2 days trying to get it right :) Now I just need to go through the code and understand it so that I can apply it to other GUIs that will work alongside this one.

 

Thanks again :)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...