[Solved] Solving the Sudoku Puzzle using OO BASIC Calc macro

Creating a macro - Writing a Script - Using the API

[Solved] Solving the Sudoku Puzzle using OO BASIC Calc macro

Postby OldStd » Thu Oct 11, 2018 4:48 pm

30/10/2018. By OldStd
    I changed the topic title so that I can put the word [Solved], as I have found a complete solution to the Sudoku puzzle using only the OO BASIC CALC macros.

    I couldn't place a word [Solved] to the topic because [Learning to program in OpenOffice Basic] is ongoing and never ending process, Sudoku, or otherwise.


I am quite new to learning how to program in OpenOffice Basic.
I always feel that having a pet project would make learning easier as the project forces us to dig for items that help to solve some problems at hand.
    I. Recently, a childhood classmate of mine told me he is playing Sudoku games everyday.
      I.1. I am now wondering whether I could use the OpenOffice to make some sort of [Sudoku solver] that can at least solve some easy to medium Sudoku games?
        I.1.1. Any suggestions from anyone as to what application to use: writer, calc, base, or impress?
        I.1.2.What do I need to learn to start the project going?
I first posted this in another forum and was advised to open a new topic on Sudoku.
Since then I had gone through some websites and their attached codes. However, as the codes were written in C, and the explanation done in non-English, I was unable to comprehend what is being done.
One idea did catch my attention: that of back-tracking when the application gets stuck.
I have yet to figure out how to do this back-tracking in codes.
Any further examples in back-tracking explained in English would be much appreciated.
From Ziz46's suggested site, I have downloaded Sudoku 0.5.5 extension and installed the extension, only to realise that I don't even what an extension is, and how to use the extension manager.

Zizi46 suggested a couple of sites to start me off.
https://extensions.openoffice.org/en/project/sudoku
https://forum.openoffice.org/en/forum/v ... =5&t=89193
My search in the OO Basic forum yielded the following sites:
https://forum.openoffice.org/en/forum/v ... ku#p420482
https://forum.openoffice.org/en/forum/v ... ku#p420432
https://forum.openoffice.org/en/forum/v ... ku#p420291
https://forum.openoffice.org/en/forum/v ... ku#p420285
https://forum.openoffice.org/en/forum/v ... ku#p420253
https://forum.openoffice.org/en/forum/v ... ku#p184040
https://extensions.openoffice.org/project/sudoku1
https://forum.openoffice.org/en/forum/v ... ku#p146120
https://forum.openoffice.org/en/forum/v ... ku#p146116
https://forum.openoffice.org/en/forum/v ... ku#p146104
Last edited by OldStd on Tue Oct 30, 2018 4:34 pm, edited 2 times in total.
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby John_Ha » Thu Oct 11, 2018 5:19 pm

I doubt it will be easy to program a Sudoku solver in OpenOffice Basic though no doubt it will be possible and you will learn much.

OO Basic is used to write office applications like a word processor. Similarly, a hammer is used to hammer nails and a knife is used to spread butter. If you want, you can spread butter with a hammer and bash nails in with a knife but ...

You ideally need a code which allows recursion to do the backtracking - it is then all taken care of in the program without you doing very much. I don't know if OOBasic supports recursion.

See http://www.sudokuwiki.org/ - at one time Andrew Stuart published a PDF on how his solver worked and how he graded his puzzles.

See Macros and UNO API, OpenOffice.org BASIC Programming Guide and Andrew Pitonyak's OpenOffice Macro Information. I think [Tutorial] Introduction into object inspection with MRI will be useful too.
Last edited by John_Ha on Thu Oct 11, 2018 5:29 pm, edited 1 time in total.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 5992
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Learning to program in OpenOffice Basic through Sudoku

Postby RoryOF » Thu Oct 11, 2018 5:27 pm

This is like learning a language and at the same time writing the Great XXXX Novel in that language. I suggest you concentrate on learning one programming language, outside of OO - something such as Python - a good book on this at
A Byte of Python

Having learned Fortran 2 and progressed to BASIC, with excursions through C, Pascal, Modula, Java, I advise against learning a procedural language first, hence my suggestion of Python.
Apache OpenOffice 4.1.6 on Xubuntu 18.04 (mostly 64 bit version) and infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 27656
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Thu Oct 11, 2018 8:35 pm

Dear John_Ha
Thank you for your info and advice.
You have given me so many URL's I need to go through them first, before I can make head and tails out of them.
I had downloaded and installed MRI but haven't found out how to use the MRI yet.
I like your hammer and butter knife metaphor.
I hope I would be able to write a program in OO Basic to solve the Sudoku, someday!
Best regards, and wish me luck!
Last edited by OldStd on Fri Oct 12, 2018 5:10 pm, edited 1 time in total.
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Thu Oct 11, 2018 9:05 pm

Dear RoryOF.
Thank you for your advice on procedural language vs other language. I started learning programming by recording macros in Microsoft Excel and then buying a book in VBA for Excel. A while back, I had taken some Introductory course in Python from a free online course.
I have recently downloaded some eBooks from the web on OO Basic programming and haven't really gone through too much of the reading yet.
I understand your metaphor on learning a new language and trying to write a novel in it.
You remind me of the story of a famous NBA coach who started his training session with the champion national basketball team players:
“Gentlemen: this is a basketball, ….”
Over here, it is 03:03 am. It is well past my bedtime as I was watching a YouTube series on “New Shanghai Beach” …
I'll read up the materials and see what I can make of them in the new few days.

Best regards
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Fri Oct 12, 2018 10:17 am

Hi. Zizi46, John_Ha, RoryOF, and everyone.

It occurs to me that most of the posts in Sudoku in the OO forum are found in the [Calc Forum], and so I think it might be easier to program with Calc. I saw something that look like matrices in some of the codes I saw. As Matrix looks awfully difficult in OO, I will settle to using the Arrays.

Here are my codes for
1. Copying the manual entries of a sample Sudoku game I saw in one author into an array.
2. Duplicating the same Sudoku game from the array back to another worksheet.
3. How the cells in the game table template are named: Top to bottom, left to right. 0 based. 0 to 80 for the 81 cells.
Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****
option explicit

Dim Doc As Object
Dim Sheet As Object
Dim Cell As Object 
Dim   MyArray(149) as string

function CopyFromCellRangeToArray
dim i, j, k as integer
Doc = ThisComponent
Sheet = Doc.Sheets(0)
   for i = 0 to 8
      for j = 0 to 8
         if i =0 and j = 0 then
            k = 0
         else
            k = k + 1
         end if      
         Cell = Sheet.getCellByPosition(j,i)
         MyArray(k)= Cell.string
      next j
   next i
   CopyFromCellRangeToArray = MyArray()
   Msgbox "Cell(78) = " & MyArray(78)
end function

Sub DuplicatedFromArrayToCellRange
dim i,j,k as integer
MyArray = CopyFromCellRangeToArray
Sheet = Doc.Sheets(1)
   for i = 0 to 8
      for j = 0 to 8
         if i =0 and j = 0 then
            k = 0
         else
            k = k + 1
         end if      
         Cell = Sheet.getCellByPosition(j,i)
         Cell.setstring(MyArray(k))
      next j
   next i
end sub

sub NamingCells
dim i,j,k as integer
Doc = ThisComponent
Sheet = Doc.Sheets(2)
   for i = 0 to 8
      for j = 0 to 8
         if i =0 and j = 0 then
            k = 0
         else
            k = k + 1
         end if      
         Cell = Sheet.getCellByPosition(j,i)
         Cell.setstring(CStr(k))
      next j
   next i
end sub

Attachments
Sudoku_001.ods
First glimpse
(13.76 KiB) Downloaded 38 times
Last edited by OldStd on Fri Oct 12, 2018 5:12 pm, edited 1 time in total.
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby RoryOF » Fri Oct 12, 2018 10:26 am

It might be best to distance yourself from the low level code and concentrate instead on the algorithm you will use to solve the Suduko problem. Once you have the algorithm writing the code is relatively trivial in any language.
Apache OpenOffice 4.1.6 on Xubuntu 18.04 (mostly 64 bit version) and infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 27656
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Fri Oct 12, 2018 10:37 am

Hi. RoryOF.
Thanks for the advice.
As I am so new to the programming in OO Basic, that even to write these few lines of codes, I have to look up the syntax at the forum and elsewhere in the Google search.
I haven't even done much reading in the basic guide yet.
Just a few days ago, all I knew was to record a macro to learn the syntax and terms used in OO.
Hopefully, I will come to the stage where I can concentrate on the algorithm, and that, too, is a big word for me for the time being. :D
Last edited by OldStd on Fri Oct 12, 2018 5:14 pm, edited 1 time in total.
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Fri Oct 12, 2018 11:36 am

Hi. RoryOF.
Responding to your suggestion on concentrating on the [algorithms], I have used [Brute-force] approach before but I have just come across the term [Depth First Search].
At first glance, I can't quite understand the algorithm, especially, how to record the list of options available, how to mark the option as visited but failed, and how to go back to use the option not visited.
If you have some code snippets on this algorithm, it would be much appreciated.
Best regards.
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby RoryOF » Fri Oct 12, 2018 11:45 am

A very quick search found this
Mathematics and Sudokus
which seems to lead to presentation and discussion of various algorithms for solution of Sudoku puzzles.

I'm currently involved in research for and writings set in the 1812-30 and 1946 periods (before Sudoku was invented?) so am not giving any thought to programming at present.
Apache OpenOffice 4.1.6 on Xubuntu 18.04 (mostly 64 bit version) and infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 27656
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Fri Oct 12, 2018 5:02 pm

Hi. RoryOF.
Thank you for your link and info.
It is rather interesting. I may want to try some of the algorithms mentioned there.
Just wondering how you could come across this kind of document in your search and I couldn't?
Do you have any special way of searching or perhaps using some kind of search tool I have never heard of?
Maybe it is one of your research tools?
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby John_Ha » Fri Oct 12, 2018 5:08 pm

See Sudoku Solver using Recursive Backtracking which gives a Java program using recursion which is about 60 or 70 lines long.

The recursion occurs because the solveSudoku() method calls itself - that is why backtracking is so easy and why the code is so short.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 5992
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Fri Oct 12, 2018 5:22 pm

Hi. John_Ha.
Thanks for the link.
I'll go through the codes and see if I can adapt them into the OO Basic program.
Best regards.
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby RoryOF » Fri Oct 12, 2018 6:10 pm

OldStd wrote:Hi. RoryOF.
Thank you for your link and info.
It is rather interesting. I may want to try some of the algorithms mentioned there.
Just wondering how you could come across this kind of document in your search and I couldn't?
Do you have any special way of searching or perhaps using some kind of search tool I have never heard of?
Maybe it is one of your research tools?


I use Google, as available to all. The trick is just the selection of keywords - one needs to pick the key terms, but not to overspecify.
Apache OpenOffice 4.1.6 on Xubuntu 18.04 (mostly 64 bit version) and infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 27656
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Learning to program in OpenOffice Basic through Sudoku

Postby John_Ha » Fri Oct 12, 2018 6:31 pm

RoryOF wrote:I use Google, as available to all. The trick is just the selection of keywords - one needs to pick the key terms, but not to overspecify.

... and is a skill we all need these days!
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 5992
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Fri Oct 12, 2018 6:55 pm

Hi. RoryOF and John_Ha.
Thank you for your responses.
You two have proven to be a better Google searcher than I am.

Hi. John_Ha.
I took a look at the Java codes. I can't quite understand Java OOP language on class, etc.
I guess it is the recursive call to the function that does the tricks, while I don't understand how it goes back to the original cell and do a re-assignment of value.
Looking at the codes again, I think I probably need to use the matrix instead of the array to do the job.
Like it or not, I have to go back to learn matrix in OO Basic.
I can't find the topic on matrix in the few ebooks I have download. However, searching on Google, I could find some materials on matrix.
I'll see what will come out of the new searches in the basic knowledge on how to use the matrix to program.
Thanks and regards.
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Sat Oct 13, 2018 8:08 pm

Hi. Zizi46, John_Ha, RoryOF, and everyone.

I still find the recursive, or depth-first, approach a bit difficult to understand and therefore I will stick to the lower level methods of using pencil and paper as suggested in the book by Crook.
https://www.ams.org/notices/200904/tx090400460p.pdf

Trying towards this direction, I have so far done the following steps:

    1 Copied the sample Sudoku game data into an array.
    2 Formulated functions to extract from the array
      2.1 a row (9 in total)
      2.2 a column (9 in total)
      2.3 a block of 3 x 3 cells (9 in total)
    3 Filled up all the blank cells with no data with [123456789]

The next steps will be
    1 To eliminate from the filled cells with the 9 digits those digits that occur in the same row, same column, or same block of the selected cell.
    2 Repeat the process until no more can be eliminated.
    3 Next, look for cells in the row, or column, or block that contain some common digits and eliminate those common digits from all other cells outside the cells in the respective rows, columns,block.
    4 After these, I'll find out what other steps to learn and apply.
I took a long time to learn the arrays as I can't find much materials on the topic apart from one or examples in the basic section of the OO guide.

I feel that I am making some progress.

Codes are attached in the Calc workbook for those who are free to comment.

Thanks and regards.
Attachments
Sudoku_002.ods
For your reading pleasure and comments
(14.12 KiB) Downloaded 38 times
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Mon Oct 15, 2018 10:39 am

Hi. Everyone.

I have succeeded in getting the Sudoku games from Table 1 (the given game) to Table 2 by applying only removing the digits repeated.

However, this method now gets stuck after only 2 rounds of the operations. Number of [clues], single digits in a cell, has increased from 24 clues to 26 clues. The digits [6] and [5] colored red in the image are the results of this method.

Stage 2 method involved in removing a subset of digits from another cell in the same row, or column, or block of 3x3 cells.

For example, in the block in the center, [79] can be removed from [2379] resulting in the cell now having digits of [23] only. Similarly, [39] can be removed from [239], resulting in increasing a clue [2]. As the 2 cells are in the same block, [3] can be removed from 23, resulting in another [clue], [3].

I have yet to figure out how to do this task in codes.

In the meantime, I am looking up material on how to use the XRAY extension.

Regards.
Attachments
img_tables.png
Don't know how to insert this in the message
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby robleyd » Mon Oct 15, 2018 11:46 am

Cheers
David
Apache OpenOffice 4.1.6 - Slackware 14.2 - 64 bit
LibreOffice 6.0.7.3 - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 2254
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Learning to program in OpenOffice Basic through Sudoku

Postby RoryOF » Mon Oct 15, 2018 12:09 pm

MRI documentation at
https://github.com/hanya/MRI/wiki

This chapter may be helpful in actually applying MRI
https://fivedots.coe.psu.ac.th/~ad/jlop/chaps/03.%20Examining.pdf
Apache OpenOffice 4.1.6 on Xubuntu 18.04 (mostly 64 bit version) and infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 27656
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Mon Oct 15, 2018 1:20 pm

wrong solution.png
Can't be that easy.
Hi. robleyd.
Hi. RoryOF.

Thank you for your links.

I'll follow up on these in order to learn how to use MRI.

For example, in the block in the center, [79] can be removed from [2379] resulting in the cell now having digits of [23] only. Similarly, [39] can be removed from [239], resulting in increasing a clue [2]. As the 2 cells are in the same block, [3] can be removed from 23, resulting in another [clue], [3].


Unfortunately, I had not understood the method introduced by Crook. As I tried the idea, in a fraction of seconds, the entire sheet is filled with single digits in every cell, with some blocks of 3x3 correct, but in some other blocks, rows, or columns, digits are repeated, and hence violating the rules of Sudoku.
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby Zizi64 » Mon Oct 15, 2018 2:38 pm

In the meantime, I am looking up material on how to use the XRAY extension.


Code: Select all   Expand viewCollapse view
Sub SomeSub
dim...

rem Load Xray:
   If (Not GlobalScope.BasicLibraries.isLibraryLoaded("XrayTool")) Then
      GlobalScope.BasicLibraries.LoadLibrary("XrayTool")
   End If


...here you get the object variable oMyObject somehow...

rem Examine oMyObject with the xraytool:
   xray oMyObject



ens sub


https://forum.openoffice.org/en/forum/v ... 20&t=54217
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.1 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.2 and AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 7449
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Mon Oct 15, 2018 3:10 pm

Thank you Tibor.

I didn't realize we have to load the library first.
I'll read up the materials and try it out later.

Thanks and regards
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby Zizi64 » Mon Oct 15, 2018 6:35 pm

I didn't realize we have to load the library first.


You can load it manually too: just click on the library icon in the IDE.
(When you can edit it, that means: it has loaded, and it can work)

loadxray.png
loadxray.png (11.32 KiB) Viewed 1786 times


When the library icon is yellow, then the xray is in the memory.
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.1 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.2 and AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 7449
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Mon Oct 15, 2018 7:24 pm

Hi. Tibor.

Thanks for the info.

I copied your line of codes into a test macro carrying codes snippet copied from the web and run it.
I checked the icon of Xray, and it is now yellow.

I need to play around with it a bit more to see how it actually works.

As for the Sudoku application, I am not so concerned about getting it fully functional but more so to learn some OO Basic codes along the way.

It appears that I am mainly making use of the [arrays] in this project.

The arrays in OO seem to be quite different from what I saw in some other languages.

For example, I don't even find anything that describe the length of the array, such as Arr.length.

In the present stage of development, I have removed the unwanted digits from cells until it doesn't work any more. The next thing to do, as I imagine it, would be to choose one cell containing 2 digits and insert one as a new clue, save the other in an array for future use if the process gets stuck down the line, and save the current configuration of data in another array that can be retrieved.

This means, I need to access the last element in an array, or append an item at the bottom of an array.

Right now I don't know how to access the last element, as I don't the actual number, other than using the Ubound of an empty array? Even that I don't find any example on how to apply it. Where do I find any reference for this basic knowledge of syntax of arrays?

Another approach is not to save anything, but apply a random choice between the 2 or 3 digits, and if it doesn't work, start all over again, and because of the random choice, it eventually will hit on a combination that works. I have to learn to use the random function, yet.

Attached is [work-in-progress] of the project. Perhaps, I'll use it to test out how to use the Xray later.

Best regards
Attachments
Sudoku_003.ods
Program gets stuck after 6 rounds and 9 added clues
(14.97 KiB) Downloaded 35 times
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby Zizi64 » Mon Oct 15, 2018 7:33 pm

For example, I don't even find anything that describe the length of the array, such as Arr.length.
...
Where do I find any reference for this basic knowledge of syntax of arrays?

https://wiki.openoffice.org/wiki/Docume ... ide/Arrays

Code: Select all   Expand viewCollapse view
MsgBox(LBound(MyArray))
MsgBox(UBound(MyArray))
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.1 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.2 and AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 7449
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Learning to program in OpenOffice Basic through Sudoku

Postby Zizi64 » Mon Oct 15, 2018 7:37 pm

Tibor Kovacs, Hungary; LO4.4.7, LO6.1.1 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.2 and AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 7449
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Mon Oct 15, 2018 7:44 pm

Thanks for the links.

Yes. This would be the syntax of arrays if I want to save a copy of the [work-in-progress] Sudoku table in an array for future retrieval.

Sub Create_Array_of_Arrays(i,k)
Dim aArray(i) as variant
for j = 0 to i
aArray(j) = dimArray(k)
next j
xray aArray
End Sub

Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby OldStd » Wed Oct 17, 2018 7:17 am

My Algorithm.png
My algorithm to solve the Sudoku puzzle
The attachment My Algorithm.png is no longer available
Testing out Step 3. Part 3

Hi. Ziz64 and everyone.

With reference to the diagram on my algorithm to solve the Sudoku game, I am now working on Step 3 (part 3)
Saving the other digit, together with the cell number and the current array of strings of digits

Thanks to Zizi64, for his links, I have found out how to do these, by performing the following tests with codes

I think I am on track. [Eating a whale, one bite at a time]

By the way, I am looking for the equivalent of [collections], [collection] but can't find them. Can anyone show me where to find [collections] in OO BASIC?

Code: Select all   Expand viewCollapse view
sub test2
dim oArr() as object   ''' An array to hold the saved cell number, cell value, and current array
dim nArr1(1) as integer   ''' a variable to save the current cell number
dim sArr2(1) as string   ''' a variable to save the remaining part of the cell value
dim sArr3(80) as string   ''' to mimic the current array being processed
dim oArrk() as object   ''' a worker array to hold the 3 items above.
dim i as integer

rem Current cell number
nArr1(0) = 28
rem Current cell value, a string of digits
sArr2 (0) = "357"
rem Not exactly the current array under processing
rem The following array is just demo to mimic an array to be saved
rem In actual program, this is the current array being processed
for i = 0 to 80
sArr3(i) = CStr(i)
next i

rem Inserting items into the arrays designed
AddItemToArray(oArrk,nArr1)
AddItemToArray(oArrk,sArr2)
AddItemToArray(oArrk,sArr3)
AddItemToArray(oArr, oArrk())

rem How to access the data from the array holding the saved data

rem To retrieve the saved cell number
msgbox oArr(0)(0)(0)
rem To retrieve the saved remaining cell value (for future use)
msgbox oArr(0)(1)(0)
Rem To retrieve the saved array
msgbox oArr(0)(2)(1)

end sub


Sub AddItemToArray(xArray, vNextElement)
Dim iUB%,iLB%
iLB = lBound(xArray())
iUB = uBound(xArray())
If iLB > iUB then
iUB = iLB
redim xArray(iLB To iUB)
else
iUB = iUB +1
redim preserve xArray(iLB To iUB)
endif
xArray(iUB) = vNextElement
End Sub

Sub removeItemFromArray(xArray())
Dim iUB%,iLB%
iLB = lBound(xArray())
iUB = uBound(xArray())
iUB = iUB - 1
redim preserve xArray(iLB To iUB)

End Sub
Openoffice 4.15
Windows 10
OldStd
 
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: Learning to program in OpenOffice Basic through Sudoku

Postby JeJe » Wed Oct 17, 2018 12:03 pm

Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 299
Joined: Wed Mar 09, 2016 2:40 pm

Next

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests