# PowerBasic question: SORT

Hello,

How I can sort a string in alphabeticaly order? I am using this type of string:

Field\$(1) = "Anthony"
Field\$(2) = "Carol"
Field\$(3) = "Arnold"
Field\$(4) = "Dude"
...
Field\$(n) = "..."

I don't wanna use other string, I just wanna to "swap" the Fields in alphabeticaly order without using arrays. If someone understood what I mean and wanna help me, I'll be glad.

Regards,
Donehand

## Comments

• Hello,
Why hasn't anyone else helped you? This is simple.

I'm not sure, but I think you compare strings the same way in PowerBasic as QBasic. This works in QB anyways.
[code]
ARRAYSIZE% = 4
DIM Field\$(1 TO ARRAYSIZE%)
Field\$(1) = "Anthony"
Field\$(2) = "Carol"
Field\$(3) = "Arnold"
Field\$(4) = "Dude"
'BUBBLE SORT
FOR i% = 1 TO ARRAYSIZE%
FOR j% = 2 TO ARRAYSIZE%
IF Field\$(j%) < Field\$(j%-1) THEN
SWAP Field\$(j%), Field\$(j%-1)
END IF
NEXT j%
NEXT i%
'END OF BUBBLE SORT
FOR i% = 1 TO ARRAYSIZE%
PRINT "Field\$("; i%;") = "; Field\$(i%)
NEXT i%
END
[/code]
It ran fine with QB. You may need to change some things for PB.
If PB doesnt have a SWAP function, you may need to write one. That's not hard.
[code]
'SWAP
temp\$ = Field\$(j%)
Field\$(j%) = Field\$(j%-1)
Field\$(j%-1) = temp\$
'END OF SWAP
[/code]
Put that code in place of the SWAP line.

Sorry it took so long to get help on this.

:
: How I can sort a string in alphabeticaly order? I am using this type of string:
:
: Field\$(1) = "Anthony"
: Field\$(2) = "Carol"
: Field\$(3) = "Arnold"
: Field\$(4) = "Dude"
: ...
: Field\$(n) = "..."
:
: I don't wanna use other string, I just wanna to "swap" the Fields in alphabeticaly order without using arrays. If someone understood what I mean and wanna help me, I'll be glad.
:
: Regards,
: Donehand
:
:

Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!