* *

Coding

User

Welcome, Guest. Please login or register.
May 24, 2013, 12:13:00 PM

Login with username, password and session length

Menu

Stats

Members
  • Total Members: 491
  • Latest: TOPMO3
Stats
  • Total Posts: 12061
  • Total Topics: 1688
  • Online Today: 94
  • Online Ever: 150
  • (September 26, 2012, 02:29:19 PM)
Users Online
Users: 2
Guests: 42
Spiders: 3
Total: 47
zappa52
Larry McCaughn
Google
Baidu (2)

Recent Topics

Author Topic: Using text arrays  (Read 964 times)

0 Members and 1 Guest are viewing this topic.

Offline rosslcs

  • Newbie
  • *
  • Posts: 30
  • Bananas: 0
Using text arrays
« on: June 21, 2012, 06:46:25 AM »
I an trying to print text from an array with the use of the following code...

OPENCONSOLE
DEF name$[30]:ISTRING

name$[1] = "John"
name$[2] = "Mark"

PRINT name$ (1)

PRINT "Press any key to close"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END

However I am getting an error with the PRINT name$ (1)
section of the program.

If there a correct way to use the PRINT name$ (1) array?


Online Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 192
  • Bananas: 4
  • Gender: Male
Re: Using text arrays
« Reply #1 on: June 21, 2012, 07:51:10 AM »
Your code appears to be trying to print the single name stored in element #1
The error is you are using (1) instead of [1].

The following code contains a loop to print the contents of all the elements of the array.
Hope this helps.
Code: [Select]

OPENCONSOLE
DEF name$[30]:ISTRING
DEF x:INT
name$[0] = "Sally"
name$[1] = "John"
name$[2] = "Mark"
name$[29] = "Me"
 
FOR x = 0 TO 29
  IF  name$ (x)  = ""
     PRINT "..."
  ELSE   
     PRINT name$ [x]
  ENDIF
PRINT "Press any key to close"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END
« Last Edit: June 21, 2012, 07:52:54 AM by Larry McCaughn »
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline rosslcs

  • Newbie
  • *
  • Posts: 30
  • Bananas: 0
Re: Using text arrays
« Reply #2 on: June 21, 2012, 09:29:20 AM »
Thanks for the code example. The array works fine using []
but the example only shows "SJM" instead of "Sally John Mark" when run.

Online Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 192
  • Bananas: 4
  • Gender: Male
Re: Using text arrays
« Reply #3 on: June 21, 2012, 11:28:46 AM »
My bad.
DEF name$[30]:ISTRING doesn't define an array of strings.
It defines a single string of 30 characters.
change that definition to
DEF name$[30]:STRING
 
and it should work correctly.
 
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline GWS

  • Moderator
  • Sr. Member
  • *****
  • Posts: 316
  • Bananas: 14
Re: Using text arrays
« Reply #4 on: June 27, 2012, 09:49:41 AM »
Hi,

Istrings are weird .. being arrays themselves.

So using an array of them is a bit strange.

Here's an example ..

Code: [Select]
OPENCONSOLE

' define an array of 10 Istrings of 20 chars each   
' defined as names[ number_of_strings, chars_per_string ]

def names[10,20]:ISTRING   
 
' assigned as names[ first_char, index_of_strings ]
 
names[0,0] = "John Smith"   
names[0,1] = "Sam Stone"

' calling ...
c$ = names[0,0]
d$ = names[0,1]
print c$
print d$   

print:print "Press Any Key"
DO:UNTIL INKEY$ <> ""

CLOSECONSOLE
END

Don't forget that arrays are zero based.

best wishes, :)

Graham
Tomorrow may be too late ...

Offline rosslcs

  • Newbie
  • *
  • Posts: 30
  • Bananas: 0
Re: Using text arrays
« Reply #5 on: June 29, 2012, 04:42:02 AM »
Thanks for your advice on using Istrings array.

 

To link to us use this code/button on your site

http://www.codingmonkeys.com/images/cm_link.gif