PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: arrays, list in freebasic  (Read 1066 times)

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 193
arrays, list in freebasic
« on: January 07, 2018, 06:16:46 PM »

Having just come back to freebasic, and firefly, and being a bit confused.
At the moment I'm stuck on setting values into an array. I've a list of two columns of numbers (100 in total), and hoped I could wrap something like
Code: [Select]
  Dim Shared  xy(103) as Double  ={ 11.1820, 99.3837 ,
 -1.3761, 100.0000, 
 -13.9125, 99.0392,
lots more numbers...
23.5638, 97.2002,
 11.1820, 99.3837  }

The values were derived from elsewhere, and formatted into this list. I think the fb array wants all the numbers on the same line, which is going to be more tricky to recognize errors in them, during the 'honing/development process. Anyone any ideas on how to create this array, without too much hassle.
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8559
  • Windows 10
    • PlanetSquires Software
Re: arrays, list in freebasic
« Reply #1 on: January 07, 2018, 06:39:16 PM »

I believe you just need to end each line with the "line continuation" character which is an underscore.
Code: [Select]
Dim Shared  xy(103) as Double  ={ 11.1820, 99.3837 , _
 -1.3761, 100.0000, _
 -13.9125, 99.0392, _
lots more numbers...
23.5638, 97.2002, _
 11.1820, 99.3837  }
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 193
Re: arrays, list in freebasic
« Reply #2 on: January 07, 2018, 08:41:48 PM »

Thanks, Paul. That did the trick. Any idea how i can purge my single brain cell of javscript, C#, Python, and all the other rubbish I have in there?
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8559
  • Windows 10
    • PlanetSquires Software
Re: arrays, list in freebasic
« Reply #3 on: January 07, 2018, 08:46:22 PM »

coffee. lots of coffee.  :)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 193
Re: arrays, list in freebasic
« Reply #4 on: January 13, 2018, 01:17:41 PM »

right, having completed my latest FF/FB programming exercise, is there an easy way, a parser/whatever, that will format the resulting code into something pretty, e.g. consistent line indents for blocks of code, and so forth?
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8559
  • Windows 10
    • PlanetSquires Software
Re: arrays, list in freebasic
« Reply #5 on: January 13, 2018, 01:54:06 PM »

There is nothing inside of FireFly itself that does automatic code formatting. It is not something that I have devoted any energy to in the past.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 193
Re: arrays, list in freebasic
« Reply #6 on: January 30, 2018, 01:12:41 PM »

another array problem that I have, this time in freebasic. How do I define an array of strings? I don't know the length of each string, nor the number of said strings. So far, the program compiles, then fails with an unknown error. I've attached a sub set of the code to demonstrate the problem.
Code: [Select]
dim shared x1 as double,y1 as double
dim shared op() as string      'list of g code statements
dim shared p as integer        'counter for op
       
  '------------------------------
 sub ad(opline as string)    'adds line of g code to op
  op(p)=opline
    p=p+1
 end sub
 '-----------------------
 sub getvalues()
      input "input x1 ",x1
      input "input y1 ",y1
 end sub
 '-----------------------
 sub writecomments()
       ad( "(rectangle x1 = "+str(x1)+")")
      ad( "(rectangle y1 = "+str(y1)+")")
 END sub
'-------------
 sub showcode()
   dim k as Integer
   k=0
 while   k<p
    print op(k)
    k= k+1
 WEND
 END sub
'---------------------------

 '--------------------------
 'main loop
 p=0
 getvalues()
 writecomments()
 showcode()
 
      print "done"
sleep

from what I've read in the fb help  my op() should give a variable length array - but as mentioned, it crashes when running. For the small example I've shown op(1) will work, but that is only an array of two small strings, so should I set the size to be larger than I might ever need, say op(100000)?
Logged

Johan Klassen

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 70
  • FF3 User
Re: arrays, list in freebasic
« Reply #7 on: January 30, 2018, 02:59:23 PM »

use redim to create variable length array, here's a very simple example
Code: [Select]
redim shared as string s(0 to 2)
s(0)="0"
s(1)="11"
s(2)="222"

for i as long=0 to 2
print s(i)
next

?"======================"

redim preserve s(0 to 4)

s(3)="3333"
s(4)="44444"

for i as long=0 to 4 'or for i as long=lbound(s) to ubound(s)
print s(i)
next
Logged

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 193
Re: arrays, list in freebasic
« Reply #8 on: January 30, 2018, 05:39:21 PM »

Thanks Johan, that seems to do it. A bit ugly as each time I added a string I redimed the array by +1, but works ok, so far.
Logged