|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
3 dimenional control arrayIs it possible to create a three-dimensional control array? When I
create a copy of a label or text box with the same name, it only gives me a 1-dimensional array, and no option to change it. I was going to try to create an app to do Sudoku puzzles, and thought it would be easier if one dimension referred to the number of the squares in the boxes, one referred to the element in the rows, and one referred to the columns. Excuse me for the basic question, as I am not a professional programmer. Jim No.
-- Show quoteHide quoteRandy Birch MS MVP Visual Basic http://vbnet.mvps.org/ ---------------------------------------------------------------------------- Read. Decide. Sign the petition to Microsoft. http://classicvb.org/petition/ ---------------------------------------------------------------------------- "Jim Madsen" <jus***@nobody.com> wrote in message news:OFvnfKdzFHA.3124@TK2MSFTNGP12.phx.gbl... : Is it possible to create a three-dimensional control array? When I : create a copy of a label or text box with the same name, it only gives : me a 1-dimensional array, and no option to change it. : : I was going to try to create an app to do Sudoku puzzles, and thought it : would be easier if one dimension referred to the number of the squares : in the boxes, one referred to the element in the rows, and one referred : to the columns. : : Excuse me for the basic question, as I am not a professional programmer. : : Jim "Jim Madsen" <jus***@nobody.com> wrote in message No.news:OFvnfKdzFHA.3124@TK2MSFTNGP12.phx.gbl... > Is it possible to create a three-dimensional control array? > When I create a copy of a label or text box with the same name, it only What you can do is create your own array in code and assign those text boxes > gives me a 1-dimensional array, and no option to change it. to it. Something like this (assuming you have 81 text boxes starting at index 0): Dim NineOfNine(1 To 9, 1 To 9) As TextBox Dim x As Long, y As Long For y = 1 To 9 For x = 1 To 9 Set NineOfNine(x, y) = MyTextBoxArray(x + (y - 1) * 9 - 1) Next Next > I was going to try to create an app to do Sudoku puzzles, and thought it You'd really want a 2D array, I think. You'd then refer to the .Text > would be easier if one dimension referred to the number of the squares in > the boxes, one referred to the element in the rows, and one referred to > the columns. property of the associated text box. I'm having difficulty seeing how a 3D array would help. Jeff Johnson [MVP: VB] wrote:
<snip> > I wanted a 3 dimensional array, because I could use one dimesion to >>I was going to try to create an app to do Sudoku puzzles, and thought it >>would be easier if one dimension referred to the number of the squares in >>the boxes, one referred to the element in the rows, and one referred to >>the columns. > > > You'd really want a 2D array, I think. You'd then refer to the .Text > property of the associated text box. I'm having difficulty seeing how a 3D > array would help. > > compare the numbers in the rows, one to compare the numbers in the columns, and one to compare the numbers in the smaller bozes (and of course look for one lone number in each of the boxes, which would be a solution). BTW, my dentist is named Jeff Johnson here in Colorado Springs -- you aren't my dentist, are you? :) Jim "Jim Madsen" <jus***@nobody.com> wrote in message I don't think you're envisioning the use of the array in the same way I am, news:uf9svzdzFHA.2960@tk2msftngp13.phx.gbl... >> You'd really want a 2D array, I think. You'd then refer to the .Text >> property of the associated text box. I'm having difficulty seeing how a >> 3D array would help. > I wanted a 3 dimensional array, because I could use one dimesion to > compare the numbers in the rows, one to compare the numbers in the > columns, and one to compare the numbers in the smaller bozes (and of > course look for one lone number in each of the boxes, which would be a > solution). because I still can't comprehend how you'd actually use that third dimension. I'd use math to segregate the nine boxes and interrogate them for their values (or lack thereof). So it would be the various combinations of 1-3, 4-6, and 7-9 in both the x and y dimensions. I'd be impressed if you can pull this off. I just tried Sudoku for the first time about a week ago and I really liked it. Of course, being the geeky programmer one of the first things I thought of was "I wonder if I could write a program to solve these" and then I got to thinking how nasty it would be. You might just have to go the brute force method. > BTW, my dentist is named Jeff Johnson here in Colorado Springs -- you Just about everyone I've ever known has known at least one other Jeff > aren't my dentist, are you? :) Johnson. Now spit. My wife got me hooked on these a couple weeks ago and I've been pondering
the same thing for the last week. I was actually going to sit down tonight and try out some code tonight. Good to know I'm not the only one. <g> -Matt Show quoteHide quote "Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message news:ubeWzBezFHA.1616@TK2MSFTNGP10.phx.gbl... > > "Jim Madsen" <jus***@nobody.com> wrote in message > news:uf9svzdzFHA.2960@tk2msftngp13.phx.gbl... > >>> You'd really want a 2D array, I think. You'd then refer to the .Text >>> property of the associated text box. I'm having difficulty seeing how a >>> 3D array would help. >> I wanted a 3 dimensional array, because I could use one dimesion to >> compare the numbers in the rows, one to compare the numbers in the >> columns, and one to compare the numbers in the smaller bozes (and of >> course look for one lone number in each of the boxes, which would be a >> solution). > > I don't think you're envisioning the use of the array in the same way I > am, because I still can't comprehend how you'd actually use that third > dimension. I'd use math to segregate the nine boxes and interrogate them > for their values (or lack thereof). So it would be the various > combinations of 1-3, 4-6, and 7-9 in both the x and y dimensions. > > I'd be impressed if you can pull this off. I just tried Sudoku for the > first time about a week ago and I really liked it. Of course, being the > geeky programmer one of the first things I thought of was "I wonder if I > could write a program to solve these" and then I got to thinking how nasty > it would be. You might just have to go the brute force method. > >> BTW, my dentist is named Jeff Johnson here in Colorado Springs -- you >> aren't my dentist, are you? :) > > Just about everyone I've ever known has known at least one other Jeff > Johnson. > > Now spit. > Jeff Johnson [MVP: VB] wrote:
Show quoteHide quote > "Jim Madsen" <jus***@nobody.com> wrote in message I was just going to write something to assist doing these puzzles, > news:uf9svzdzFHA.2960@tk2msftngp13.phx.gbl... > > I don't think you're envisioning the use of the array in the same way I am, > because I still can't comprehend how you'd actually use that third > dimension. I'd use math to segregate the nine boxes and interrogate them for > their values (or lack thereof). So it would be the various combinations of > 1-3, 4-6, and 7-9 in both the x and y dimensions. > > I'd be impressed if you can pull this off. I just tried Sudoku for the first > time about a week ago and I really liked it. Of course, being the geeky > programmer one of the first things I thought of was "I wonder if I could > write a program to solve these" and then I got to thinking how nasty it > would be. You might just have to go the brute force method. > without erasing holes into the newspaper, and pointing out the obvious. My thoughts were if the first dimension was rows, then it would look through index numbers 0 through 8 of the first dimension (representing each of the 9 rows), and if it found the puzzle number you were looking for (which you'd have first selected), change the color for that row. Same with the other nine rows. Second dimension--would similarly search the first column for that number, change color if found, and similarly check the rest of the rows. Third dimension--would similarly search the first box of nine numbers for the number selected, would change the color of the box of those nine numbers, and similarly go through the rest of the boxes with nine numbers. And obviously, you'd have to change the number of any box that already had a number in it. If there is a sole number in the box that did not change color, "we have a winner". The user can fill in the number in that box, and it would similarly rescan all of the above for further existing solutions. Obviously, it gets more complicated than that--(i.e. when you have two numbers left in a column or box, etc.) And for the harder puzzles, I would think that the user would have to guess, or use a brute force method. I just wanted to work on it because it seems like an interesting project. One of the first programs I wrote on my own used one-dimensional arrays to generate cryptograms, and to help solve the cryptograms in the newspaper. An array makes it so easy to scan sets of numbers, letters, etc, in an orderly manner. Jim > Is it possible to create a three-dimensional control array? As Randy said, no, you can't have more than a one-dimensionalWhen I > create a copy of a label or text box with the same name, it only gives > me a 1-dimensional array, and no option to change it. > > I was going to try to create an app to do Sudoku puzzles, and thought it > would be easier if one dimension referred to the number of the squares > in the boxes, one referred to the element in the rows, and one referred > to the columns. control array. However, you can have a one-dimensional array of MSFlexGrid's. Each MSFlexGrid offers a two-dimensional array of cells that can hold text (here, the grid's TextMatrix property will prove handy) and, of course, the control array's dimensional element would be for your non-row, non-column usage (I am not familiar with Sudoku puzzles, so I am unclear about the three-dimensional structure you are after). Rick Rick Rothstein [MVP - Visual Basic] wrote:
> Thank you for another possible option, Rick.> > As Randy said, no, you can't have more than a one-dimensional > control array. However, you can have a one-dimensional array of > MSFlexGrid's. Each MSFlexGrid offers a two-dimensional array of > cells that can hold text (here, the grid's TextMatrix property > will prove handy) and, of course, the control array's dimensional > element would be for your non-row, non-column usage (I am not > familiar with Sudoku puzzles, so I am unclear about the > three-dimensional structure you are after). > > Rick > > Sudoku puzzles are popular number puzzles, that now appear in almost every newspaper, alon with the crossword puzzle. Jim Rick Rothstein [MVP - Visual Basic] wrote:
> (I am not A Sudoku puzzle consists of a 9 by 9 grid of numbers. Within each row> familiar with Sudoku puzzles, so I am unclear about the > three-dimensional structure you are after). and column of the grid, the digits 1-9 may only appear once each. The grid is also divided into larger sections, 3 by 3, tic-tac-toe fashion. Each of these sections can only have the digits 1-9 appear once each.
Show quote
Hide quote
"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
http://www.sudoku.com/
wrote in message news:%23sn52udzFHA.156@tk2msftngp13.phx.gbl... > > Is it possible to create a three-dimensional control array? > When I > > create a copy of a label or text box with the same name, it only > gives > > me a 1-dimensional array, and no option to change it. > > > > I was going to try to create an app to do Sudoku puzzles, and > thought it > > would be easier if one dimension referred to the number of the > squares > > in the boxes, one referred to the element in the rows, and one > referred > > to the columns. > > As Randy said, no, you can't have more than a one-dimensional > control array. However, you can have a one-dimensional array of > MSFlexGrid's. Each MSFlexGrid offers a two-dimensional array of > cells that can hold text (here, the grid's TextMatrix property > will prove handy) and, of course, the control array's dimensional > element would be for your non-row, non-column usage (I am not > familiar with Sudoku puzzles, so I am unclear about the > three-dimensional structure you are after). > > Rick > As others suggested, you can't have more than one dimension in control
arrays, however, you can do this: Private Function GetIndex(ByVal a As Long, ByVal b As Long, ByVal c As Long) As Long GetIndex = a * b * c End Function And use it like this: Debug.Print Text1(GetIndex(1, 2, 3)).Text However, since you are going to try a lot of methods to display and interact with the user, it's best to isolate your code to 2 parts: GUI and non-GUI. This will make it easier for you to change the GUI if you find away to make a better one. For example, store the info in a UDF array and scan the array instead of the GUI objects: Public Type MyData sNumber As String End Type Public Numbers() As MyData Dim i As Long Dim j As Long Dim k As Long ReDim Preserve Numbers(9, 9, 9) As MyData For i = 1 To 9 For j = 1 To 9 For k = 1 To 9 Numbers(i, j, k).sNumber = Text1(GetIndex(1, 2, 3)).Text Next Next Next Now, when you try to solve it or perform operation on it, you only need to access the Numbers() array which is independent of what GUI elements you have used, and you could scrap the GUI and use another one easily. This improves code reuse. For instance, if I were you, I would use a PictureBox inside a UserControl and draw the grid manually, it could be a lot of work though, but it gives the nicest result. If needed, you could use DrawFocusRect() API function to show the user which cell is selected. Show quoteHide quote "Jim Madsen" <jus***@nobody.com> wrote in message news:OFvnfKdzFHA.3124@TK2MSFTNGP12.phx.gbl... > Is it possible to create a three-dimensional control array? When I create > a copy of a label or text box with the same name, it only gives me a > 1-dimensional array, and no option to change it. > > I was going to try to create an app to do Sudoku puzzles, and thought it > would be easier if one dimension referred to the number of the squares in > the boxes, one referred to the element in the rows, and one referred to > the columns. > > Excuse me for the basic question, as I am not a professional programmer. > > Jim Make that:
ReDim Preserve Numbers(3, 3, 9) As MyData As it seems what you want: http://en.wikipedia.org/wiki/Sudoku "Someone" <nob***@cox.net> wrote in message news:T2B2f.2491$MN6.2061@fed1read04...Show quoteHide quote > As others suggested, you can't have more than one dimension in control > arrays, however, you can do this: > > Private Function GetIndex(ByVal a As Long, ByVal b As Long, ByVal c As > Long) As Long > GetIndex = a * b * c > End Function > > And use it like this: > > Debug.Print Text1(GetIndex(1, 2, 3)).Text > > However, since you are going to try a lot of methods to display and > interact with the user, it's best to isolate your code to 2 parts: GUI and > non-GUI. This will make it easier for you to change the GUI if you find > away to make a better one. For example, store the info in a UDF array and > scan the array instead of the GUI objects: > > Public Type MyData > sNumber As String > End Type > Public Numbers() As MyData > > Dim i As Long > Dim j As Long > Dim k As Long > > ReDim Preserve Numbers(9, 9, 9) As MyData > > For i = 1 To 9 > For j = 1 To 9 > For k = 1 To 9 > Numbers(i, j, k).sNumber = Text1(GetIndex(1, 2, 3)).Text > Next > Next > Next > > Now, when you try to solve it or perform operation on it, you only need to > access the Numbers() array which is independent of what GUI elements you > have used, and you could scrap the GUI and use another one easily. This > improves code reuse. For instance, if I were you, I would use a PictureBox > inside a UserControl and draw the grid manually, it could be a lot of work > though, but it gives the nicest result. If needed, you could use > DrawFocusRect() API function to show the user which cell is selected. > > > "Jim Madsen" <jus***@nobody.com> wrote in message > news:OFvnfKdzFHA.3124@TK2MSFTNGP12.phx.gbl... >> Is it possible to create a three-dimensional control array? When I >> create a copy of a label or text box with the same name, it only gives me >> a 1-dimensional array, and no option to change it. >> >> I was going to try to create an app to do Sudoku puzzles, and thought it >> would be easier if one dimension referred to the number of the squares in >> the boxes, one referred to the element in the rows, and one referred to >> the columns. >> >> Excuse me for the basic question, as I am not a professional programmer. >> >> Jim > > "Someone" <nob***@cox.net> wrote in message news:T2B2f.2491$MN6.2061@fed1read04...> As others suggested, you can't have more than one dimension in control That's not going to work, values of 1,1 and 2 will produce the same result > arrays, however, you can do this: > > Private Function GetIndex(ByVal a As Long, ByVal b As Long, ByVal c As > Long) As Long > GetIndex = a * b * c > End Function as 2,1,1. You need to use a * 81 + b * 9 + c. Michael > That's not going to work, values of 1,1 and 2 will produce the same result Not enough coffee :-)> as 2,1,1. You need to use a * 81 + b * 9 + c. Show quoteHide quote "Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message news:e8hQWSfzFHA.4032@TK2MSFTNGP15.phx.gbl... > "Someone" <nob***@cox.net> wrote in message > news:T2B2f.2491$MN6.2061@fed1read04... >> As others suggested, you can't have more than one dimension in control >> arrays, however, you can do this: >> >> Private Function GetIndex(ByVal a As Long, ByVal b As Long, ByVal c As >> Long) As Long >> GetIndex = a * b * c >> End Function > > That's not going to work, values of 1,1 and 2 will produce the same result > as 2,1,1. You need to use a * 81 + b * 9 + c. > > Michael > Java solver:
http://www.sudokusolver.co.uk/ "Someone" <nob***@cox.net> wrote in message news:mnD2f.2507$MN6.1300@fed1read04...Show quoteHide quote >> That's not going to work, values of 1,1 and 2 will produce the same >> result as 2,1,1. You need to use a * 81 + b * 9 + c. > > Not enough coffee :-) > > > > > "Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message > news:e8hQWSfzFHA.4032@TK2MSFTNGP15.phx.gbl... >> "Someone" <nob***@cox.net> wrote in message >> news:T2B2f.2491$MN6.2061@fed1read04... >>> As others suggested, you can't have more than one dimension in control >>> arrays, however, you can do this: >>> >>> Private Function GetIndex(ByVal a As Long, ByVal b As Long, ByVal c As >>> Long) As Long >>> GetIndex = a * b * c >>> End Function >> >> That's not going to work, values of 1,1 and 2 will produce the same >> result as 2,1,1. You need to use a * 81 + b * 9 + c. >> >> Michael >> > > Jim Madsen wrote:
> Is it possible to create a three-dimensional control array? When I Thank-you everyone for the replies and suggestions. I decided that this > create a copy of a label or text box with the same name, it only gives > me a 1-dimensional array, and no option to change it. > > I was going to try to create an app to do Sudoku puzzles, and thought it > would be easier if one dimension referred to the number of the squares > in the boxes, one referred to the element in the rows, and one referred > to the columns. > > Excuse me for the basic question, as I am not a professional programmer. > > Jim really wasn't a problem after all. I will create a control array with 100 objects. I will create a 3 dimensional string variable, and will assign one to each of the control array objects. So it will function like I have a 3-dimensional control array, but I really won't. (I might have to create a 4th dimension to control the control array itself (tell which object needs to change color, etc.) Hope this works. Jim "Jim Madsen" <jus***@nobody.com> wrote in message If there's 81 textboxes why does it need to be 3 or 4 dimensions?news:etSNnvezFHA.3408@TK2MSFTNGP09.phx.gbl... > Thank-you everyone for the replies and suggestions. I decided that this > really wasn't a problem after all. I will create a control array with 100 > objects. I will create a 3 dimensional string variable, and will assign > one to each of the control array objects. So it will function like I have > a 3-dimensional control array, but I really won't. (I might have to > create a 4th dimension to control the control array itself (tell which > object needs to change color, etc.) Hope this works. Show quoteHide quote > > Jim
Show quote
Hide quote
"Jim Madsen" <jus***@nobody.com> wrote in message I would create nine objects with its own internal map of nine squares.news:etSNnvezFHA.3408@TK2MSFTNGP09.phx.gbl... > Jim Madsen wrote: > > Is it possible to create a three-dimensional control array? When I > > create a copy of a label or text box with the same name, it only gives > > me a 1-dimensional array, and no option to change it. > > > > I was going to try to create an app to do Sudoku puzzles, and thought it > > would be easier if one dimension referred to the number of the squares > > in the boxes, one referred to the element in the rows, and one referred > > to the columns. > > > > Excuse me for the basic question, as I am not a professional programmer. > > > > Jim > > Thank-you everyone for the replies and suggestions. I decided that this > really wasn't a problem after all. I will create a control array with > 100 objects. I will create a 3 dimensional string variable, and will > assign one to each of the control array objects. So it will function > like I have a 3-dimensional control array, but I really won't. (I might > have to create a 4th dimension to control the control array itself (tell > which object needs to change color, etc.) Hope this works. > > Jim Perhaps a 3d array. Wouldn't matter. Each square would be a pos/number/vallist() triad. type pos ' position in the nine number ' actual value value() ' probablables end type (These might make interesting objects in themselves) When you seeded the puzzle each object would receive its seed and then using a rules engine map probable values for each of the remaining squares. Each object would generate an event for each user change... First determining if it would violate its need for state (all numbers unique) Second if the number is probable. If a probable number was entered, then the object would raise an event. Each object would tune in to File and Row messages he would be interested in. (Such a mapping of events would define neighbors) When receiving an event each object would uses its own internal rules engine to determine if the number was 'probable/valid' and pass back a yea or nay. If you receive all yeas, send a 'done', and each object (interested in that file/row) updates itself to reflect the new mapping or 'probablilty'. Each object would have a Sub Seed( posvalue, [posvalue],[posvalue], ...) Sub Matrix( 1...9) 'where it is in the grand puzzle ' uses this to determine events it is interested in. Function Display( rGrid ) ' fills in grid or other control Sub Show() ' allow a cheater - would display all nine squares and defined and probable numbers for each. .... If you checkout the website http://www.sudoku.com/ you will find some interesting starts on creating better rules engines. Just some thoughts.... -ralph Jim Madsen <jus***@nobody.com>'s wild thoughts were released
on Mon, 10 Oct 2005 13:41:39 -0600 bearing the following fruit: >Is it possible to create a three-dimensional control array? When I Hmm - A grid eh? Perhaps a grid control would be easier to>create a copy of a label or text box with the same name, it only gives >me a 1-dimensional array, and no option to change it. > >I was going to try to create an app to do Sudoku puzzles, and thought it >would be easier if one dimension referred to the number of the squares >in the boxes, one referred to the element in the rows, and one referred >to the columns. use? J >Excuse me for the basic question, as I am not a professional programmer. Jan Hyde (VB MVP)> >Jim -- Arrest: What you take when you are tired. (Leopold Fechtner) [Abolish the TV Licence - http://www.tvlicensing.biz/] "Jim Madsen" <jus***@nobody.com> wrote in message No.news:OFvnfKdzFHA.3124@TK2MSFTNGP12.phx.gbl... > Is it possible to create a three-dimensional control array? > When I create a copy of a label or text box with the same name, Correct.> it only gives me a 1-dimensional array, and no option to change it. > I was going to try to create an app to do Sudoku puzzles, and There's nothing to stop you creating your own ...> thought it would be easier if one dimension referred to the number > of the squares in the boxes, one referred to the element in the > rows, and one referred to the columns. Use the normal Control array to set up the basic 81 cells, then create additional arrays to hold the "sets" you're interested in, something like Private Columns() as Variant Private Rows() as Variant Private MiniGrid() as Variant Private Cells(8) as Label Sub Form_Load Set Cells( 0 ) = Label1( 0 ) . . . Set Cells( 8 ) = Label1( 8 ) Rows( 0 ) = Cells Set Cells( 0 ) = Label1( 0 ) Set Cells( 1 ) = Label1( 9 ) . . . Set Cells( 8 ) = Label1( 72 ) ' I think Columns( 1 ) = Cells Set Cell( 0 ) = Label1( 0 ) . . . Set Cell( 8 ) = Label1( 20 ) MiniGrid( 0 ) = Cells End Sub OK; you can probably work some Modulo arithmentic to make this cleaner, but you get the idea. Then, as you set each Label on the form, the same object references get updated in your duplicate arrays. BTW, to retrieve cells, use this sort of thing : Rows( 0 )( 0 ) ' gets you the top-left corner cell Columns( 8 )( 0 ) ' gets you the top-right corner cell, HTH, Phill W.
Converting decimal to BCD (binary coded decimal)...
Transparent Picturebox I must be blind -- what's wrong with this sub? RESET does what? Why can't I test class functions from the Immediate window? advanced tooltip bubbles question Reverse Array order ? Cannot Load Form! Activex Exe convert month to month |
|||||||||||||||||||||||