From: Preschool Mike on 8 Apr 2010 19:54 I'm trying to use a userform to collect a list of words (i.e., 20) to later diplay in a shape or textbox (as flash cards) in my presentation.. What's the best way to collect and store my list? I know I could do something like word1 = userform1.textbox1.text, word2 = userform1.textbox2.text and so on but I thought an array would simplifiy things. The only problem is I'm completely confused when it comes to using arrays. Also, I guess since I'm here, how would I later retrieve my list for display in one textbox, one word at a time (e.g., click my word button and the first word appears and click my word button again and the second word appears). Thanks so much! -- Mike Mast Special Education Preschool Teacher
From: Steve Rindsberg on 8 Apr 2010 21:26 In article <1494401D-83B1-4C08-AE46-922CA05A6875(a)microsoft.com>, Preschool Mike wrote: > I'm trying to use a userform to collect a list of words (i.e., 20) to later > diplay in a shape or textbox (as flash cards) in my presentation.. What's > the best way to collect and store my list? I know I could do something like > word1 = userform1.textbox1.text, word2 = userform1.textbox2.text and so on > but I thought an array would simplifiy things. The only problem is I'm > completely confused when it comes to using arrays. Also, I guess since I'm > here, how would I later retrieve my list for display in one textbox, one word > at a time (e.g., click my word button and the first word appears and click my > word button again and the second word appears). ' AirCode Dim arayWords(1 to 20) as String arayWords(1)= userform1.textbox1.text arayWords(2)= userform1.textbox2.text ' and so on ' Or you could give each of the text boxes a ' predictable name, say MyText1, MyText2 and so on, ' then Dim oCtl as Control Dim x as long x = 1 For each oCtl in Userform1.Controls If Instr(oCtl.Name,"MyText") > 0 Then arayWords(x) = .Item(x).text x = x+1 End If Next To display them, something like this: Sub MyWord() ' would need to have arayWords declared as public ' at top of module Static WordIndex as Long ' reset the counter if we've used all the words If WordIndex > 20 then WordIndex = 1 MsgBox arayWords(WordIndex) WordIndex = WordIndex + 1 End Sub ============================== PPT Frequently Asked Questions http://www.pptfaq.com/ PPTools add-ins for PowerPoint http://www.pptools.com/
From: Tamutka on 9 Apr 2010 01:50 On Apr 9, 3:26 am, Steve Rindsberg <ab...(a)localhost.com> wrote: > In article <1494401D-83B1-4C08-AE46-922CA05A6...(a)microsoft.com>, Preschool Mike > wrote: > > > I'm trying to use a userform to collect a list of words (i.e., 20) to later > > diplay in a shape or textbox (as flash cards) in my presentation.. What's > > the best way to collect and store my list? I know I could do something like > > word1 = userform1.textbox1.text, word2 = userform1.textbox2.text and so on > > but I thought an array would simplifiy things. The only problem is I'm > > completely confused when it comes to using arrays. Also, I guess since I'm > > here, how would I later retrieve my list for display in one textbox, one word > > at a time (e.g., click my word button and the first word appears and click my > > word button again and the second word appears). > > ' AirCode > Dim arayWords(1 to 20) as String > > arayWords(1)= userform1.textbox1.text > arayWords(2)= userform1.textbox2.text > ' and so on > > ' Or you could give each of the text boxes a > ' predictable name, say MyText1, MyText2 and so on, > ' then > > Dim oCtl as Control > Dim x as long > x = 1 > For each oCtl in Userform1.Controls > If Instr(oCtl.Name,"MyText") > 0 Then > arayWords(x) = .Item(x).text > x = x+1 > End If > Next > > To display them, something like this: > > Sub MyWord() > ' would need to have arayWords declared as public > ' at top of module > Static WordIndex as Long > ' reset the counter if we've used all the words > If WordIndex > 20 then WordIndex = 1 > MsgBox arayWords(WordIndex) > WordIndex = WordIndex + 1 > End Sub > > ============================== > PPT Frequently Asked Questionshttp://www.pptfaq.com/ > > PPTools add-ins for PowerPointhttp://www.pptools.com/ Hi, I am confused and curious: this seems very interresteing, but I do not know how and where to use. Can anyone explain me more deeply, please? Or show me an example? Thank you! Natasa
From: David Marcovitz on 9 Apr 2010 10:23 Mike, I'm guessing you read the section in my book about arrays and are still confused so I'm not sure I can explain it any better, but I'll try. You know what a variable is, a place to store one piece of information. An array is simply a bunch of numbered boxes to store multiple pieces of the same kind of information. For example if you want a bunch of words, you could use: Dim myword1 As String Dim myword2 As String Dim myword3 As String .... I do this a lot because it is easy to understand. However, you might want to simplify this by using an array. If you want an array with 20 items, you would do Dim myword(20) As String The tricky part about this is that it gives you 20 items, numbered 0 through 19: myword(0), myword(1), myword(2), ..., myword(19) Only a computer geek starts counting at 0 so this is confusing. Steve, in his example, uses the nice trick to tell the computer that he wants to start counting at 1: Dim myword(1 To 20) As String Now, you have: myword(1), myword(2), myword(3), ..., myword(20) This might confuse a computer geek, but it is much easier for the rest of us. Now, once you have an array, you can pretend that you don't have an array and just access the elements of the array like you would a bunch of individual variables: myword(1) = "mom" myword(2) = "dad" myword(3) = "cat" .... myword(20) = "noodle" That will work fine, but it defeats the purpose of having an array (except that you have only one simple Dim statement). The power of the array is that you can access different elements by number. This is great if you want to access one randomly (e.g., generate a random number between 1 and 20, put it in the variable myRandNum and then access myWord(myRandNum) ), or if you want to use a variable in any other way to decide which array element to access (perhaps, based on which button is pressed or which slide you are on). It is also great if you want to cycle through the elements of the array: For i = 1 To 20 MsgBox myWord(i) Next i This just displays each element of the array in succeeding message boxes. Two other quick notes about arrays. Arrays can be multidimensional so you could, for example, use an array to represent a checkerboard, referring to rows and columns. But that gets a bit more complicated and is beyond what you want to know now. You also don't need to know in advance how many elements the array is going to have (possibly you want to define it based on user input). For that you can read the section of my book about ReDim. I hope this makes it a little clearer, and I hope Steve's code does what you want. --David On 4/8/10 7:54 PM, Preschool Mike wrote: > I'm trying to use a userform to collect a list of words (i.e., 20) to later > diplay in a shape or textbox (as flash cards) in my presentation.. What's > the best way to collect and store my list? I know I could do something like > word1 = userform1.textbox1.text, word2 = userform1.textbox2.text and so on > but I thought an array would simplifiy things. The only problem is I'm > completely confused when it comes to using arrays. Also, I guess since I'm > here, how would I later retrieve my list for display in one textbox, one word > at a time (e.g., click my word button and the first word appears and click my > word button again and the second word appears). > > Thanks so much! -- David M. Marcovitz Author of _Powerful PowerPoint for Educators_ http://www.PowerfulPowerPoint.com/ Microsoft PowerPoint MVP Associate Professor, Loyola University Maryland
From: Steve Rindsberg on 9 Apr 2010 11:17
In article <3b2747dd-c66a-4135-aebb- a1f4c84450e5(a)g30g2000yqc.googlegroups.com>, Tamutka wrote: > On Apr 9, 3:26 am, Steve Rindsberg <ab...(a)localhost.com> wrote: > > In article <1494401D-83B1-4C08-AE46-922CA05A6...(a)microsoft.com>, Preschoo > l Mike > > wrote: > > > > > I'm trying to use a userform to collect a list of words (i.e., 20) to l > ater > > > diplay in a shape or textbox (as flash cards) in my presentation.. W > hat's > > > the best way to collect and store my list? I know I could do somethi > ng like > > > word1 = userform1.textbox1.text, word2 = userform1.textbox2.text an > d so on > > > but I thought an array would simplifiy things. The only problem is I > 'm > > > completely confused when it comes to using arrays. Also, I guess sin > ce I'm > > > here, how would I later retrieve my list for display in one textbox, on > e word > > > at a time (e.g., click my word button and the first word appears and cl > ick my > > > word button again and the second word appears). > > > > ' AirCode > > Dim arayWords(1 to 20) as String > > > > arayWords(1)= userform1.textbox1.text > > arayWords(2)= userform1.textbox2.text > > ' and so on > > > > ' Or you could give each of the text boxes a > > ' predictable name, say MyText1, MyText2 and so on, > > ' then > > > > Dim oCtl as Control > > Dim x as long > > x = 1 > > For each oCtl in Userform1.Controls > > If Instr(oCtl.Name,"MyText") > 0 Then > > arayWords(x) = .Item(x).text > > x = x+1 > > End If > > Next > > > > To display them, something like this: > > > > Sub MyWord() > > ' would need to have arayWords declared as public > > ' at top of module > > Static WordIndex as Long > > ' reset the counter if we've used all the words > > If WordIndex > 20 then WordIndex = 1 > > MsgBox arayWords(WordIndex) > > WordIndex = WordIndex + 1 > > End Sub > > > > ======================== > ====== > > PPT Frequently Asked Questionshttp://www.pptfaq.com/ > > > > PPTools add-ins for PowerPointhttp://www.pptools.com/ > > Hi, > I am confused and curious: this seems very interresteing, but I do not > know how and where to use. Can anyone explain me more deeply, please? > Or show me an example? My understanding is that Mike wants to keep a list of words (entered in a dialog box/user form) and then each time a user clicks a button in PowerPoint during a presentation, to display one of those words. Putting the words into an array allows him to create and hold the list. The code in MyWord shows how to retrieve the next word from the array (list of words). In real life, he'd modify MyWord to do something other than simply display the word in a MsgBox. ============================== PPT Frequently Asked Questions http://www.pptfaq.com/ PPTools add-ins for PowerPoint http://www.pptools.com/ |