none
Rookie needs double help. RRS feed

  • Question

  • Hello everyone.  I'm Jay.  I've been visiting here for about a month but I haven't posted anything.  Just have been reading and trying different things.  I'm very new to programming.  I have no other experience with it.  But, I'd like to learn and start off at the beginning, the building blocks.

    Anyway, on to what I'd like to talk about.  I'm a teacher abroad and I made a program that my kids can search for English names to choose, if they wish to have one.  It works.  It functions fine I suppose.  Basically, it prompts the student if they are a boy or girl, which then makes the program know to look at the boy name section or girl name section.  Then, they can search names by letters that they like.

    So, I had to input each letter seperately.  I want to add names, but it becomes bulky and tedious.  I was wondering if theres a way to just make one large group for boys and one for girls, and somehow make the program pick out the names by the first letter.  I see people post their programs here but I don't really know how to do it, so I'll mimic some line here:

    if 'a' then

    textwindow.writeline("abbey, amy,")

    endif

    if 'b' then

    textwindow.writeline("bella, bianca")

    endif

    Like that.  Is it possible to just make a girls section and boys section and have it pull out names based on the first letter?

    I also have another question.  I work on the monthly challenges.  I'm on the lowest level one for this month.  I can make a program that converts fine.  But, I'm not able to get the proper units to show up when it converts.  I don't want to have an answer please.  Maybe just a simple nudge in the right direction, or, how/what I should be thinking for that.

    Thanks for reading.  If someone could also tell me how to post my program number that would be appreciated.  Like.. people will say KMB8766 for example.  How do I know what mine is for that? 

    Monday, February 20, 2012 3:06 PM

Answers

  • How about this?    WCN156-0  

    You'd better add "program.delay(1500)" at line:6


    • Edited by NaochanONEditor Wednesday, February 22, 2012 12:00 PM
    • Marked as answer by jaytep Thursday, February 23, 2012 5:49 AM
    Wednesday, February 22, 2012 11:47 AM
    Answerer
  • Oh, I guess I'm a lil' l8 to offer a solution. NaochanON replied one 1st.

    But either way, I'm gonna publish mine as well.

    This is my 1st post here and am still messing w/ MS Small Basic. When I saw yours, I thought it would be a nice excuse to experimenting with saving and loading files into my programs.

    So, instead of having the name examples splattered within the code, I've created 2 files, one for boys and the other for girl names.

    Respectively:   BoyNames.txt & GirlNames.txt

    I've copied and pasted all the names from WCN156 split in those 2 files.  Here it comes, 1st BoyNames.txt:

    Abel, Abraham, Ahmad, Albert, Alberto, Alec, Alfredo, Ali, Alvin, Amari, Amir, Andy, Angelo, Armando, Arthur, Arturo, Avery, Axel
    Beau, Bennett, Billy, Braxton, Brayan, Braylon, Brennan, Brent, Brett, Brock, Bryant, Bryson
    Cade, Calvin, Camden, Carl, Casey, Chad, Chance, Chandler, Charlie, Chris, Clayton, Cohen, Colby, Corbin, Corey, Curtis
    Dakota, Dallas, Damon, Dane, Danny, Dante, Darius, Darren, Davion, Davis, Dawson, Dean, Deandre, Declan, Dennis, Desmond, Donald, Dorian, Doublas, Drake, Dustin
    Easton, Eddie, Elliot, Emanuel, Emiliano, Emilio, Enrique, Ernesto, Esteban, Ezekiel, Ezra
    Felipe, Felix, Frank, Franklin, Frederick
    Gael, Gary, Gerardo, Graham, Grayson, Gregory, Griffin, Guillermo, Gustavo
    Harrison, Holden, Hudson, Hugo
    Ismael, Israel
    Jace, Jamal, Jamari, Jamarion, Javon, Jay, Jaylen, Jermaine, Jerry, Jimmy, Joaquin, Joe, Johnny, Jonas, Josue, Jude, Julio, Julius, Justice
    Kai, Keaton, Keegan, Keith, Kelvin, Kenny, Khalil, Kyler
    Lance, Lane, Larry, Lawrence, Leo, Leonel, Lorenzo, Louis, Luca
    Maddox, Malik, Marcos, Marshall, Martin, Marvin, Mateo, Maurice, Mauricio, Maximus, Mekhi, Melvin, Miles, Misael, Mitchell, Mohamed, Moises, Morgan
    Nasir, Nehemiah, Nelson, Noe
    Oliver, Omarion, Orlando, Osvaldo
    Pablo, Payton, Pedro, Phillip, Preston
    Quentin, Quincy
    Rafael, Ramon, Randy, Raul, Raymond, Reece, Reid, Ricky, Roberto, Rodney, Rodrigo, Rogelio, Roger, Roman, Ronald, Roy, Ruben, Russel, Ryder, Rylan
    Salvador, Sam, Santiago, Saul, Sawyer, Scott, Sergio, Silas, Simon, Skyler, Solomon
    Tate, Taylor, Terrance, Terrell, Terry, Theodore, Tobias, Toby, Tomas, Tommy, Tony, Trent, Trey, Troy, Tucker, Tyson
    Uriel
    Vance
    Walker, Walter, Weston, Wilson
    Xander
    Yahir
    Zachariah, Zander, Zane, Zion

    Now GirlNames.txt:

    Abby, Adeline, Aileen, Ainsley, Alana, Alayna, Alejandra, Alessandra, Alice, Alina, Alivia, Allie, Amari, Amaya, Amya, Anahi, Anastasia, Anaya, Angelica, Angie, Anika, Aniyah, Annabelle, Anne, Annie, Anya, April, Ariel, Aslee, Aspen, Athena, Aurora, Ayanna
    Bella, Bethany, Bianca, Brenda, Brenna, Bridget, Brielle, Brittany, Brynn
    Cadence, Callie, Cameron, Camila, Camille, Cara, Carly, Carmen, Carolina, Carolyn, Casey, Cassandra, Cassidy, Cecilia, Celeste, Chelsea, Cheyenne, Christine, Cindy, Clara, Clarissa, Claudia, Cora, Crystal, Cynthia
    Dakota, Dana, Danna, Daphne, Dayana, Dayanara, Deanna, Delaney, Denise, Desiree, Diamond, Dominique, Dulce
    Eden, Elaina, Elenor, Eliana, Elisa, Elise, Eliza, Elle, Ellen, Ellie, Emilia, Erica, Esmerelda, Esther, Estrella
    Fatima, Fernanda, Fiona, Francesca
    Genevieve, Georgia, Gloria, Guadalupe
    Halle, Harley, Harmony, Hayden, Heather, Heaven, Heidi, Helen, Helena, Holly, Hope
    Imani, India, Iris, Isis, Itzel, Ivy
    Jaden, Jaelyn, Jamie, Jane, Janelle, Janet, Janiya, Jayla, Jenny, Jimena, Joanna, Josephine, Josie, Joy, Judith, Julianna, Julie, Julissa, Justice
    Kadence, Kailyn, Kali, Kara, Karla, Kathleen, Katrina, Kaylin, Keira, Kelly, Kelsey, Kendra, Kiana, Kiera, Kiersten, Kiley, Kira, Kirsten, Kristen, Kyla, Kyra
    Lacey, Lana, Larissa, Leilani, Lexi, Lia, Liberty, Liliana, Linda, Lisa, Litzy, Lizbeth, Logan, Lola, London, Lucia, Lucy
    Macy, Madeleine, Maggie, Makenna, Malia, Mallory, Marie, Marina, Marisol, Maritza, Marlene, Marley, Martha, Mckenna, Melany, Melina, Melody, Mercedes, Meredith, Miracle, Miriam, Monica, Monique
    Nadia, Nancy, Natasha, Nayeli, Nina, Noelle, Nora, Nyla
    Olivia, Ophelia
    Paris, Patricia, Paulina, Penelope, Perla, Phoebe, Piper, Precious, Presley, Priscilla
    
    Raquel, Raven, Renee, Rosa, Rose, Ruth, Ryan
    Sabrina, Sadie, Sage, Samara, Sandra, Sarai, Sasha, Scarlett, Selena, Serena, Serenity, Shania, Shannon, Shayla, Sienna, Simone, Skye, Skyla, Skyler, Stella, Sylvia
    Tabitha, Talia, Tamia, Tara, TarynmTatum, Teagan, Teresa, Tessa, Tia, Tiana, Tiffany, Tori
    
    Valentina, Veronica, Violet, Virginia, Vivian, Viviana
    Wendy, Whitney, Willow
    Ximena
    Yadira, Yasmin, Yasmine, Yesenia

    Each one of them has 26 lines, representing a letter from the alphabet :-)

    PS: Gonna resume this post below...


    • Proposed as answer by GoToLoopEditor Wednesday, February 22, 2012 7:03 PM
    • Marked as answer by jaytep Thursday, February 23, 2012 5:49 AM
    • Edited by GoToLoopEditor Friday, February 24, 2012 2:49 PM SawyerScott, names were sticked together
    Wednesday, February 22, 2012 6:38 PM
    Answerer
  • I've created these 2 following subroutines to read those 2 files and transfer them into a 2D array. Here are they:

    '==============================================================
    
    Sub Initialize_Array_Names
      ' this sub calls: Fill_in_Names_from_File()
      
      folder= Program.Directory + "\
      data=   "Names.txt
      
      gender= "Boy
      Fill_in_Names_from_File()   ' calls subroutine to retrieve names from ...\BoyNames.txt
      
      gender= "Girl
      Fill_in_Names_from_File()   ' calls subroutine to retrieve names from ...\GirlNames.txt
      
    EndSub
    
    '==============================================================
    
    Sub Fill_in_Names_from_File
      ' this sub is called from: Initialize_Names_Array()
      ' reads file records and transfer them to a 2D-array
      
      path= folder + gender + data
      ' full path to the file containing the name examples
      ' either   ...\BoyNames.txt   or   ...\GirlNames.txt
      
      For line= 1 To 26
        ' each 1 of the 26 lines contains names starting w/ a particular letter from 'A' to 'Z'
        
        letter= Text.GetCharacter(line + 64)
        ' obtains a letter corresponding to its ASCII code line #
        
        names[gender][letter]= File.ReadLine(path,line)
        ' Ex.:  names["Girl"]["O"]=  "Olivia, Ophelia"   w/ line= 15  &  letter= 15+64 = 79 = "O"
        
      EndFor
      
    EndSub
    
    '==============================================================

    Both BoyNames.txt & GirlNames.txt must reside in the same folder as the code since it uses Program.Directory to find out their paths.

    The code uses the variable 'gender' as a flag to decide which file to read from and where to store them inside the array.

    The code is very well commented, so I hope you, jaytep, can understand it easily ^^

    You told that you didn't know many Small Basic commands. I wonder if you've already read the manual, available in many languages. There are also many slides in PowerPoint somewhere around here; and even some videos on YouTube!

    PS: Gonna publish the whole code I've re-written from you below.


    • Proposed as answer by GoToLoopEditor Wednesday, February 22, 2012 7:04 PM
    • Marked as answer by jaytep Thursday, February 23, 2012 5:49 AM
    • Edited by GoToLoopEditor Tuesday, February 28, 2012 1:59 AM
    Wednesday, February 22, 2012 7:03 PM
    Answerer
  • ' Initialize constants for special control characters in ASCII code: BEL= Text.GetCharacter ( 7) ' Makes internal PC-Speaker buzz BS= Text.GetCharacter ( 8) ' Backspace TAB= Text.GetCharacter ( 9) ' Horizontal Tabulation (HT) LF= Text.GetCharacter (10) ' Line-Feed (jumps a line) CR= Text.GetCharacter (13) ' Carriage Return ESC= Text.GetCharacter (27) ' "Esc" Key ARW= Text.GetCharacter (26) ' Right Arrow SPC= " " ' SPaCe ' Initialize screen: TextWindow.Title= "Boys & Girls Name Choosing Helper TextWindow.Left= 200 TextWindow.Top= 300 CharColor= "Green ScrColor= "Black ' Initialize array and other variables: Initialize_Array_Names() ' Input from user: Start: TextWindow.Clear() TextWindow.ForegroundColor= CharColor TextWindow.BackgroundColor= ScrColor TextWindow.Write("Please, type in your name " + ARW + SPC) TextWindow.BackgroundColor= "DarkGray user= TextWindow.Read() TextWindow.BackgroundColor= ScrColor TextWindow.Write (LF + "Hello, " + user) TextWindow.WriteLine(", I'm going to help you out to choose a name!") TextWindow.WriteLine("But first, do you want a boy or a girl name?" + LF) TextWindow.ForegroundColor= "Magenta TextWindow.WriteLine("Press '1' or 'B' for boys, '2' or 'G' for girls" + LF) TextWindow.ForegroundColor= CharColor

    Choose:
    gender= Text.ConvertToUpperCase( TextWindow.ReadKey() )
    If      gender = "1" Or gender = "B" Then
      gender= "Boy
    ElseIf  gender = "2" Or gender = "G" Then
      gender= "Girl
    Else
      Sound.PlayBellRing()
      Goto Choose  ' goes back to read a key input until a valid one is finally pressed!
    EndIf

    TextWindow.Write    ("Now " + user) TextWindow.WriteLine(", think of a letter you like and punch it.") TextWindow.WriteLine("We got some name tips from all over the alphabet! :D" + LF) TextWindow.WriteLine("If you wish to start over, just hit 'Space',") TextWindow.WriteLine("or 'Esc' if you'd rather prefer to quit." + LF) If gender = "Boy" Then TextWindow.ForegroundColor= "Blue Else TextWindow.ForegroundColor= "Red EndIf ' Display-Names "Main Loop": Loop: letter= Text.ConvertToUpperCase( TextWindow.ReadKey() ) ascii= Text.GetCharacterCode(letter) record= names[gender][letter] If letter = SPC Then Sound.PlayChime() Goto Start EndIf If letter = ESC Then Sound.PlayChimesAndWait() Program.End() EndIf If ascii < 65 Or ascii > 65+25 Then ' capital "A"=65 in ASCII/Unicode Sound.PlayBellRing() ' play bell sound if anything diff. from a letter was pressed! :P Goto Loop EndIf If record = "" Then TextWindow.Write("So sorry, no name records starting w/ letter " + ARW + SPC) TextWindow.BackgroundColor= "Yellow TextWindow.WriteLine(letter + LF + BEL) TextWindow.BackgroundColor= ScrColor Else TextWindow.BackgroundColor= "Cyan TextWindow.Write (letter) TextWindow.BackgroundColor= ScrColor TextWindow.WriteLine(ARW + SPC + record + LF) Sound.PlayClick() EndIf Goto Loop


    I've stretched the code a lil' longer me guess. But don't threat on asking about any doubts you may have on it. Peace out! ^_^






    • Proposed as answer by GoToLoopEditor Wednesday, February 22, 2012 7:19 PM
    • Marked as answer by jaytep Thursday, February 23, 2012 5:49 AM
    • Edited by GoToLoopEditor Tuesday, February 28, 2012 3:18 AM
    Wednesday, February 22, 2012 7:12 PM
    Answerer

All replies

  • First to publish a code and get the 6 digit code, you need internet access and just hit the Publish button on the SmallBasic IDE interface.

    On the boy-girl issue, we could use two arrays or something similar, perhaps loading the names from a file and perhaps with a sorting method to order them alphabetically.

    Depending on what you want to do there are past examples on this forum I could point you to (e.g. sorting) or perhaps make some suggestions based on your code.  Other peoples answres to the challenges is a good way to get some ideas.

    Monday, February 20, 2012 6:45 PM
    Moderator
  • Thanks for replying.  I understand about the 6 digit code thing now, thanks.

    I'm not familiar with arrays just yet, or loading them from a file.  Do you mean like, I can make a file outside of SmallBasic and pull information out of it.  Like a saved word file?

    Okay, I'll check out some other answers.  I think I have an idea for what I want to do but I'm not sure how hard it could be, I don't think it should be so hard, maybe I'm just thinking too much.

    Anyway, here is my program for names: WCN156

    Any advice other than what I asked for before would be helpful.  The way I did it was the only way I knew how to make it work.  It seems big and bulky and maybe it can be done a better way. 

    I didn't make it pretty, I haven't started learning that stuff just yet.  I know how to change the colors and whatnot, but thats about it.


    EDIT: By the way, I'm working on a finish point.  For example, having it promp to ask for another letter, or to type finish to end their session.  Something like that.  I haven't figure that out yet, but I'm working on it, testing it out.  I know at the moment you have to restart the program in order to go from boy to girl or girl to boy.
    • Edited by jaytep Tuesday, February 21, 2012 12:55 PM
    • Proposed as answer by GoToLoopEditor Wednesday, February 22, 2012 6:16 PM
    • Unproposed as answer by GoToLoopEditor Wednesday, February 22, 2012 6:16 PM
    Tuesday, February 21, 2012 12:49 PM
  • jaytep,

    Your program works well, and as you suspect it is quite long.  Arrays would be the way to go ultimately, possibly with names stored in files.  However what you have is good and as you learn about arrays and files these methods can come later.

    Perhaps also one way to handle the boy/girl issue would be to put all the boy stuff in one subroutine and the girls in another.  This will make the program more modular so it can be extended more easily when or if you move to arrays.  It would remove the GoTo statements which are generally not recommended if at all possible since they can lead to code that is hard to understand, debug or develop.

    Tuesday, February 21, 2012 6:47 PM
    Moderator
  • Thanks, I'm going to take a look at how arrays and subroutines work.  I'm working my way through the tutorial PDF file trying to learn and practice through that.  I made this program for two reasons.  To just try and do something, and to use it as a practical program for my students.

    I think I will keep this program as a sort of starting point and just work on it as I learn things.  I can add and change it as I learn new things.  I had a few minutes at work to read the definitions of arrays and subroutines and I can sort of understand how they work and they will surely help me.  I'll do my best to test out how to use them to implement them into the program.

    I will try to finish the challenge program and see if it can work here when I post the program code.

    Wednesday, February 22, 2012 9:19 AM
  • How about this?    WCN156-0  

    You'd better add "program.delay(1500)" at line:6


    • Edited by NaochanONEditor Wednesday, February 22, 2012 12:00 PM
    • Marked as answer by jaytep Thursday, February 23, 2012 5:49 AM
    Wednesday, February 22, 2012 11:47 AM
    Answerer
  • Wow, thanks NaochanON.  I'm going to take a deep look at that when I can.  I don't know many of the commands, but I can sort of understand it.  This is what I thought it should look like.  I can add to it as I'd please.  I just don't know enough commands to effectively do what I want to do just yet.

    Wednesday, February 22, 2012 12:50 PM
  • Oh, I guess I'm a lil' l8 to offer a solution. NaochanON replied one 1st.

    But either way, I'm gonna publish mine as well.

    This is my 1st post here and am still messing w/ MS Small Basic. When I saw yours, I thought it would be a nice excuse to experimenting with saving and loading files into my programs.

    So, instead of having the name examples splattered within the code, I've created 2 files, one for boys and the other for girl names.

    Respectively:   BoyNames.txt & GirlNames.txt

    I've copied and pasted all the names from WCN156 split in those 2 files.  Here it comes, 1st BoyNames.txt:

    Abel, Abraham, Ahmad, Albert, Alberto, Alec, Alfredo, Ali, Alvin, Amari, Amir, Andy, Angelo, Armando, Arthur, Arturo, Avery, Axel
    Beau, Bennett, Billy, Braxton, Brayan, Braylon, Brennan, Brent, Brett, Brock, Bryant, Bryson
    Cade, Calvin, Camden, Carl, Casey, Chad, Chance, Chandler, Charlie, Chris, Clayton, Cohen, Colby, Corbin, Corey, Curtis
    Dakota, Dallas, Damon, Dane, Danny, Dante, Darius, Darren, Davion, Davis, Dawson, Dean, Deandre, Declan, Dennis, Desmond, Donald, Dorian, Doublas, Drake, Dustin
    Easton, Eddie, Elliot, Emanuel, Emiliano, Emilio, Enrique, Ernesto, Esteban, Ezekiel, Ezra
    Felipe, Felix, Frank, Franklin, Frederick
    Gael, Gary, Gerardo, Graham, Grayson, Gregory, Griffin, Guillermo, Gustavo
    Harrison, Holden, Hudson, Hugo
    Ismael, Israel
    Jace, Jamal, Jamari, Jamarion, Javon, Jay, Jaylen, Jermaine, Jerry, Jimmy, Joaquin, Joe, Johnny, Jonas, Josue, Jude, Julio, Julius, Justice
    Kai, Keaton, Keegan, Keith, Kelvin, Kenny, Khalil, Kyler
    Lance, Lane, Larry, Lawrence, Leo, Leonel, Lorenzo, Louis, Luca
    Maddox, Malik, Marcos, Marshall, Martin, Marvin, Mateo, Maurice, Mauricio, Maximus, Mekhi, Melvin, Miles, Misael, Mitchell, Mohamed, Moises, Morgan
    Nasir, Nehemiah, Nelson, Noe
    Oliver, Omarion, Orlando, Osvaldo
    Pablo, Payton, Pedro, Phillip, Preston
    Quentin, Quincy
    Rafael, Ramon, Randy, Raul, Raymond, Reece, Reid, Ricky, Roberto, Rodney, Rodrigo, Rogelio, Roger, Roman, Ronald, Roy, Ruben, Russel, Ryder, Rylan
    Salvador, Sam, Santiago, Saul, Sawyer, Scott, Sergio, Silas, Simon, Skyler, Solomon
    Tate, Taylor, Terrance, Terrell, Terry, Theodore, Tobias, Toby, Tomas, Tommy, Tony, Trent, Trey, Troy, Tucker, Tyson
    Uriel
    Vance
    Walker, Walter, Weston, Wilson
    Xander
    Yahir
    Zachariah, Zander, Zane, Zion

    Now GirlNames.txt:

    Abby, Adeline, Aileen, Ainsley, Alana, Alayna, Alejandra, Alessandra, Alice, Alina, Alivia, Allie, Amari, Amaya, Amya, Anahi, Anastasia, Anaya, Angelica, Angie, Anika, Aniyah, Annabelle, Anne, Annie, Anya, April, Ariel, Aslee, Aspen, Athena, Aurora, Ayanna
    Bella, Bethany, Bianca, Brenda, Brenna, Bridget, Brielle, Brittany, Brynn
    Cadence, Callie, Cameron, Camila, Camille, Cara, Carly, Carmen, Carolina, Carolyn, Casey, Cassandra, Cassidy, Cecilia, Celeste, Chelsea, Cheyenne, Christine, Cindy, Clara, Clarissa, Claudia, Cora, Crystal, Cynthia
    Dakota, Dana, Danna, Daphne, Dayana, Dayanara, Deanna, Delaney, Denise, Desiree, Diamond, Dominique, Dulce
    Eden, Elaina, Elenor, Eliana, Elisa, Elise, Eliza, Elle, Ellen, Ellie, Emilia, Erica, Esmerelda, Esther, Estrella
    Fatima, Fernanda, Fiona, Francesca
    Genevieve, Georgia, Gloria, Guadalupe
    Halle, Harley, Harmony, Hayden, Heather, Heaven, Heidi, Helen, Helena, Holly, Hope
    Imani, India, Iris, Isis, Itzel, Ivy
    Jaden, Jaelyn, Jamie, Jane, Janelle, Janet, Janiya, Jayla, Jenny, Jimena, Joanna, Josephine, Josie, Joy, Judith, Julianna, Julie, Julissa, Justice
    Kadence, Kailyn, Kali, Kara, Karla, Kathleen, Katrina, Kaylin, Keira, Kelly, Kelsey, Kendra, Kiana, Kiera, Kiersten, Kiley, Kira, Kirsten, Kristen, Kyla, Kyra
    Lacey, Lana, Larissa, Leilani, Lexi, Lia, Liberty, Liliana, Linda, Lisa, Litzy, Lizbeth, Logan, Lola, London, Lucia, Lucy
    Macy, Madeleine, Maggie, Makenna, Malia, Mallory, Marie, Marina, Marisol, Maritza, Marlene, Marley, Martha, Mckenna, Melany, Melina, Melody, Mercedes, Meredith, Miracle, Miriam, Monica, Monique
    Nadia, Nancy, Natasha, Nayeli, Nina, Noelle, Nora, Nyla
    Olivia, Ophelia
    Paris, Patricia, Paulina, Penelope, Perla, Phoebe, Piper, Precious, Presley, Priscilla
    
    Raquel, Raven, Renee, Rosa, Rose, Ruth, Ryan
    Sabrina, Sadie, Sage, Samara, Sandra, Sarai, Sasha, Scarlett, Selena, Serena, Serenity, Shania, Shannon, Shayla, Sienna, Simone, Skye, Skyla, Skyler, Stella, Sylvia
    Tabitha, Talia, Tamia, Tara, TarynmTatum, Teagan, Teresa, Tessa, Tia, Tiana, Tiffany, Tori
    
    Valentina, Veronica, Violet, Virginia, Vivian, Viviana
    Wendy, Whitney, Willow
    Ximena
    Yadira, Yasmin, Yasmine, Yesenia

    Each one of them has 26 lines, representing a letter from the alphabet :-)

    PS: Gonna resume this post below...


    • Proposed as answer by GoToLoopEditor Wednesday, February 22, 2012 7:03 PM
    • Marked as answer by jaytep Thursday, February 23, 2012 5:49 AM
    • Edited by GoToLoopEditor Friday, February 24, 2012 2:49 PM SawyerScott, names were sticked together
    Wednesday, February 22, 2012 6:38 PM
    Answerer
  • I've created these 2 following subroutines to read those 2 files and transfer them into a 2D array. Here are they:

    '==============================================================
    
    Sub Initialize_Array_Names
      ' this sub calls: Fill_in_Names_from_File()
      
      folder= Program.Directory + "\
      data=   "Names.txt
      
      gender= "Boy
      Fill_in_Names_from_File()   ' calls subroutine to retrieve names from ...\BoyNames.txt
      
      gender= "Girl
      Fill_in_Names_from_File()   ' calls subroutine to retrieve names from ...\GirlNames.txt
      
    EndSub
    
    '==============================================================
    
    Sub Fill_in_Names_from_File
      ' this sub is called from: Initialize_Names_Array()
      ' reads file records and transfer them to a 2D-array
      
      path= folder + gender + data
      ' full path to the file containing the name examples
      ' either   ...\BoyNames.txt   or   ...\GirlNames.txt
      
      For line= 1 To 26
        ' each 1 of the 26 lines contains names starting w/ a particular letter from 'A' to 'Z'
        
        letter= Text.GetCharacter(line + 64)
        ' obtains a letter corresponding to its ASCII code line #
        
        names[gender][letter]= File.ReadLine(path,line)
        ' Ex.:  names["Girl"]["O"]=  "Olivia, Ophelia"   w/ line= 15  &  letter= 15+64 = 79 = "O"
        
      EndFor
      
    EndSub
    
    '==============================================================

    Both BoyNames.txt & GirlNames.txt must reside in the same folder as the code since it uses Program.Directory to find out their paths.

    The code uses the variable 'gender' as a flag to decide which file to read from and where to store them inside the array.

    The code is very well commented, so I hope you, jaytep, can understand it easily ^^

    You told that you didn't know many Small Basic commands. I wonder if you've already read the manual, available in many languages. There are also many slides in PowerPoint somewhere around here; and even some videos on YouTube!

    PS: Gonna publish the whole code I've re-written from you below.


    • Proposed as answer by GoToLoopEditor Wednesday, February 22, 2012 7:04 PM
    • Marked as answer by jaytep Thursday, February 23, 2012 5:49 AM
    • Edited by GoToLoopEditor Tuesday, February 28, 2012 1:59 AM
    Wednesday, February 22, 2012 7:03 PM
    Answerer
  • ' Initialize constants for special control characters in ASCII code: BEL= Text.GetCharacter ( 7) ' Makes internal PC-Speaker buzz BS= Text.GetCharacter ( 8) ' Backspace TAB= Text.GetCharacter ( 9) ' Horizontal Tabulation (HT) LF= Text.GetCharacter (10) ' Line-Feed (jumps a line) CR= Text.GetCharacter (13) ' Carriage Return ESC= Text.GetCharacter (27) ' "Esc" Key ARW= Text.GetCharacter (26) ' Right Arrow SPC= " " ' SPaCe ' Initialize screen: TextWindow.Title= "Boys & Girls Name Choosing Helper TextWindow.Left= 200 TextWindow.Top= 300 CharColor= "Green ScrColor= "Black ' Initialize array and other variables: Initialize_Array_Names() ' Input from user: Start: TextWindow.Clear() TextWindow.ForegroundColor= CharColor TextWindow.BackgroundColor= ScrColor TextWindow.Write("Please, type in your name " + ARW + SPC) TextWindow.BackgroundColor= "DarkGray user= TextWindow.Read() TextWindow.BackgroundColor= ScrColor TextWindow.Write (LF + "Hello, " + user) TextWindow.WriteLine(", I'm going to help you out to choose a name!") TextWindow.WriteLine("But first, do you want a boy or a girl name?" + LF) TextWindow.ForegroundColor= "Magenta TextWindow.WriteLine("Press '1' or 'B' for boys, '2' or 'G' for girls" + LF) TextWindow.ForegroundColor= CharColor

    Choose:
    gender= Text.ConvertToUpperCase( TextWindow.ReadKey() )
    If      gender = "1" Or gender = "B" Then
      gender= "Boy
    ElseIf  gender = "2" Or gender = "G" Then
      gender= "Girl
    Else
      Sound.PlayBellRing()
      Goto Choose  ' goes back to read a key input until a valid one is finally pressed!
    EndIf

    TextWindow.Write    ("Now " + user) TextWindow.WriteLine(", think of a letter you like and punch it.") TextWindow.WriteLine("We got some name tips from all over the alphabet! :D" + LF) TextWindow.WriteLine("If you wish to start over, just hit 'Space',") TextWindow.WriteLine("or 'Esc' if you'd rather prefer to quit." + LF) If gender = "Boy" Then TextWindow.ForegroundColor= "Blue Else TextWindow.ForegroundColor= "Red EndIf ' Display-Names "Main Loop": Loop: letter= Text.ConvertToUpperCase( TextWindow.ReadKey() ) ascii= Text.GetCharacterCode(letter) record= names[gender][letter] If letter = SPC Then Sound.PlayChime() Goto Start EndIf If letter = ESC Then Sound.PlayChimesAndWait() Program.End() EndIf If ascii < 65 Or ascii > 65+25 Then ' capital "A"=65 in ASCII/Unicode Sound.PlayBellRing() ' play bell sound if anything diff. from a letter was pressed! :P Goto Loop EndIf If record = "" Then TextWindow.Write("So sorry, no name records starting w/ letter " + ARW + SPC) TextWindow.BackgroundColor= "Yellow TextWindow.WriteLine(letter + LF + BEL) TextWindow.BackgroundColor= ScrColor Else TextWindow.BackgroundColor= "Cyan TextWindow.Write (letter) TextWindow.BackgroundColor= ScrColor TextWindow.WriteLine(ARW + SPC + record + LF) Sound.PlayClick() EndIf Goto Loop


    I've stretched the code a lil' longer me guess. But don't threat on asking about any doubts you may have on it. Peace out! ^_^






    • Proposed as answer by GoToLoopEditor Wednesday, February 22, 2012 7:19 PM
    • Marked as answer by jaytep Thursday, February 23, 2012 5:49 AM
    • Edited by GoToLoopEditor Tuesday, February 28, 2012 3:18 AM
    Wednesday, February 22, 2012 7:12 PM
    Answerer
  • Wow, thanks so much for going through the time and trouble to do that!  I'm going to really take the time to look at all of this code and learn how and why it works.  I want my programs to end up like this.  I sort of have an idea of what it should be but I just don't know all those commands just yet.

    I'm going to mess around with it as soon as I can =)

    Thanks so much.


    EDIT:  Forgot to ask, but what are those files that you made with the names in them.  Is it a word file or what is that? 
    • Edited by jaytep Thursday, February 23, 2012 5:50 AM
    Thursday, February 23, 2012 5:49 AM
  • Hi jaytep!

    Those 2 files are:

    • BoyNames.txt
    • GirlNames.txt

    To make them, you have to use a pure TEXT editor like Notepad, Notepad++ or even the MS Small Basic itself! If you use the internal Small Basic's editor to create them, just remove the .sb extension at the end of the file name ;-)

    WORD processors don't render normal characters only, but lots of control and format codes along. That's why you can't use any "Office" programs to edit texts to be used for programming. Just try to open a .doc file inside Notepad and you will see :P

    To make those, I just copied the boys and girls' names from your code (WCN156). I published them in my 1st post. Just Control+C them, and Control+V inside some text editor and voilà!

    Just do not forget to put those 2 files inside the same folder as the rest of the program.

    Good luck!



    Thursday, February 23, 2012 12:08 PM
    Answerer
  • Ah, I understand.  Actually, I tried some things at work when I had my free hour.  I was able to figue out to use the notepad.  I saved them as girlname.txt and boyname.txt before I saw your post, missing the 's' at the end, so I had trouble with the program.  Before I went and changed the text file I wanted to see if I could fix it in your code and I found it.

    Its no great feat.  But, as a total beginner I was totaly excited that I figured it out and now I understand that part of the code. 

    To all you guys who have posted here, I really appreciate your replies, all of them.  I'm so excited to be starting this and I'm learning a lot from your help.  I'm having so much fun going through all the code you guys have changed and showed me and also trying to figure it out and learn it, see what each part does etc. 

    Thursday, February 23, 2012 4:03 PM