MSDN > 論壇首頁 > Small Basic > Post your sample source code here and get featured on our blogs! (Part II)
發問發問
 

置頂Post your sample source code here and get featured on our blogs! (Part II)

所有回覆

  • Wednesday, 1 July, 2009 18:22litdev解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Two projects I played with a while back updated for v0.5 - lots of arrays, events, graphics etc.

    1] Driving game with nice graphics and rubbish gameplay BCK921.



    2] Bouncing balls with collision physics, gravity, attraction etc. PMT149.

     
  • Wednesday, 1 July, 2009 20:18bigdaddyo 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Wow those are great!  Do you lose speed while making turns?  Maybe with just a couple tweaks on the keys it's control will be perfect.  I see your track is a sum of 3 sinusoids, pretty cool.  Maybe if you "spawn" the trees/centerline a little lower on the display and find a better background, and even a distant horizon background that slides a bit left/right with the road, it'll really look cool.

    I like to mess with gravity between lots of masses, your physics program goes way deeper than anything i've done.  It looks like your propagating backward to the point of the collison between objects because of the discrete time steps, then figuring out where things should go, really cool.  I tried to manipulate your initial variables to give the appearance of stars in orbit around each other, but I think the bouncing off the walls makes things difficult for that.  Calculating the system's energy is great, lets you see if simulation errors build up into unstable energy.  Really nice stuff.
  • Wednesday, 1 July, 2009 20:28Vijaye RajiMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Wow, litdev.  That is amazing...

  • Wednesday, 1 July, 2009 20:54litdev解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    The driving was mainly about learning how to use the events to update graphics smoothly - the actual game part could be rewritten to be much better.

    The energy is just kinetic so it changes with gravity, attraction etc.  If you forget collisions, a galaxy type gravity system should be not too hard to write.  I was playing with 3D gravity (QND161), use mouse left to rotate.   I also tried 3D Red/green stereo (QMF510) but not to much effect and other basic 3D stuff (JWV631 , LHJ742).  None of these work that great, but it was fun playing.
  • Wednesday, 1 July, 2009 20:56George BirbilisMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    it would be nice if when authoring a reply like this one could use some tag like download:ID or [download]ID[/download] to mark a download. New users don't know what to do with "QND161" say number

    Microsoft MVP J# 2004-2009, Borland Spirit of Delphi 2001
  • Thursday, 2 July, 2009 5:50Grzegorz TworekMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    2] Bouncing balls with collision physics, gravity, attraction etc. PMT149.

    It's absolutely impressive!
    Only thing I can complain about is detecting collisions of squares. They collides as balls, using radius instead of real square borders. From my own point of view, removing "square" option is good solution.
    Grzesio
  • Thursday, 2 July, 2009 6:35bigdaddyo 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Looking at what he's been able to do implementing physics, I would imagine he could model squares hitting corners & torquing each other around, would look funny.
  • Thursday, 2 July, 2009 18:13Grzegorz TworekMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Not comparable to litdev works but if you like Worm game you can play the simplest one: XKT407
    Have fun! :)


    Grzesio
  • Friday, 3 July, 2009 8:54Ron Hudson 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I have been working on a simple statistics program as a result of an Introduction to Statistics course
    in my BS/IT program.

    It seems that while I uploaded the program the write to file lines have been commented out. These
    write the programs computations to a text file so you can use them to plot your statistics in excel.

    (it also seems that some of the spacing in my program was changed during upload?)

    The program ID is KXV220
    Here is a link: http://smallbasic.com/program/?KXV220
  • Friday, 3 July, 2009 8:58Ron Hudson 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Nice worm game, Grzegorz.
  • Friday, 3 July, 2009 19:42FremyCompany解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Two projects I played with a while back updated for v0.5 - lots of arrays, events, graphics etc.

    1] Driving game with nice graphics and rubbish gameplay BCK921.

    2] Bouncing balls with collision physics, gravity, attraction etc. PMT149.
    Impressive !
    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
  • Saturday, 4 July, 2009 15:31RarelyEvil 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Here's two versions of a cellular automaton I've made: Easy code and Clean code .

    The program uses simple rules to create complex figures. Like this one:



    It takes about five minutes to render these 300 lines. I guess speed is not one of SmallBasic's strengths. :)

    For more info about cellular automata see: http://mathworld.wolfram.com/CellularAutomaton.html
    • 已編輯RarelyEvil Saturday, 4 July, 2009 15:33Links weren't working.
    •  
  • Sunday, 5 July, 2009 18:15Kniggles 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    PGG665 just a sum
  • Sunday, 5 July, 2009 18:28litdev解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    You use For i = 1 To i+1 to do an infinite loop.  This works fine and shows creative thinking, the more usual would be While ("True") .
    To manipulate a single pixel try GraphicsWindow.SetPixel(x,y,GraphicsWindow.GetRandomColor()) , you will find it is faster than drawing an ellipse of size 1, also drawing an ellipse includes the pen coloured border as well the brush coloured interior.
    The sum is bigger - import HWF459.
  • Sunday, 5 July, 2009 22:30Kniggles 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    GraphicsWindow.BackgroundColor = "midnight"
    gw = GraphicsWindow.Width
    gh = GraphicsWindow.Height
    GraphicsWindow.FontSize = 100
    Turtle.Move (100)
    Turtle.Turn (1*1)
    While ("True")
      For i = 1 To 100 ' Do 100 of these for every update of the black text to speed it up
       GraphicsWindow.SetPixel(Math.GetRandomNumber(gw),Math.GetRandomNumber(gh),GraphicsWindow.GetRandomColor())
      EndFor
      GraphicsWindow.BrushColor = "Black"
      GraphicsWindow.DrawBoundText(260,110,gw-20,"TY")
     

    EndWhile
  • Friday, 10 July, 2009 2:12bigdaddyo 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I made a program that randomly shows astronomy pictures of the day from a NASA website.  Import BQJ912

    Enjoy!
  • Friday, 10 July, 2009 23:58kennetho184 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Has anyone thought about writing a program that does something like internet research?
  • Saturday, 11 July, 2009 0:13Ron Hudson 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    what happens when i overflows?


    for i = 0 to 1
        i = 0

        .....

        if iamdone=1 then
           i = 1
        endif
       
        ...

    endfor

    of course you could use a while....

  • Tuesday, 14 July, 2009 18:43Glennium 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Hello,

    I just recently wrote my first program in Small Basic to convert numbers into Roman Numerals. 
    My programming experience is from many years back... Mainframe basic in High School in the 70's, Fortran77 in College, and writing batch files when I worked on a help desk.

    I would like to know how my program could be streamlined.

    The program is located at SFP007

    Thanks ;
    Glenn

  • Tuesday, 14 July, 2009 19:46litdev解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hi, looks pretty efficient to me.  Here's another using text manipulations rather than maths to get the digits and does more manipulation of the characters in the code without GoTo's and uses a smaller database of Roman characters entered in the code - much the same though.  Import VGR369.
  • Tuesday, 14 July, 2009 23:02Glennium 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Thanks litdev,

    The program you showed is more compact, and looks more efficient.

    I wrote my program to make a Roman Digital Clock.

    Here is my Clock RJP086

    Later on I might integrate that other program.


    The next 2 things I want to do for my clock is to get rid of the window border, and to get rid of the button in the Start/Task Bar.

    Any ideas on how to go about this?


    Thanks;
    Glenn
    • 已編輯Glennium Tuesday, 14 July, 2009 23:06
    •  
  • Wednesday, 15 July, 2009 5:18bigdaddyo 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Nice clock Glennium, it's helping me brush up on roman numerals, didn't know what an L (50?) before. 

    How about a binary clock??  That'll drive people nuts.  Or hexadecimal, octal, analog?  A funny clock I've seen is a real analog that spins counterclockwise, to keep you on your toes.

    How about 3 hourglasses pouring sand, one each for hour/minute/second?
  • Thursday, 16 July, 2009 13:52Glennium 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    It's funny that you said you would like to see an analog clock running backwards.
    I met Admiral Grace Hopper back in '82 (when she was still a Captain), and on her
    desk she had a ship's clock that she had rigged to run backwards.  She also invented
    the first compiler, and worked on COBOL.  
    Anyway, here is my "Regular" analog clock TKV488, which all you have to do is change 
    the direction and it will run backwards.

    Here are the hands I used to make it run...

    [img]http://img.smakkie.com/SH.png[/img]
    [img]http://img.smakkie.com/MH.png[/img]
    [img]http://img.smakkie.com/HH.png[/img]


    Glenn
    • 已編輯Glennium Thursday, 16 July, 2009 14:00
    • 已編輯Glennium Thursday, 16 July, 2009 16:05
    • 已編輯Glennium Thursday, 16 July, 2009 16:12
    • 已編輯Glennium Thursday, 16 July, 2009 16:29
    •  
  • Thursday, 16 July, 2009 16:21Grzegorz TworekMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼

    Glennium, maybe it's better to take hands directly from your website?

    Iter = "http://img.smakkie.com"  
    
    DrawTicks()
    SecondHand = Shapes.AddImage(Iter + "/SH.png")
    MinuteHand = Shapes.AddImage(Iter + "/MH.png")
    HourHand = Shapes.AddImage(Iter + "/HH.png")
    
    BTW there is an error in SB if backslash is used in URLs. I report this issue in appropriate thread.
    Grzesio
  • Thursday, 16 July, 2009 16:27Glennium 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    You are correct, I could have done that, but different forums have different styles of trying to insert pictures.
    I just thought it could be easier to cut and paste from here...

    Glenn
  • Thursday, 16 July, 2009 16:31Grzegorz TworekMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Maybe it's good idea? I personally like when code does everything including pictures download :)
    Now people may choose.
    Grzesio
  • Wednesday, 22 July, 2009 4:23iUberGeek 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I made an extremely basic dictionary lookup app (note: this app requires the Speech and Music extension to function properly, downloadable at http://smallbasic.com/smallbasic.com/wiki/speech_music_extension.ashx):
    http://smallbasic.com/program/?LPF760

    UPDATE:

    An updated version of the above program is available at:

    The update contains the def cleaner written by LitDev and a "Please wait..." prompt after the user enters the word to be defined. Thanks, LitDev!
    • 已編輯iUberGeek Thursday, 23 July, 2009 23:15Updated the program
    •  
  • Wednesday, 22 July, 2009 19:08litdev解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Good program,

    It seems that TextWindow.WriteLine(def) is printing some characters that are sounded as beeps.  You can remove these, I think they are unicode 7 and possibly some < 0 or > 255?  Here is a sub to clean the def before writing it.

    Sub clean
      cleandef = ""
      For i = 1 To Text.GetLength(def)
        char = Text.GetSubText(def,i,1)
        code = Text.GetCharacterCode(char)
        If (
    code >= 0 And code <> 7 And code < 256) Then
          cleandef = cleandef+char
        EndIf
      EndFor
      def = cleandef
    EndSub
  • Thursday, 23 July, 2009 23:16iUberGeek 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Thanks, LitDev! See my edited post above...
  • Tuesday, 4 August, 2009 18:18abish 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    I wrote a text program. It writes its own directory so it works with anything. I'll make the directories changeable later on.
    Import JGH297
    Note I'm fairly new to SB. If anyone has any suggestions for improvement I'm happy to recieve.
    • 已編輯abish Tuesday, 4 August, 2009 18:23Too much text
    • 已編輯abish Tuesday, 4 August, 2009 18:26I want to improve
    •  
  • Friday, 21 August, 2009 18:23johnkrog 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    Have created an application for so-called vocabulary test, which also give an example of the usage of external files.
    In the program you can enter pairs of words (e.g. from english to german, you ca also add these lists directly in a text file) and be asked to guess (at least in Norway, children often have to learn vocabulary in a foreign language by learning a set of words).  The program can be extended relatively simply to support any Q&A (e.g. capitals of countries etc.)

    Since it depends on that the vocabulary pairs are in an external file in a particular directory, in is provided as a zip-file at http://www.idi.ntnu.no/~krogstie/smallbasic/vocabulary.zip 

    The program code is also provided below  (made for 0.5 not yet tested for 0.6) (but note you have to create a directory where the vocabulary files should reside, see rootfile)
    'Made for SmallBasic version 0.5, English language version
    
    TextWindow.Title = "Vocabulary test"
    
    
    'Directory where vocabulary files  resides, expected to be on a 'vocabulary'-catalogue 
    'beneath the program
     
    
    rootfile = Program.Directory + "\vocabulary\" 
    
    'get the available files on the directory
    
    provideusername ()
    
    filearray = File.GetFiles(rootfile)
    
    numfiles = Array.GetItemCount(filearray)
    
    
    choosenfile = 0
    
    While choosenfile = 0
      
      choosedictionary()
      
    endwhile
    
    
    'Settings
    
    'illustration from  flickr, NB take time, only relevant if one of the languages is english not checked
    
    picture = "off"
    
    
    'sound-effects
    sounds = "off"
    
    'main loop
    
    While choice <> 9
      
      choice = 0
      mainmenu ()
      
      If choice = 1 then
        clear()
        guess ()
      endif
      
      If choice = 2 then
        clear()
        competition ()
      endif
      
      If choice = 3 then
        
        list()
        
      endif
      
      If choice = 4 then
        add()
      endif
      
      If choice = 5 then
        update()
      endif
      
      If choice = 6 then
        choosedictionary()
      endif 
      
      If choice = 7 then
        newlist()
      endif 
      
      If choice = 8 then
        admin()
      endif 
      
      
    EndWhile
    
    TextWindow.WriteLine ("Goodbye "+username)
    
    Program.Delay(1300)
    
    Program.End()
    
    
    
    'main menu
    
    Sub mainmenu
      
      TextWindow.WriteLine("Press enter")
      Dummy = TextWindow.Read()
      TextWindow.Clear()
      While choice < 1 or choice > 9
        TextWindow.WriteLine ("")
        TextWindow.WriteLine ("Main menu")
        TextWindow.WriteLine ("")
        TextWindow.WriteLine ("1 - Guess one word ("+direction+")")
        TextWindow.WriteLine ("2 - Guess several words ("+direction+")")
        TextWindow.WriteLine ("3 - List words")
        TextWindow.WriteLine ("4 - Enter new vocabulary pair")
        TextWindow.WriteLine ("5 - Update vocabulary pair")
        TextWindow.WriteLine ("6 - Change vocabulary list")
        TextWindow.WriteLine ("7 - Create new vocabulary list")
        TextWindow.WriteLine ("8 - Change settings")    
        TextWindow.WriteLine ("9 - End")
        TextWindow.WriteLine ("")
        TextWindow.Write ("Choose function (1-9): ")
        
        choice = TextWindow.ReadNumber()
        
      EndWhile
      
      
    EndSub
    
    
    
    Sub choosedictionary
      
      
      TextWindow.WriteLine ("")
      TextWindow.WriteLine ("Choose vocabulary list")
      TextWindow.WriteLine ("")
      
      For i = 1 To numfiles
        vocabularyfile = filearray [i]
        lang1= File.ReadLine (vocabularyfile, 1) 
        lang2= File.ReadLine (vocabularyfile, 2) 
        TextWindow.WriteLine (i+" "+lang1+" to "+lang2)
      EndFor
      
      TextWindow.WriteLine ("")
      TextWindow.Write("Make a choice (1-"+numfiles+"): ")
      
      filechoice = TextWindow.ReadNumber()
      
      
      If filechoice = choosenfile then
        TextWindow.WriteLine ("You are already using this list")
      else
        
        If filechoice > 0 and filechoice <= numfiles Then
          choosenfile = filechoice
          
          vocabularyfile = filearray [choosenfile]
          
          readfile()
          
        Else
          TextWindow.WriteLine ("Illegal choice")
          
        EndIf 
      Endif
      
    EndSub
    
    
    Sub readfile
      'read contents from file, first two lines indicate the name of the pair (from to)
      
      
      lang1= File.ReadLine (vocabularyfile, 1) 
      lang2= File.ReadLine (vocabularyfile, 2) 
      
      If lang1 ="English" or lang2 = "English" then
        englishrelevance = "on"
      else
        englishrelevance = "off"
      endif
      
      wordpair="dummy"
      numwords = 1
      
      fromlang = lang1
      tolang = lang2
      
      direction =tolang+" to "+ fromlang
      default = direction
      opposite = fromlang+" to "+ tolang
      'Read data to end of file
      
      
      While wordpair <> ""
        
        
        wordpair = File.ReadLine (vocabularyfile, numwords+2) 
        
        If wordpair <> "" Then
          length = Text.GetLength(wordpair) 
          
          found = 0
          pos = 0
          
          While found = 0 
            pos = pos + 1
            If Text.GetSubText(wordpair,pos,1) = ";" Then
              found = 1
            EndIf
          EndWhile
          
          word1 = Text.GetSubText (wordpair,1,pos-1)
          word2 = Text.GetSubText (wordpair, pos+1, length-pos)
          
          lang1[numwords] = word1
          lang2[numwords] = word2
          
          numwords=numwords+1
          
        EndIf
        
      Endwhile
      
      numwords = numwords-1
      
      
      
    EndSub
    
    
    Sub list
      'add stops for long lists
      
      TextWindow.WriteLine ("")
      TextWindow.WriteLine (" "+fromlang+"           "+tolang)
      TextWindow.WriteLine ("")
      
      For i = 1 To numwords
        
        word1 = lang1[i]
        word2 = lang2[i]
        
        lengde = 15 - Text.GetLength(word1)
        padding = " "
        For j = 1 To lengde
          padding = padding + " "
        endfor
        If i < 10 Then  
          TextWindow.WriteLine (" "+i+ " " + word1+padding+word2)
        else
          TextWindow.WriteLine (i+ " " + word1+padding+word2)
        endif
        
      EndFor 
      TextWindow.WriteLine ("")
      
    EndSub
    
    
    'Guess single word
    
    Sub guess
      
      new = 0
      
      while new = 0
        i = Math.GetRandomNumber(numwords)
        
        if pick[i] = 0 Then
          new  = 1
          pick [i] = 1
        EndIf
        
      EndWhile
      
      word1= lang1[i]
      word2= lang2[i]
      
      If picture = "on" Then
        TextWindow.WriteLine ("Getting illustration from flickr ") 
        If fromlang = "English" then
          pic = Flickr.GetRandomPicture(word1)
        else
          pic = Flickr.GetRandomPicture(word2)
        endif
        
        GraphicsWindow.DrawResizedImage(pic,0,0,640,480)
      EndIf
      
      
      If direction = default then
        fromword = word2
        toword = word1
        tolanghere = fromlang
      Else
        fromword = word1
        toword = word2
        tolanghere = tolang
      endif
      
      TextWindow.Write ("What is '" + fromword + "' in "+ tolanghere + "? ")
      
      guess = TextWindow.Read()
      lowcaseguess= Text.ConvertToLowerCase (guess)
      
      
      If lowcaseguess <> toword then    
        TextWindow.WriteLine ("Wrong, correct answer is " + toword)
        if sounds = "on" then
          Sound.PlayBellRing ()
        endif
        
      Else
        TextWindow.WriteLine ("")
        TextWindow.WriteLine ("Correct ")
        numcorrect = numcorrect + 1
        
        if sounds= "on" then
          Sound.PlayChime ()   
        endif
        
      endif 
      
      TextWindow.WriteLine("") 
      
    EndSub
    
    
    'Competition, one try for each, add high-score list 
    
    Sub competition
      
      numcorrect = 0
      TextWindow.Write ("How many times do you want to guess (1 - "+numwords+")? " )
      times = TextWindow.ReadNumber ()
      If times > numwords then
        times = numwords
        TextWindow.Writeline ("There is only "+ numwords + " words in the current list" )
      endif
      
      If times > 0 then
        For j = 1 To times
          guess ()   
        EndFor
        TextWindow.WriteLine("")
        TextWindow.WriteLine ("You got  "+numcorrect+" of "+times+" correct")
      endif
      
    endsub
    
    
    Sub clear
      
      'clear array to test if the same word is not choosen twice 
      
      For i = 1 to numwords
        pick [i] = 0
      EndFor 
      
    Endsub
    
    'Add new word
    
    
    Sub add
      
      TextWindow.Write ("Enter " + fromlang +" word: ")
      word1 = TextWindow.Read ()
      TextWindow.Write ("Enter matching word in "+ tolang +" ")
      word2 = TextWindow.Read ()
      'check if exist
      wordexist ()
      
      If existing = 0 then
        
        'should also check the second word, in case of homonyms
       
        numwords = numwords + 1
        lowcaseword1 = Text.ConvertToLowerCase (word1)
        lowcaseword2 = Text.ConvertToLowerCase (word2)
        
        lang1[numwords] = lowcaseword1
        lang2[numwords] = lowcaseword2
        
        wordpair = lowcaseword1+";"+lowcaseword2
        File.AppendContents(vocabularyfile,wordpair)
      else
        TextWindow.WriteLine("")
        TextWindow.WriteLine (word1+ " or "+word2+" is already in the list")   
        
      endif
      
    EndSub
    
    
    
    Sub update
      'placeholder to change an entry (e.g. if a mistake has been made)
      
      list ()
      
      TextWindow.Write("Choose the number of the word to change (1-"+numwords+"): ")
      choice = TextWindow.ReadNumber()
      If choice >0 and choice < numwords + 1 then
       
        lang1[choice] = "xxx"
        lang2[choice] = "xxx" 
        TextWindow.Write ("Enter " + fromlang +" word: ")
        word1 = TextWindow.Read ()
        TextWindow.Write ("Enter matching word in "+ tolang +" ")
        word2 = TextWindow.Read ()
        'check if exist
        wordexist ()
      
        If existing = 0 then
       
          lowcaseword1 = Text.ConvertToLowerCase (word1)
          lowcaseword2 = Text.ConvertToLowerCase (word2)
          lang1[choice] = lowcaseword1
          lang2[choice] = lowcaseword2
          wordpair = lowcaseword1+";"+lowcaseword2
          File.WriteLine (vocabularyfile,choice+2,wordpair)
        else
          TextWindow.WriteLine("")
          TextWindow.WriteLine (word1+ " or "+word2+" is already in the list")   
    
        endif
      Else
        TextWindow.WriteLine("Make a choice between (1-"+numwords+")!")
      endif
      
      
    endsub
    
    
    
    Sub newlist
     
      'enter filename
      TextWindow.Write("Enter filename: ")
      newfile = TextWindow.Read()
      'sjekk at filnavn ikke finnes
      
      newpath = rootfile + newfile +".txt"
      found = 0
      For i = 1 to numfiles
        If newpath = filearray[i] Then
          found = 1  
        EndIf
        
      endfor
      
      If found = 1 then
        TextWindow.WriteLine("The file "+newfile+" already exists")
      else
        
        
        TextWindow.Write("Enter the first language: ")
        tempfromlang = TextWindow.Read()
        
        TextWindow.Write("Enter the second language: ")
        temptolang = TextWindow.Read()
        
        If tempfromlang = temptolang then
          TextWindow.WriteLine (tempfromlang+ " should be different than "+ temptolang)
        else
          
          fromlang = tempfromlang
          tolang = temptolang 
          vocabularyfile=newpath
          
          File.WriteLine(vocabularyfile,1,fromlang)
          File.WriteLine(vocabularyfile,2,tolang) 
          
          lang1=fromlang
          lang2=tolang
          
          If fromlang ="English" or tolang = "English" then
            englishrelevance = "on"
          else
            englishrelevance = "off"
          endif
          'enter vocabulary pairs (at least one pair)
          numwords = 0
        
          addpair = 1
          while addpair = 1  
            add()
            TextWindow.Write("Enter 1 to add more vocabulary pairs: ")
            addpair = TextWindow.ReadNumber()
          endwhile
          
          direction = tolang+" to "+ fromlang
          default = direction
          opposite = fromlang+" to "+ tolang
        
          numfiles = numfiles + 1
          filearray[numfiles] = vocabularyfile
          choosenfile = numfiles
        endif
        
      endif
      
    endsub
    
    
    
    Sub wordexist
      
      'check if word already in list
      existing = 0
      counter = 1
      While counter <= numwords and existing = 0
        
        If word1 = lang1[counter] or word2 = lang2[counter] then
          existing = 1
        EndIf
        
        counter = counter + 1   
        
      endwhile
      
      
    endsub
    
    Sub provideusername  
      TextWindow.Write ("Enter your name ")
      username =TextWindow.Read ()
    endsub
    
    Sub admin
      
      ' Make this as a menu
      'Different users
      'sound on and off 
      'High-score (vs each vocabulary file ?)
      
      
      TextWindow.Write ("From " + direction +", do you want to change (Y/N)? ")
      valg = TextWindow.Read ()
      If text.ConvertToUpperCase(valg) = "Y" Then
        if direction = default then
          direction=opposite
        Else
          direction = default
        endif  
      EndIf  
      
      If englishrelevance = "on" then
        
        TextWindow.Write("Flickr-pictures are "+ picture +", change (Y/N)? ")
        
        valg = TextWindow.Read ()
        If text.ConvertToUpperCase(valg) = "Y" Then
          If picture = "off" Then
            picture = "on"
          Else
            picture = "off"
          EndIf
        EndIf 
      EndIf       
    EndSub 
    
     
     
    
     
  • Thursday, 17 September, 2009 13:36Phidisher 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I just started using small basic a couple days ago and I'm really enjoying it.  This code is the beginning of a ship game  - not much is done yet except for the initial setup of the ship for the player.  The speed of the ship is controlled by the wind direction.

    Up arrow: Lift the anchor.
    Left arrow: Turn Port.
    Right Arrow: Turn Starboard.
    Down Arrow: Drop the anchor.

    The program ID is: SGN809
    Download at: http://smallbasic.com/program/?SGN809
  • Thursday, 17 September, 2009 18:58litdev解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Phidisher,

    Really nice code structure and helpful comments - very easy to follow.

    Comments:

    1] Calls to SmallBasic functions can be slow if done often, so limit these calls, especially in loops.  For example in getcommand , you could use key = GraphicsWindow.LastKey , then check the variable key rather than calling GraphicsWindow.LastKey repeatedly.  This is of very little importance here, but good to remember.

    2] Shapes are drawn from the top left corner of the shape.  Often the game coordinates are easiest using the shape centre (e.g. to interact with mouse position or for collision detection), hence we often draw the shape at (x-width/2,y-height/2), where (x,y) is the centre of the shape and width,height are for the shape.  Again of no impact here, but could be useful later.

    3] You could use a Timer event to change the wind direction.

    Nice work, look forward to more of the game.


  • Friday, 18 September, 2009 20:30bigdaddyo 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼

    This could be alot of fun with another player and you have your cannons going!  You might try this code change to make heading not jump sometimes, also I noticed there's no East heading check:

      If(GraphicsWindow.LastKey = "Left") Then
        'heading = math.Abs(Math.Remainder(heading + .9, 360))
        heading = Math.Remainder(heading + .9, 360)
        vhead = heading * -1
        Shapes.Rotate(myship, vhead)
      endif
      
      If(GraphicsWindow.LastKey = "Right") Then
        If heading = 0 Then 
          heading = 360
        EndIf
        heading = Math.Remainder(heading - .9, 360)
        If heading < 0 then
          heading = heading + 360
        EndIf 
        vhead = heading * -1
        Shapes.Rotate(myship, vhead)
      endif
  • Friday, 18 September, 2009 22:59NickMon 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Demo code for times table calculation using two loops:

    http://smallbasic.com/program/?CFV877
  • Tuesday, 13 October, 2009 0:00CiccioIT 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hello everyone!

    This  is my little contribution with an example  (http://smallbasic.com/program/?BPB749) that, i suppose, might be instructive for the implementation of passing parameters, return values from procedures, analysis of recursion, conservation of local variables and a correct use of Stack in an enviroment as Small Basic that behaves a bit like the assembly language.

    The program is fully commented for easy understanding!

    The program implement the recursive function to calculate the factorial and the recursive function of Fibonacci.

    I translated "introducing Small Basic" in Italian. May be useful?

    Thanks to all

  • Tuesday, 13 October, 2009 0:16Vijaye RajiMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    CiccioIT, if you want to publish the Italian version of the "Introducing Small Basic" document, please contact me at: vijayegatmicrosoftdotcom.  I'll hook you up with our Localization expert.

  • Wednesday, 14 October, 2009 21:57CiccioIT 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    The Turtle draws the logarithmic and Archimede's Spiral.
    The drawing is totally customizable.

    Attention! (Bug) Program Listing remove some code line. Use the import command in the Small Basic Enviroment to get the program with code
    NNR245

    http://smallbasic.com/program/?NNR245
  • Wednesday, 21 October, 2009 1:49russjr08 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Well im a beginner so I dont have much. I just started yesterday night. So far I have 
    1.A turtle program that makes three squares- Import # FPJ031
    2.A turtle program that makes a hexagon and also has a repeat function- Import # NFG843
    3.A program that grabs images off of flickr depending on the query you type in the TextWindow- Import # NNL559 (Was gonna make it set as desktop background on request)
    4.A cacluator (Was helped with a youtube tutorial)
    5.A button game (Same as above)

    I know it dosent seem much but for me it makes very good progress for me.
    4 and 5 is not my code so I wont post it in respect of the maker

    2 questions
    1.Is there any good tutorials for SmallBasic I already read the PDF that came with it
    2.Is there a way to visually see the cordinates (X and Y) for GraphicsWindow I am only 13 (Dont think im not good at computers becuase of my age I do a lot of things) So i havent taken a course yet in math to figure that out and it would really help if i didnt have to plugin numbers and take a guess (Maybe a grid would help)
  • Sunday, 1 November, 2009 8:05aadams 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Here's a simple chat/IM client.

    KLG986

    Uses a ColdFusion web application server to process the requests and maintain session data.

    NOTE: You'll have to un-comment the line starting with: "checkDir = File." as it is automatically commented out when publishing
  • Thursday, 5 November, 2009 10:34PinaPete 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    Hi,
    I wrote a small clock program, my first attempt using Small Basic, I've commented the source, hope it's useful to somebody :-)

    P.S. I am pretty sure it could be made smaller, however, that was not my goal, I was just exploring the languadge.

    'Open a graphis Window for the Clock
    GraphicsWindow.Width = 850
    GraphicsWindow.Height = 200
    
    ' Set colors
    ' Background color
    BackColor="Black"
    ' Foreground color (digits & dots)
    ForeColor="White"
    
    'Set initial color
    GraphicsWindow.BackgroundColor = BackColor
    GraphicsWindow.BrushColor = ForeColor
    
    ' Variables used
    ' Seconds (latest / Last used)
    sec = 8
    oldsec = -1
    ' Minutes (latest / Last used)
    min = 8
    oldmin = 0
    
    ' Hours (latest / Last used)
    hrs = 8
    oldhrs = 0
    
    ' Start loop
    While sec < 60
      
      'Get current time (Sec, Min, and hrs)
      sec = Clock.Second
      min = Clock.Minute
      hrs = Clock.Hour
      
      ' if the clock has changed since the last loop (takes less than 1 second per loop) 
      if oldsec<>sec Then
        
        ' Update flashing dots
        dodots()  
      
        ' redraw the Seconds
        comp = sec
        breakdown()
        offset = 750
        num = units
        draw_segs()
        offset = 600
        num = tens
        draw_segs()
      
        If min<>oldmin then ' Check if the Minutes have changed, redraw if yes.
          comp = min
          breakdown()
          offset = 450
          num = units
          draw_segs()
          offset = 300
          num = tens
          draw_segs()
        EndIf
    
        If hrs<>oldhrs then ' Check if the Hours have changed, redraw if yes.
          comp = hrs
          breakdown()
          offset = 150
          num = units
          draw_segs()
          offset = 0
          num = tens
          draw_segs()
        EndIf
    
        'Save current time information for next pass
        oldsec = sec
        oldhrs = hrs
        oldmin = min
      EndIf
    ' end of loop, start again  
    EndWhile
    
    Sub dodots
      
      'If even seconds: Dot is ON, if Odd seconds: Dot is OFF (Change color)
      If sec/2 = Math.Ceiling(sec/2) then 
        GraphicsWindow.BrushColor = ForeColor
      Else 
        GraphicsWindow.BrushColor = BackColor
      endIf
        
      ' Draw dots (two triangles)
      ' Right Bottom
      GraphicsWindow.FillTriangle (570,140,580,140,575,135)
      GraphicsWindow.FillTriangle (570,140,580,140,575,145)
    
      ' Right Top
      GraphicsWindow.FillTriangle (570,50,580,50,575,45)
      GraphicsWindow.FillTriangle (570,50,580,50,575,55)
    
      'Left Bottom
      GraphicsWindow.FillTriangle (270,140,280,140,275,135)
      GraphicsWindow.FillTriangle (270,140,280,140,275,145)
    
      ' Left Top
      GraphicsWindow.FillTriangle (270,50,280,50,275,45)
      GraphicsWindow.FillTriangle (270,50,280,50,275,55)
    endsub
    
    
    sub breakdown
      ' take a number "00" to "59" and turn it into Tens and Units
      ' Much easier with 'Int' function
      ' tens = int (comp/10)
      'units = comp - tens
      ' Oh well.....
      If comp < 10 Then
        tens = 0
        units = comp
      ElseIf comp <20 then
        tens = 1
        units = comp - 10
      ElseIf comp <30 then
        tens = 2
        units = comp - 20
      ElseIf comp <40 then
        tens = 3
        units = comp - 30
      ElseIf comp <50 then
        tens = 4
        units = comp - 40
      ElseIf comp <60 then
        tens = 5
        units = comp - 50
        EndIf
    endsub    
    
    
    Sub draw_segs 
      ' Decide what number to draw 0 .. 9
      ' Select case would have been nice I guess
      If num=1 then 
        draw_1()
      elseIf num=2 then 
        draw_2()
      elseIf num=3 then 
        draw_3()
      elseIf num=4 then 
        draw_4()
      elseif num=5 then 
        draw_5()
      elseif num=6 then 
        draw_6()
      elseif num=7 then 
        draw_7()
      elseif num=8 then 
        draw_8()
      elseif num=9 then 
        draw_9()
      elseIf num=0 then 
        draw_0()
      EndIf
    endsub    
    sub draw_0 ' Draw a number 0
      GraphicsWindow.BrushColor = ForeColor
      Horiz_top()
      Vert_TL()
      Vert_TR()
      Vert_BL()
      Vert_BR()
      Horiz_bot()
      GraphicsWindow.BrushColor = BackColor
      Horiz_mid()
    endsub
    
    sub draw_1 ' Draw a number 1
      GraphicsWindow.BrushColor = ForeColor
      Vert_TR()
      Vert_BR()  
      GraphicsWindow.BrushColor = BackColor
      Horiz_top()
      Vert_TL()
      Horiz_mid()
      Vert_BL()
      Horiz_bot()
    endsub
    
    sub draw_2 ' Draw a number 2
      GraphicsWindow.BrushColor = ForeColor
      
      Horiz_top()
      Vert_TR()
      Horiz_mid()
      Vert_BL()
      Horiz_bot()
      GraphicsWindow.BrushColor = BackColor
      Vert_TL()
      Vert_BR()
    endsub
    
    sub draw_3 ' Draw a number 3
      GraphicsWindow.BrushColor = ForeColor
      Horiz_top()
      Vert_TR()
      Horiz_mid()
      Vert_BR()
      Horiz_bot()
      GraphicsWindow.BrushColor = BackColor
      Vert_TL()
      Vert_BL()
    endsub
    
    sub draw_4 ' Draw a number 4
      GraphicsWindow.BrushColor = ForeColor
      Vert_TL()
      Vert_TR()
      Horiz_mid()
      Vert_BR()
      GraphicsWindow.BrushColor = BackColor
      Horiz_top()
      Vert_BL()
      Horiz_bot()
    endsub
    
    sub draw_5 ' Draw a number 5
      GraphicsWindow.BrushColor = ForeColor
      Horiz_top()
      Vert_TL()
      Horiz_mid()
      Vert_BR()
      Horiz_bot()
      GraphicsWindow.BrushColor = BackColor
      Vert_TR()
      Vert_BL()
    endsub
    
    sub draw_6 ' Draw a number 6
      GraphicsWindow.BrushColor = ForeColor
      Horiz_top()
      Vert_TL()
      Horiz_mid()
      Vert_BL()
      Vert_BR()
      Horiz_bot()
      GraphicsWindow.BrushColor = BackColor
      Vert_TR()
    endsub
    sub draw_7 ' Draw a number 7
      GraphicsWindow.BrushColor = ForeColor
      Horiz_top()
      Vert_TR()
      Vert_BR()
      GraphicsWindow.BrushColor = BackColor
      Vert_TL()
      Horiz_mid()
      Vert_BL()
      Horiz_bot()
    endsub
    
    sub draw_8 ' Draw a number 8
      GraphicsWindow.BrushColor = ForeColor
      Horiz_top()
      Vert_TL()
      Vert_TR()
      Horiz_mid()
      Vert_BL()
      Vert_BR()
      Horiz_bot()
    endsub
    
    sub draw_9 ' Draw a number 9
      GraphicsWindow.BrushColor = ForeColor
      Horiz_top()
      Vert_TL()
      Vert_TR()
      Horiz_mid()
      Vert_BR()
      Horiz_bot()
      GraphicsWindow.BrushColor = BackColor
      Vert_BL()
    endsub
    
    sub Horiz_top 'Select offset for horizontal segment, TOP
      X=10
      y=10
      Horiz_Seg()
    endsub  
    
    sub Horiz_mid 'Select offset for horizontal segment, MIDDLE
      X=10
      y=94
      Horiz_Seg()
    endsub
    
    sub Horiz_bot 'Select offset for horizontal segment, BOTTOM
      X=10
      y=178
      Horiz_Seg()
    endsub
    
    Sub Vert_TL 'Select offset for Vertical segment, TOP LEFT
      X=8
      y=12
      Vert_Seg()
    endsub
    
    Sub Vert_TR 'Select offset for Vertical segment, TOP RIGHT
      X=92
      y=12
      Vert_Seg()
    endsub
    
    Sub Vert_BL 'Select offset for Vertical segment, BOTTOM LEFT
      X=8
      y=96
      Vert_Seg()
    endsub
    
    Sub Vert_BR 'Select offset for Vertical segment, BOTTOM RIGHT
      X=92
      y=96
      Vert_Seg()
    endsub
    
    
    Sub Horiz_Seg ' Draw the Horizontal Segment
      ' Offset gives the location; i.e. "Hours, Minutes, or Seconds" and then "Tens or Units"
      ' x is the position "Top, Middle, or Bottom"
      x=x+offset
      'draw two triangles (Top and Bottom)  
      GraphicsWindow.FillTriangle (X+0,Y+0,X+10,Y+10,X+10,Y-10)
      GraphicsWindow.FillTriangle (X+80,Y+0,X+70,Y+10,X+70,Y-10)
      'draw one rectangle (middle portion)
      GraphicsWindow.FillRectangle (x+10,y-10,60,20)
    EndSub
    
    Sub Vert_Seg ' Draw the Horizontal Segment
      ' Offset gives the location; i.e. "Hours, Minutes, or Seconds" and then "Tens or Units"
      ' x is the position "Top Left, Top Right, Bottom Left, or Bottom Right"
      x=x+offset
      'draw two triangles (each end)  
      GraphicsWindow.FillTriangle (X+0,Y+0,X+10,Y+10,X-10,Y+10)
      GraphicsWindow.FillTriangle (X+0,Y+80,X+10,Y+70,X-10,Y+70)
      'draw one rectangle (middle portion)
      GraphicsWindow.FillRectangle (x-10,y+10,20,60)
    EndSub  
  • Thursday, 5 November, 2009 12:24Grzegorz TworekMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    PinaPete: Really nice piece of app! Especially if you are beginner.
    Remember you can export your source using toolbar button in SB and give us only the code. It may be useful when posting large amount of lines.
    Grzesio
  • Thursday, 5 November, 2009 14:29PinaPete 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Not an absolute beginner, I have dabled with various basic variations, I must say I like this one it makes you think a little about what you are doing.

    And yes I did try the "Publish" button but it did not function, maybe it's the companies firewall (not that I would do anything like this during working hours). 
  • Friday, 6 November, 2009 10:46PinaPete 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    I had a moment of thought, rare but does happen, the code below replaces the "Breakdown" sub routine, it's not a pretty solution but cuts down the process some what, I love short solutions:
    sub breakdown
      ' Take the value as a two letter word then use
      ' GetSubText to get the 1st and second characters
    If Text.GetLength(comp) = 1 then tens = "0" units = Text.GetSubText(comp,1,1) else tens = Text.GetSubText(comp,1,1) units = Text.GetSubText(comp,2,1) endif endsub
  • Friday, 6 November, 2009 13:45Jason Jacques 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    This is probably a little closer to the code you initially had in mind:

    Sub breakdown
      ' Calculate tens and units for comp
      tens  = Math.Floor(comp/10)
      units = Math.Remainder(comp, 10)
    EndSub

    Integer devision in other languages is synonymous with the result from Math.Floor() in Small Basic.

    Rather than calculating the units = comp - (tens * 10) you can Math.Remainder() which allows you to calculate the remainder of a division.

    Hope this helps,

    Jason.
  • Saturday, 7 November, 2009 15:07Dudeson 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Here's my Example Project Compilation!

    SSG215

    have fun!
    Live for nothing, OR CODE FOR SOMETHING!
  • Sunday, 8 November, 2009 18:22Davey-Wavey 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    Finding problems running old example code in v.0.7 I decided to write a debugger to see what was going on.  Might be useful to others...

    The Import code is: KGH734

    Just paste this entire code into the end of your own program and use it as necessary.

    ' ===============================================================
    ' ====                                                       DEBUGGER v1                                                       =======
    ' ===============================================================
    '                                                       (c) davey-wavey 2009
    '
    ' To 'watch' a variable, use:               dbug["description"]=variable
    '
    '       where 'description' is a text string - usually just the name of the variable again
    '       and 'variable' is the variable value to show
    '       e.g. dbug["score"]=score
    '
    ' To show the debug textWindow, put this at the end of your main loop:    debug()
    '
    ' NOTE: This will only really work with graphics programs as it will wipe out textWindow ones!
    '
    Sub Debug
      nl=Text.GetCharacter(10)  ' define the newline character
      
      tmpdbug=dbug              ' get copy of dbug values
      
      ' convert all semicolon separators to newlines
      While (Text.GetIndexOf(tmpdbug,";") > 0)
        tmpdbug = Text.GetSubText(tmpdbug,1,text.GetIndexOf(tmpdbug,";")-1) + nl + Text.GetSubTextToEnd(tmpdbug,text.GetIndexOf(tmpdbug,";")+1)
      EndWhile
      
      ' clear textwindow and output debug text
      TextWindow.Clear()
      TextWindow.WriteLine ("==== DEBUG START ====" + nl)
      TextWindow.WriteLine (tmpdbug)
      TextWindow.WriteLine ("==== DEBUG END ====" +nl)
    EndSub

  • Wednesday, 11 November, 2009 16:01Davey-Wavey 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Small Basic Windows (sbWin) - import code: SKD503

    I've been playing with creating a mini windows environment within SB. I've given up on it now as SB is too basic to handle the graphics, and you can only write text to the background, not onto shapes.

    Anyway, I'm posting it here in case any of it is useful as an example to someone.
  • Wednesday, 18 November, 2009 4:29Kniggles 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    KWD243 its a picture bridge  building mind game i think.
    have fun
    Me heads a shed and me lifes a dream, Its all for fun and mostley free.
  • Wednesday, 18 November, 2009 4:46Kniggles 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Here's my Example Project Compilation!

    SSG215

    have fun!
    Live for nothing, OR CODE FOR SOMETHING!
    kewl, thanks, had to take 2 lines out though :)>

    Me heads a shed and me lifes a dream, Its all for fun and mostley free.
  • Thursday, 26 November, 2009 21:18Davey-Wavey 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    It's taken me 10 years, but I've finally done it!

    SNAKEBITE - SB



    The full program excluding images/sound: KTN094

    You can download the full game here: snakeBite.zip

    An early concept version with vector graphics: VHG623