Liberty BASIC Community Forum
« What'S wrong »

Welcome Guest. Please Login or Register.
May 28th, 2017, 10:53pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: What'S wrong  (Read 281 times)
ombre
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 18
xx What'S wrong
« Thread started on: Aug 24th, 2016, 09:27am »

Code:
nom$="aa":prenom$="a":nomF$="aaF":nais$="1944":ad1$="ada":ad1Tel$="ta"
 liste$(1)= nom$+","+prenom$+","+nomF$+","+nais$+","+ad1$+","+ad1Tel$
'sort liste$(),1,1
print liste$(1)
print
    nom$=upto$(liste$(1),",")
    liste$(1)= replstr$(liste$(1),nom$+",","")
    prenom$= upto$(liste$(1),",")
    liste$(1)= replstr$(liste$(1),prenom$+",","")
    nomF$= upto$(liste$(1),",")
    liste$(1)= replstr$(liste$(1),nomF$+",","")
    nais$= upto$(liste$(1),",")
    liste$(1)= replstr$(liste$(1),nais$+",","")
    ad1$= upto$(liste$(1),",")
    liste$(1)= replstr$(liste$(1),ad1$+",","")
    ad1Tel$=liste$(1)
print nom$
print prenom$
print nomF$
print nais$
print ad1$
print ad1Tel$ 


Why has ad1$ the same value as ad1Tel$
« Last Edit: Aug 24th, 2016, 12:14pm by Brandon Parker » User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1643
xx Re: What'S wrong
« Reply #1 on: Aug 24th, 2016, 09:40am »

First, please use button with # to put code tags around your code
Without it, first line is unreadable
Quote:
nom$="aa"renom$="a":nomF$="aaF":nais$="1944":ad1$="ada":ad1Tel$="ta"


Second, what this code supposed to do?
User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
ombre
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 18
xx Re: What'S wrong
« Reply #2 on: Aug 24th, 2016, 09:50am »

To sort records with many fields saved in Direct access, I have to copy the fields in an array separated by ",". Once the array is sorted, I have to write it back as a record, and to do this, I have to separate the array using «upto$» and «replstr$» but it doesn't work.
User IP Logged

Brandon Parker
Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1079
xx Re: What'S wrong
« Reply #3 on: Aug 24th, 2016, 12:13pm »

Were you attempting to do something like this?

This is just one way of doing what I believe you are after. There are more ways to accomplish the same task, but this one is pretty simple and straight forward. It does require that the string be in the specific format that was in your original post.

Code:
'Set how many variables will be added for sorting
Dim liste$(5)

'Get your variables however do wish and assign them
nom$="aa"
prenom$="a"
nomF$="aaF"
nais$="1944"
ad1$="ada"
ad1Tel$="ta"

'Use a combined string for easy manipulation with an array
myCombinedStrings$= nom$+","+prenom$+","+nomF$+","+nais$+","+ad1$+","+ad1Tel$

'Go through the string parsing out each variable and assign it to an element of the arry
While (myCombinedStrings$ <> "")
    If Instr(myCombinedStrings$, ",") > 0 Then
        liste$(i) = Left$(myCombinedStrings$, (Instr(myCombinedStrings$, ",") - 1))
    Else
        liste$(i) = myCombinedStrings$
        myCombinedStrings$ = ""
        Exit While
    End If
    myCombinedStrings$ = Mid$(myCombinedStrings$, (Instr(myCombinedStrings$, ",") + 1))
    i = (i + 1)
Wend

'Print out the array
For i = 0 To 5
    Print liste$(i)
Next i

Print

'Sort the array
Sort liste$(), 0, 5

'Print out the array again to show differences after sorting
For i = 0 To 5
    Print liste$(i)
Next i

Print

'Assign the elements of the array back the the combined string or your individual variable as you wish
For i = 0 To 5
    If (i > 0) Then myCombinedStrings$ = myCombinedStrings$ +  ","
    myCombinedStrings$ = myCombinedStrings$ + liste$(i)
Next i

'Print out the entire string resorted
Print myCombinedStrings$ 



{:0)

Brandon
User IP Logged

Windows 7 Home Premium 64-bit Intel(R) Quad Core(TM) i5 CPU M 430 @ 2.27GHz 4GB DDR3 RAM
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1643
xx Re: What'S wrong
« Reply #4 on: Aug 24th, 2016, 2:28pm »

Quote:
To sort records with many fields saved in Direct access, I have to copy the fields in an array separated by ",". Once the array is sorted, I have to write it back as a record, and to do this, I have to separate the array using «upto$» and «replstr$» but it doesn't work.

Not clear yet.
If you need sort stuff, why not use double dimensional array, put each field in distinct column, and sort by column needed (read up on SORT)?
If you chose to combine string by "," and then need to split it back, why not use WORD$ (read up on WORD$)?
User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1643
xx Re: What'S wrong
« Reply #5 on: Aug 24th, 2016, 2:40pm »

As to why your code don't work
(checked by printing all intermediate liste$(1))

then you run
Code:
replstr$(liste$(1),prenom$+",","") 

it changes "a," in all places it finds. In "ada," too.

You just choose wrong tool.
(I suggest WORD$)
« Last Edit: Aug 24th, 2016, 2:41pm by tsh73 » User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
ombre
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 18
xx Re: What'S wrong
« Reply #6 on: Aug 31st, 2016, 10:35am »

I finally got it with double dimensional array. I had a brain freeze!!
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls