Jump to content

Spreadsheet imitation using inputs


pieeater
 Share

Recommended Posts

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]

Link to comment
Share on other sites

  • 1 year later...

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.

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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.

 

Link to comment
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

Link to comment
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.

 

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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.

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

×
×
  • Create New...