Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Has anyone seen a string variable like this: $(0), zero

Status
Not open for further replies.

beetlebailey

Programmer
Jan 4, 2005
51
US
I am using an Allen/Bradley 1746-BAS basic module. Within it's basic code is a variable in which I want to manipulate. The data is stored in string variable $(0) is 987723605XXXA9347286. Any ideas on how to access this string variable so I can chop it up into 3 pieces. The formula provided by johnwm works great like this:
10 A$ = "987723605XXXA9347286"
20 B$ = LEFT$(A$,4)
30 C$ = MID$(A$,5,8)
40 D$ = RIGHT$(A$,8)
which breaks up the string nicely into 3 pieces. But I cannot seem to get $(0) set to A$ or A$ to equal $(0).
Any ideas on what is going on here ?

Thanks
 
Can you check carefully on your variable name? Most Basics need variable names to start with a letter, and generally the bracketed figure refers to an element of an array. The $ (normally only at the end of the variable name, but before the array index) signifies that it is a string variable.

Looks to me as if your variable is an array element which may be called X$(0) (where X is some string starting with a letter), and somehow you've mislaid the X.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
What johnwm said is true. The $(0) is made for an array:

Code:
DIM SomeVariable$(2)

SomeVariable$(0) = "1234567890"
SomeVariable$(1) = LEFT$(SomeVariable$(0), 5)
SomeVariable$(2) = RIGHT$(SomeVariable$(0), 5)

CLS
PRINT "data before cut: "; SomeVariable$(0)
PRINT "data after  cut: "; SomeVariable$(1), SomeVariable$(2)

This idea is akin to spreadsheets (like Excel or Lotus)

If I understand you right, you simply want to clear the string in A$ in your code. If so, then just do it.

Code:
CLS

A$ = "Filled"
PRINT "data in A$ variable before: "; A$

A$ = "" 'SEE the quotes with nothing inside?
        '   this is called an 'empty string'
PRINT "data in A$ variable AFTER: "; A$

HTH
--MiggyD

--> It's a bird! It's a plane! No, it's an OS update patch! Ahh!! <--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top