none
creating records in sb RRS feed

  • Question

  • back in the day, i used to program in basic , then unix, dbase and foxpro. it's been a long time and i've forgotten much of the code and syntax but i thoght i would play around with sb and create programs for myself. in dbase, i remember i could create records and fill each record with data, for example, first and last name, date, address, city town,etc., using a set number of variables a(1), a(2). Once input, I could create record 1,2,3,4, etc., each using the a(1), a(2)... In this way there were hundreds of records that were created, each with unique data but using the same variables. In this way, I could compare the data in each record, for example, how many people had the same last name, or name the city and how many times it appeared in the database.  I see that sb uses arrays to accomplish this data storing, to an extent, but it appears that if one had a lot of data to store the array size and number of variables could be prohibitive. My question is, is there a 'record' and 'val' command that creates seperate files or records so that hundreds of variables don't have to be used?  thanks i advance.
    Saturday, February 11, 2012 7:30 PM

Answers

  • Large arrays with greater than 200 - 500 elements will start to slow SmallBasic noticably. 

    SmallBasic has arrays with a name and index (perhaps what you call a record) and a value.

    name[index] = value
    newvalue = name[index]

    We can loop through these:

    For i = 1 To 100
     data[i] = i*i
    EndFor

    The index or the value can be numbers or a string and they can be multi-dimensional.

    data["Fred"]["Age"] = 35
    data["Fred"]["Sex"] = "Male"

    Arrays can also hold objects as values like sprites in a game.

    For i = 1 To 50
      sprite[i] = Shapes.AddEllipse(20,20)
    EndFor
    
    While ("True")
      For i = 1 To 50
        Shapes.Animate(sprite[i],Math.GetRandomNumber(500)-10,Math.GetRandomNumber(500)-10,1000)
      EndFor
      Program.Delay(1000)
    EndWhile

    We can also do other stuff with the arrays using the Array. methods.

    However, the internal implementation of this is great for simple programming, but will suffer performance at larger array sizes, mainly because it can be indexed by numbers or strings.

    There are extensions that can handle fast array manipulation, but to be frank, if this is your main objective I would switch to VisualBasic, especially if you already have some programming behind you.  VB Express 2010 is free and can be found here, and has loads of SQL and database support as well as things like list objects that are both efficient and can sort, insert etc and output to window forms.

    Saturday, February 11, 2012 8:11 PM
    Moderator

All replies

  • Large arrays with greater than 200 - 500 elements will start to slow SmallBasic noticably. 

    SmallBasic has arrays with a name and index (perhaps what you call a record) and a value.

    name[index] = value
    newvalue = name[index]

    We can loop through these:

    For i = 1 To 100
     data[i] = i*i
    EndFor

    The index or the value can be numbers or a string and they can be multi-dimensional.

    data["Fred"]["Age"] = 35
    data["Fred"]["Sex"] = "Male"

    Arrays can also hold objects as values like sprites in a game.

    For i = 1 To 50
      sprite[i] = Shapes.AddEllipse(20,20)
    EndFor
    
    While ("True")
      For i = 1 To 50
        Shapes.Animate(sprite[i],Math.GetRandomNumber(500)-10,Math.GetRandomNumber(500)-10,1000)
      EndFor
      Program.Delay(1000)
    EndWhile

    We can also do other stuff with the arrays using the Array. methods.

    However, the internal implementation of this is great for simple programming, but will suffer performance at larger array sizes, mainly because it can be indexed by numbers or strings.

    There are extensions that can handle fast array manipulation, but to be frank, if this is your main objective I would switch to VisualBasic, especially if you already have some programming behind you.  VB Express 2010 is free and can be found here, and has loads of SQL and database support as well as things like list objects that are both efficient and can sort, insert etc and output to window forms.

    Saturday, February 11, 2012 8:11 PM
    Moderator
  • Thank you for that info...it has certainly helped. What I'm seeing is that sb uses arrays, like basic did and it takes too many variables and too much time to sort through data.  I was looking for a programming language that I could play around with, as I mentioned before, and create programs for my computer and specialized needs, like keeping track of what I plant in my garden from season to season, the results and problems, and similar type of informational programs that I can manipulate the data in and change the programming as I see fit. Dbase was powerful in that way since I could open a file, point to a record and insert data using variables like a1='f.name',a2=l.name,a3='date',etc., I could than close the record, goto eof and create a menu to sort through the data as I saw fit tp program. then it was easy to open the file again, point to the next record and using the same a1,a2,a3 variables insert new data into the new 'record'.  I will look at VB express and see what it offers. Sorry for reiterating my thoghts again about the programming.   Thanks again.
    Sunday, February 12, 2012 2:25 PM