i want to create a Word Search game using Visual Basic? I've already started it by creating grids (10x10). However, I do not know how to properly insert the words that the user will search for.
Here's a look at what I did as well as the codes.10x10 grid
as you can I see, I created the grid using the Paint Event handler.
I have a text file containing all the words that the user will search. Using VB I open and read all the lines and put the words in an array (not seen in the picture).
I want the words to be inserted in the grid randomly. But I do not know how to?
Any help is much appreciated. Thank you!
The visual grid is a bit of a distraction at this stage. concentrate on getting a list of strings into an nxn two-dimensional string array. I would write a sub which, given a list of words and a dimension, returns a filled-in array (if possible).
A natural choice is a backtracking algorithm, which seeks to randomly place words into a partially filled array. For each new word, generate the collection of all valid locations and then randomly pick one of those locations. If there are no valid locations -- backtrack, removing the most recently placed word and placing it somewhere else. It might help to first sort the list of words to be placed in order of decreasing length, since it will be easier to place smaller words into a partially-filled in array than larger words. Placing the larger words when there are less constraints will thus lessen the amount of back-tracking needed.
When all of the words have been placed, fill in the rest of the array randomly.
Related
After converting PDFs to Word using the company's authorized program, the tables in my Word file are not converted as Table Objects, but use a weird format where its lines are actually a shape/picture of a table anchored below the text, and the text in the original tables are regular paragraphs where blanks are replaced by (a lot) spaces.
This gives something like:
Heading 1 Heading 2 Heading 3
Please note that the converted "tables" can be rather complex with merged cells, which makes working directly on them to reconstitue the table a pretty difficult tast (I tried)
After having tried a number of solutions to transform these fake tables back into real ones (which all failed), my last idea is to find the absolute/relative positions of the beginning and the end of the shape (which is supposed to be the table's lines), to set the Selection.Range relative to these two positions, and to delete everything within this range in order to put better Tables back later on (using for example another conversion tool).
My question is: is it possible to set a range/selection using a kind of (X;Y) on the page? Something in the idea of
Selection.setRange (Start:= 20,30 relative to page, End:= 100, 50 relative to page).
I know Word doesn't really work like that, but I don't see too many solutions to the initial problem.
I'm recently programming with the VB in the Visio.
I'm really curious about the myShape.Cells("Width") and myShape.Cells("PinX"), I mean the .Cells("...") part of the code. My program has used them very many times.
I want to know more about them, but I can't find any specific explanation about this.
Who definites it, and what are all of the key-value pairs in the .Cells().
I've seen someones in this site using someShape.Cells["Width"] to point to the value of the shape's width.
So:
I want to know if the .Cells() is an collection or map(dictionary) in reality. Please give me some explanation or files that I can read for help.
I've tried to put the myShape.Cells or myShape.Cells() in the watch window, but it didn't work. It told me something wrong..
So How can I have a look at all the key-value pairs in the .Cells(), it will be a great help to give me some codes that I can use to show the key-value pairs in the immediate window.
Thanks a lot.
There are two ways of accessing ShapeSheet cells in Visio. One is by name, using the Shape.Cells (or CellsU) method you mention, and the other is by index using Shape.CellsSRC. The second method reveals how cells are structured, by Section, Row and Column. Note that slightly confusingly, the SRC structure is not necessarily an exact replica of the cells you can see when you open the ShapeSheet in the UI, which is organised into something that's a little more user friendly.
The SRC indices are usually expressed as enums, which you can look up in the SDK along with the cell Name equivilent.
So to answer your questions more directly:
Is .Cells a collection - not one that you can call and retrieve all values. You can loop through the cells using CellsSRC but you'll discover that the cells are not necessarily contiguous, plus there are a number of unnamed or internal cells that you can't use via the api. For further details you might find this link useful https://msdn.microsoft.com/en-us/library/aa201764%28v=office.10%29.aspx
myShape.Cells() doesn't work - The cells method takes a single parameter, which is the string name of the cell. This is often, but not always, the name you see in the ShapeSheet window. Otherwise you have to look up the name in the docs - Cells reference
One last point is that you should try and use the CellsU method rather than the Cells one. The former accesses the cell names using universal syntax where the latter uses local syntax, which may differ across different locales.
From what I have seen, if I try to place a label on a form more than once, only the last one is allowed (along with some weird other happenings). I have a form which will have many Textboxes with degree and radian values. Is it possible to somehow use the same Label (or any other control for that matter) more than once so that I do not have to make multiple instances of Π and ° labels to place next to the values in the Textboxes? I realize that this is relatively minor in this instance, but it could have applications later.
I have a program which outputs a collection of tables in a word document which I eventually want to post as an html file with bookmarks and an index. The tables are grouped by "Name:" where there is a 3 row table that contains detailed header information for a section of data, then there is a second table which can span multiple pages which contains the data for that section. There is then a page break so that the next sections header table is on a new page. This can occur for a variable number of sections numbers in the hundreds. I need to write a script that
searches my document for "Name:", which is unique and would not
appear anywhere but the header table,
grabs the text that follows "Name:" within that table cell (for example "Name: Line 1234)
replaces all the blanks in that text string with an underscore to
make it a suitable bookmark name,
creates a bookmark with the name,
goes back and creates an index at the front of the document
Saves the file as an html
I have a passing familiarity with VB for word, I have used it a bit in excel, but am by no means an expert. I would appreciate any advice on functions and objects that I should be using for this script.
Hey MikeV from what I can gather, your problem seems more conceptual, less specific. What I mean is, have you started yet? Or looking at a blank script page?
I'm relatively new to coding, so I get that myself. What I do is make a list of what I need to do (what you have). Then think of the code or psuedo-code that would go with each step. Then you can start to build your script. You don't have to start with step one (as step 2/3 is often the more interesting bit), but let's do that.
Now, you need to search for a text string containing "Name:". I am proficient with VBA in excel, but haven't done anything for word. So I'd look it up. Googling "VBA find word in word document" will bring you to this page, which shows you how to approach step one. So steal their code, alter it to fit your needs and move on to step 2. Repeat the process, and that's how you build your algorithm! :)
Just a FYI, typically StackOverflow is for specific questions with an answer that can be confirmed, whereas you asked for help building an algorithm. I'd reserve those questions for your programming professor or friend who can help.
cheers
I have a pretty complex VBA plugin for Word written that automatically creates a report for me, using XML input, cycling through the X objects within the report to create the output. It is currently embedded into a Word Template file .DOCM.
I need to insert into the report a static list of text, based on the name of the item within the XML. For example, within my XML I have entries with a name BLAH1, BLAH2, BLAH3. Every time I see BLAH1, I need to match it with the static INSERT1, and BLAH2 match it with INSERT2, etc.
This seems simple enough, but her lies the problem...
It appears there are no Hashmap's in VBA without requiring external libraries, which I can't really rely on, since I can't install items on the machines where this will be running. As a result I can't store this reference data in a Hashmap as far as I can tell.
I can't seem to concatenate more than about 20 lines of strings together without hitting a max within VBA, and just parsing the chunk of text for what I need since there are about 1500 "lines" in my reference data, which greatly exceeds 20.
I also haven't found a way to embed a text, or any other type of file to hold this information within the file, and then parse the data.
I really would like to have everything within the single template file, without requiring additional text or other files to be bundled with the document. If there is no other option, I will go that route, but I wanted to see what create ideas people at Stackoverflow might have first ;-)
Have you considered using Word's Document Variables? They are name/value pairs stored invisibly within the document. (ActiveDocument.Variables("BLAH1").Value = "INSERT1" to create one, debug.print ActiveDocument.Variables("BLAH1").Value to retrieve a value (you have to use an error handler to detect non-existent indices if you go that route). Word can store (at least) hundreds of thousands of these things).