PowerBasic question: SORT - Programmers Heaven

#### Howdy, Stranger!

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

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# PowerBasic question: SORT

Posts: 5Member
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

• Posts: 354Member
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
:
: