Sign in to follow this  
Followers 0
pieeater

Spreadsheet imitation using inputs

10 posts in this topic

#1 ·  Posted (edited)

here is a UDF that uses input controls to imitate a spreadsheet.

Example 1

in this example it creates a spreadsheet which you enter data into, then once you press the "Enter" button it gets the data in the spreadsheet and creates a msgbox displaying what was entered in what box

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "SpreadSheet.au3"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 538, 327, 450, 168)
$Label1 = GUICtrlCreateLabel("Enter data for the spreadsheet", 16, 16, 147, 17)
$sSheet1 = _GUICtrlCreateSpreadsheet(5, 5, 16, 40)
$Button1 = GUICtrlCreateButton("Enter Data", 168, 8, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $array = _GUICtrlGetSpreadsheetData($sSheet1)
            For $j = 1 To $array[0][0] - 1
                For $i = 1 To $array[0][1] - 1
                    MsgBox(0, "Title", "You entered: " & $array[$j][$i] & @LF & _
                                       "In the box: " & $j & ", " & $i)
                Next
            Next
    EndSwitch
WEnd

Here are the functions:

_GUICtrlCreateSpreadsheet()

_GUICtrlDeleteSpreadsheet()

_GUICtrlGetSpreadsheetData()

_GUICtrlPopulateSpreadsheet()

9/1/2011: Added Example 1

SpreadSheet.au3

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites



I found this example to be a good start for entering a table of values for a project.  It's clear and concise.  But I'm having difficulty saving and restoring the contents of the array.

For my test, I'm using the sheet definition in the example script:

$sSheet1 = _GUICtrlCreateSpreadsheet(5, 5, 16, 40)

 

After entering a few values, I try to write the contents with:

_FileWriteFromArray($sFile, $sSheet1, 1)          ; Write array to file by string file name

 

The text file gets written, but when I look at the resulting file, it contains:

|4|5

|9|10

|14|15

|19|20

|24|25

The numbers aren't my entries ... and my entries aren't included.

So, is this the proper way to Save the contents?  Is there a better approach?

Thanks for any help.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thank's for your udf. Nice idea.

For my own sake, the results stored in $array are complete and correct (verified using _arraydisplay())
 

As Qwert, when I try to backup $array with _FileWriteFromArray, only the first two rows of the array are stored in the file. However, the numbers are my entries ... and my entries are included.

Some help ?

Edited by ldub

Share this post


Link to post
Share on other sites

I think there might be a problem with _FileWriteFromArray in the AU3 version 3.3.8.0 we're using.

Can anyone confirm?

Share this post


Link to post
Share on other sites

I think there might be a problem with _FileWriteFromArray in the AU3 version 3.3.8.0 we're using.

Can anyone confirm?

Yes there is, it's been fixed in the latest beta version. You can also search for threads related to it that mention it as well, which makes this question redundant.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yes, "Can anyone confirm?" wasn't a good way to ask.  I did see the update that was mentioned for the beta version.

What I should have asked was:  Can anyone confirm if there a problem with _FileWriteFromArray in 3.3.8.0 that would explain the result I posted? ... or is my result probably due to something else.

Sorry.

 

Share this post


Link to post
Share on other sites

You're using it wrong, $sSheet1 in the one liner you posted is the handle(?) of the spread sheet isn't it? In the example posted in the first post, it uses "$array = _GUICtrlGetSpreadsheetData($sSheet1)" to get the information from the sheet, you're not.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

It looks like I have some homework to do.  I had no idea I couldn't directly use/write array contents ... but I now see that GUICtrlRead is used.

Thanks for pointing that out. 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I found this example to be a good start for entering a table of values for a project.  It's clear and concise.  But I'm having difficulty saving and restoring the contents of the array.

For my test, I'm using the sheet definition in the example script:

$sSheet1 = _GUICtrlCreateSpreadsheet(5, 5, 16, 40)

 

After entering a few values, I try to write the contents with:

_FileWriteFromArray($sFile, $sSheet1, 1)          ; Write array to file by string file name

 

The text file gets written, but when I look at the resulting file, it contains:

|4|5

|9|10

|14|15

|19|20

|24|25

The numbers aren't my entries ... and my entries aren't included.

So, is this the proper way to Save the contents?  Is there a better approach?

Thanks for any help.

 

Hi quert,

i think that the data you want to write to file is not in the $sSheet1 variable,

instead you have to use the function _GUICtrlGetSpreadsheetData($sSheet1)

that returns an array containing the data from the cells:

try in this way:

; After entering a few values, I try to write the contents with:

_FileWriteFromArray($sFile, _GUICtrlGetSpreadsheetData($sSheet1), 1) ; Write array to file by string file name

bye

EDIT:

opsss:

as BrewManNH has already pointed out in post #7...

Edited by Pincopanco

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Yes, I did have a big misconception about arrays.  Things are better, now ... after figuring out that the contents of "cells" have to be loaded and saved ... and that the numbers I was seeing were the unique control IDs.

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

  • Similar Content

    • GarnetDagger
      By GarnetDagger
      Hello friends, I need some help and ideas because I am a tiny bit lost here!
      I am building some GUI with some tools and one of my tabs allows me to retrieve Data from my database in pre-defined ways I prefer.

      Currently, I can just look at them as in a Listview so no editing allowed I believe(*if I am wrong please correct me), but my dream is that I can have full control over it as in a spreadsheet program such as excel and open office. 
      what I like to include is for example;
      click cell to edit,
      Move cursor to next left, top, down or right cell, and make the cells bigger or smaller
      mouse over functions (for example a product info or picture loading etc),
      Enter to save temporary data in the cell / field or right away update it to my database also,
      Right mouse click for options etc,
      drag my cells and columns to edit 
      select multiple* rows / columns  etc
       
      the whole basic shenanigans i guess.
      this seems to be a daunting task for a beginner like me and I Know I am not a great programmer myself either. but I got time on my hand and I am very interested in how to accomplish this if possible, has it been done before and if not why not?!?!?! , The options I want in bold are required for the bare minimum to make things remotely work.
      Can I have some small guidance on this? I am under the impression that the AutoIt itself does not have these functions or possibilities, can I program this myself and how? Do I need to start accessing resources outside AutoIt and for example need to start learning win32 GUI programming or whatever it is called?
      I have tried the search for a while but I am at a loss.
      any help is appreciated and I will try to contribute myself as much as possible and I want to emphasize that I really Require the ELI5 (explain me like I am 5 years old) approach!
       
      thank you so much for reading and your time!  Regards Rene
       
    • kctvt
      By kctvt
      Hi there. A few years ago, we have Excel Offline. When we want to do something Auto with Excel, we have "_Excel"
      Now, Excel is not Offline anymore. Google Drive - Spreadsheet , brings Excel to Online. We can do a lot of things with Google Drive - Spreadsheet.
      But, I have a problem. Control, make a code Autoit run in Google Drive - Spreadsheet is not Easy. 
      So, I need help. Please give me some point to show me How to make a code AutoIT can run in Google Drive - Spreadsheet
      Thanks.
    • guestscripter
      By guestscripter
      Anybody have experience/ideas about doing this?
    • Relive
      By Relive
      I wrote a script that is designed to log at least 10,000 lines of data. While timing it in the beginning, I figured this will take a while so I decided to afk. I came back shortly and found an error came up in the script
      C:\Program Files (x86)\AutoIt3\Include\Excel.au3 (451) : ==> The requested action with this object has failed.: $oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value = $sValue $oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value = $sValue^ ERROR About six thousand lines were produced in the file successfully, but I was wondering what could have caused this error?