Liberty BASIC Community Forum
« IF AND ??? »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 6:09pm


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


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: IF AND ???  (Read 237 times)
Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx IF AND ???
« Thread started on: Dec 30th, 2017, 11:01am »

Hello,

I had this code what worked for me:
input "age:"; age$
for i = 1 to 500
if age$ = a$(i) then
print a$(i)$+age$
end if
next i

But now I have an second string ab$(i).
How can I tel that age must be a$(i) and ab$(i)?

Thanks!!

« Last Edit: Dec 30th, 2017, 11:02am by Konijn » User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1179
xx Re: IF AND ???
« Reply #1 on: Dec 30th, 2017, 2:40pm »

As you quoted it your program won't run.
Did you copy/paste, or did you retype in error Code:
'a$( i)$'? 


Can you give the whole code? Click the # sign on the forum editor and put your code within the resulting [ code] and [ /code] markers. It is then more easily read, as I've done here.

I assume you are dimensioning and filling the arrays first??

As far as using two conditions rather than just one you can use
Code:
if age$ = a$(i) and age$ =ab$( i)  then
print a$(i)$+age$
end if 


Most of us would enter that as
Code:
if age$ = a$(i) and age$ =ab$( i)  then print a$(i)$+age$ 


Keep at it... coding gets easier with practice & we are glad to help...
« Last Edit: Dec 30th, 2017, 2:43pm by tenochtitlanuk » User IP Logged

Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: IF AND ???
« Reply #2 on: Dec 31st, 2017, 09:53am »

Code:
open "c:\melkteller\inlees.csv" for input as #readFile
open "c:\melkteller\voer1.csv" for input as #voer
dim a$(3000)
dim b$(3000)
dim c$(3000)
dim d$(3000)
dim e$(3000)
dim f$(3000)
dim g$(3000)
dim h$(3000)
dim i$(3000)
dim j$(3000)
dim k$(3000)
dim l$(3000)
dim m$(3000)
dim n$(3000)

while not(eof(#readFile))
inputcsv #readFile, a$(i), b$(i), c$(i), d$(i), e$(i), f$(i), g$(i), h$(i),i$(i), j$(i), k$(i), l$(i), m$(i), n$(i)
    i=i+1
wend
close #readFile
for j=0 to i
print a$(j), b$(j), c$(j), d$(j), e$(j), f$(j), g$(j), h$(j), i$(j), k$(j), l$(j), m$(j), n$(j)
next j

[voerinlees]
dim voera$(3000)
dim voerb$(3000)
dim voerc$(3000)
dim voerd$(3000)
dim voere$(3000)
dim voerf$(3000)
dim voerg$(3000)
dim voerh$(3000)
dim voeri$(3000)
dim voerj$(3000)
dim voerk$(3000)
dim voerl$(3000)
dim voerm$(3000)
dim voern$(3000)
dim voero$(3000)
dim voerp$(3000)
while not(eof(#voer))
   inputcsv #voer, voera$(i), voerb$(i), voerc$(i), voerd$(i), voere$(i), voerf$(i), voerg$(i), voerh$(i), voeri$(i), voerj$(i), voerk$(i), voerl$(i), voerm$(i), voern$(i), voero$(i), voerp$(i)
    i=i+1
wend
close #voer

for j=0 to i
    print voera$(j), voerb$(j), voerc$(j), voerd$(j)
next j




[verstuur]
input "koenummer:"; koenr$
for i = 1 to 500
     if koenr$ = voera$(i) and koenr$ = a$(i) then
print a$(i)+voera$(i)+l$(j)+voerb$(i)
print ";"+a$(i)+";Vader: ;"+l$(i)+";Klfdt: ;"+k$(i)+"("+g$(i)+")"+";;;Status:;"+j$(i)+"("+h$(i)+");Voer;"+voerb$(i)+";Mlk305:;;V/E:   ;"+e$(i)+"  "+f$(i)+";Cel:   ;"+d$(i)+";;;Apart:;"+b$(i)+";;;;;"
end if


     next


 
« Last Edit: Dec 31st, 2017, 10:02am by Konijn » User IP Logged

Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: IF AND ???
« Reply #3 on: Dec 31st, 2017, 09:56am »

Hello,

This is the code. I think the problem is that I combine 2 files and I want to send from both files the strings in one string.
The IF and And is with this code not working I am afraid
User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1179
xx Re: IF AND ???
« Reply #4 on: Dec 31st, 2017, 11:48am »

The following code seems to work. I abbreviated some of your code and rearranged some lines, and had to generate the test files and make sure that an item in the first column of each matched the entry I reply with!
Things like lumping the dimension lines together make for more compact code, so easier to follow logic thread.

Code:
goto [skip] '   this just generates some sample files....

open "inlees.csv" for output as #file1Out
open "voer1.csv"  for output as #file2Out
    for i =0 to 3000
        for k =1 to 14
            #file1Out randItem$();
            if k <14 then #file1Out ","; else #file1Out ""
        next k

        for k =1 to 16
            #file2Out randItem$();
            if k <16 then #file2Out ","; else #file2Out ""
        next k
    next i
close #file1Out
close #file2Out
'   NB I then manually make sure both have a line with matching first entries...

[skip]  '   _____________________________________________________

dim a$(3000), b$(3000), c$(3000), d$(3000), e$(3000), f$(3000), g$(3000)    '   14 fields
dim h$(3000), i$(3000), j$(3000), k$(3000), l$(3000), m$(3000), n$(3000)

dim voera$(3000), voerb$(3000), voerc$(3000), voerd$(3000), voere$(3000), voerf$(3000), voerh$(3000), voerg$(3000)
dim voeri$(3000), voerj$(3000), voerk$(3000), voerl$(3000), voerm$(3000), voern$(3000), voero$(3000), voerp$(3000)'  16 fields

i =0
open "inlees.csv" for input as #readFile
    while not( eof( #readFile))
        inputcsv #readFile, a$(i), b$(i), c$(i), d$(i), e$(i), f$(i), g$(i), h$(i),i$(i), j$(i), k$(i), l$(i), m$(i), n$(i)
        'print               a$(j), b$(j), c$(j), d$(j), e$(j), f$(j), g$(j), h$(j), i$(j), k$(j), l$(j), m$(j), n$(j)
        i =i +1
    wend
close #readFile

[voerinlees]
i =0
open "voer1.csv"  for input as #voer
    while not( eof( #voer))
        inputcsv #voer, voera$(i), voerb$(i), voerc$(i), voerd$(i), voere$(i), voerf$(i), voerg$(i), voerh$(i), voeri$(i), voerj$(i), voerk$(i), voerl$(i), voerm$(i), voern$(i), voero$(i), voerp$(i)
        'print           voera$(i), voerb$(i), voerc$(i), voerd$(i), voere$(i), voerf$(i), voerg$(i), voerh$(i), voeri$(i), voerj$(i), voerk$(i), voerl$(i), voerm$(i), voern$(i), voero$(i), voerp$(i)
        i =i +1
    wend
close #voer

[verstuur]
input "koenummer:"; koenr$
for i = 1 to 3000
    if ( koenr$ = voera$( i)) and ( koenr$ = a$( i)) then
        print a$(i), voera$(i), l$(j), voerb$(i)
        print ";" +a$(i) +";Vader: ;" +l$(i) +";Klfdt: ;" +k$(i) +"(" +g$(i) +")" +";;;Status:;"_
             +j$(i) +"(" +h$(i) +");Voer;" +voerb$(i) +";Mlk305:;;V/E:   ;"+e$(i)+"  "+f$(i)_
             +";Cel:   ;" +d$(i) +";;;Apart:;" +b$(i) +";;;;;"
    end if
next i

print "Done"

end

function randItem$()
    for j =1 to 2
        randItem$ =randItem$ +chr$( 65 +int( 26 *rnd( 1)))
    next j
end function
 


QW,AZ,PB,YG,LE,EW,TV,RB,NW,VZ,ER,TP,MF,ZS
TE,TI,ZO,BU,KQ,UT,RH,IU,BG,YO,EF,SM,UW,QF
JR,VH,IO,YI,CQ,DJ,JL,CO,WN,OU,OV,YT,YD,AY
MI,JB,OW,TF,EM,UM,RB,YO,SH,YQ,BH,YW,LB,QN
LV,NI,YL,NC,JF,PC,CN,JH,DL,MO,UE,MB,CB,OM
EK,BR,BY,EJ,FB,DF,IZ,YZ,FP,XC,JJ,RP,WP,MR
WX,RW,MX,DQ,CU,WC,GR,KH,IR,OM,BN,HA,XV,HH
etc..etc..


TG,XZ,RF,YM,KZ,QQ,DF,DP,QL,LE,RK,XI,QM,CX,LG,EB
YN,UZ,KQ,OD,WZ,JU,LL,GO,PT,KR,KF,BM,YH,NQ,BO,ZX
JR,VH,IO,YI,CQ,DJ,JL,CO,WN,OU,OV,YT,YD,AY,ZZ,ZZ
AK,JH,LL,SY,FM,CD,EV,TB,EO,QN,UW,AT,QX,NH,DO,NX
IL,PY,ZA,RB,MZ,KD,YJ,TW,EE,AW,CZ,JL,VV,YO,EX,NN
PM,DI,OT,MU,DQ,NM,JC,JM,RP,LV,SB,LL,AP,NR,WI,VE
IY,BY,WJ,ID,EI,VV,XQ,GI,ZB,WQ,VO,XK,DM,XU,SS,QK
etc..etc..


Note how I made sure that a line (third one) has same value in both files.

I'm not sure what all your columns of data represent, and how you intend them to be formatted....
.
User IP Logged

Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: IF AND ???
« Reply #5 on: Dec 31st, 2017, 1:59pm »

Thanks tenochtitlanuk,

I tried the code, but get no result. What I notice, LB looks by both files on the same line. Just what you said.
But is it possible that LB wil find the value in the other while its not on the same line as the first file?
I think I can manage to make 2 files with the same value in the first row, but its tricky!
Thanks
Jack

User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1179
xx Re: IF AND ???
« Reply #6 on: Dec 31st, 2017, 2:42pm »

In that case, first find ( in my case) 'JR' in the first file, then separately in the second. You probably will need to change the path/filename unless you have the files in the same directory. Only the bit looking for the koenr$ to be found is changed...
Any better?

Code:
goto [skip] '   this just generates some sample files....

open "inlees.csv" for output as #file1Out
open "voer1.csv"  for output as #file2Out
    for i =0 to 3000
        for k =1 to 14
            #file1Out randItem$();
            if k <14 then #file1Out ","; else #file1Out ""
        next k

        for k =1 to 16
            #file2Out randItem$();
            if k <16 then #file2Out ","; else #file2Out ""
        next k
    next i
close #file1Out
close #file2Out
'   NB I then manually make sure both have a line with matching first entries...

[skip]  '   _____________________________________________________

dim a$(3000), b$(3000), c$(3000), d$(3000), e$(3000), f$(3000), g$(3000)    '   14 fields
dim h$(3000), i$(3000), j$(3000), k$(3000), l$(3000), m$(3000), n$(3000)

dim voera$(3000), voerb$(3000), voerc$(3000), voerd$(3000), voere$(3000), voerf$(3000), voerh$(3000), voerg$(3000)
dim voeri$(3000), voerj$(3000), voerk$(3000), voerl$(3000), voerm$(3000), voern$(3000), voero$(3000), voerp$(3000)'  16 fields

i =0
open "inlees.csv" for input as #readFile
    while not( eof( #readFile))
        inputcsv #readFile, a$(i), b$(i), c$(i), d$(i), e$(i), f$(i), g$(i), h$(i),i$(i), j$(i), k$(i), l$(i), m$(i), n$(i)
        'print               a$(j), b$(j), c$(j), d$(j), e$(j), f$(j), g$(j), h$(j), i$(j), k$(j), l$(j), m$(j), n$(j)
        i =i +1
    wend
close #readFile

[voerinlees]
i =0
open "voer1.csv"  for input as #voer
    while not( eof( #voer))
        inputcsv #voer, voera$(i), voerb$(i), voerc$(i), voerd$(i), voere$(i), voerf$(i), voerg$(i), voerh$(i), voeri$(i), voerj$(i), voerk$(i), voerl$(i), voerm$(i), voern$(i), voero$(i), voerp$(i)
        'print           voera$(i), voerb$(i), voerc$(i), voerd$(i), voere$(i), voerf$(i), voerg$(i), voerh$(i), voeri$(i), voerj$(i), voerk$(i), voerl$(i), voerm$(i), voern$(i), voero$(i), voerp$(i)
        i =i +1
    wend
close #voer

[verstuur]
input "koenummer:"; koenr$

i =0
while koenr$ <> voera$( i)
    i =i +1
wend

j =0
while koenr$ <> a$( j)
    j =j +1
wend

if i =3000 or j =3000 then print "Not found": end

print a$( j), voera$( i), l$( j), voerb$( i)

print koenr$; " was found in line "; i; " of voera$ array"
print "   and in line "; j; " of a$ array."
print "Done"

end

function randItem$()
    for j =1 to 2
        randItem$ =randItem$ +chr$( 65 +int( 26 *rnd( 1)))
    next j
end function
 
User IP Logged

Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: IF AND ???
« Reply #7 on: Jan 1st, 2018, 11:56am »

Hello tenochtitlanuk,

First best wishes for 2018!!!

Thanks this is working! Great!
a Question, if I enter a valua which is not in the both files, is it possible that LB only prints the value I entered?
If I do it now I get error.
https://www.zweedsgras.nl/wp-content/uploads/2018/01/Knipsel-1.jpg" alt="User Image" border="0">

And voerc$ and voerd$ are numbers, for example 0.5 and 13.2 How can I go to number to make a formule;
voerd$ - voerc$ = new value
new value/voerd$ *100 = percentage (rounded 0 decimals)
« Last Edit: Jan 1st, 2018, 12:07pm by Konijn » User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1179
xx Re: IF AND ???
« Reply #8 on: Jan 1st, 2018, 3:55pm »

Happy New Year to you too!

Try this- only made small changes but does what I think you want.
Code:
goto [skip] '   this just generates some sample files....

open "inlees.csv" for output as #file1Out
open "voer1.csv"  for output as #file2Out
    for i =0 to 3000
        for k =1 to 14
            #file1Out randItem$();
            if k <14 then #file1Out ","; else #file1Out ""
        next k

        for k =1 to 16
            #file2Out randItem$();
            if k <16 then #file2Out ","; else #file2Out ""
        next k
    next i
close #file1Out
close #file2Out
'   NB I then manually make sure both have a line with matching first entries...

[skip]  '   _____________________________________________________

dim a$(3000), b$(3000), c$(3000), d$(3000), e$(3000), f$(3000), g$(3000)    '   14 fields
dim h$(3000), i$(3000), j$(3000), k$(3000), l$(3000), m$(3000), n$(3000)

dim voera$(3000), voerb$(3000), voerc$(3000), voerd$(3000), voere$(3000), voerf$(3000), voerh$(3000), voerg$(3000)
dim voeri$(3000), voerj$(3000), voerk$(3000), voerl$(3000), voerm$(3000), voern$(3000), voero$(3000), voerp$(3000)'  16 fields

i =0
open "inlees.csv" for input as #readFile
    while not( eof( #readFile))
        inputcsv #readFile, a$(i), b$(i), c$(i), d$(i), e$(i), f$(i), g$(i), h$(i),i$(i), j$(i), k$(i), l$(i), m$(i), n$(i)
        'print               a$(j), b$(j), c$(j), d$(j), e$(j), f$(j), g$(j), h$(j), i$(j), k$(j), l$(j), m$(j), n$(j)
        i =i +1
    wend
close #readFile

[voerinlees]
i =0
open "voer1.csv"  for input as #voer
    while not( eof( #voer))
        inputcsv #voer, voera$(i), voerb$(i), voerc$(i), voerd$(i), voere$(i), voerf$(i), voerg$(i), voerh$(i), voeri$(i), voerj$(i), voerk$(i), voerl$(i), voerm$(i), voern$(i), voero$(i), voerp$(i)
        'print           voera$(i), voerb$(i), voerc$(i), voerd$(i), voere$(i), voerf$(i), voerg$(i), voerh$(i), voeri$(i), voerj$(i), voerk$(i), voerl$(i), voerm$(i), voern$(i), voero$(i), voerp$(i)
        i =i +1
    wend
close #voer

[verstuur]
input "koenummer:"; koenr$

i =0
while koenr$ <> voera$( i) and i <3000
    i =i +1
wend
if i <3000 then print "Found in voera$"

j =0
while koenr$ <> a$( j) and j <3000
    j =j +1
wend
if j <3000 then print "Found in a$()"

if i =3000 or j =3000 then print "Not found": end

print a$( j), voera$( i), l$( j), voerb$( i)

print koenr$; " was found in line "; i; " of voera$ array"
print "   and in line "; j; " of a$ array."
print "Done"

end

function randItem$()
    for j =1 to 2
        randItem$ =randItem$ +chr$( 65 +int( 26 *rnd( 1)))
    next j
end function
 


QUOTE. You asked..

And voerc$ and voerd$ are numbers, for example 0.5 and 13.2 How can I go to number to make a formule;
voerd$ - voerc$ = new value
new value/voerd$ *100 = percentage (rounded 0 decimals)


Check out the val() function ( turn strings into numbers)
Code:

voerc$ = "0.5"  '   both expressed as a string of ( numeric) characters
voerd$ ="13.2"  '   below I use 'val()' to turn strings into numbers for your formula

percentage =100 *(val( voerd$) -val( voerc$) ) /val( voerd$)

print percentage;                " shown as a raw decimal number."
print using( "###", percentage); "% with decimal parts suppressed."

end
 

You should see...
96.2121212 shown as a raw decimal number.
96% with decimal parts suppressed.
User IP Logged

Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: IF AND ???
« Reply #9 on: Jan 2nd, 2018, 2:10pm »

Hello tenochtitlanuk,

Thanks, this is great working!, Just what I need.
Only if voerc$ and voerd$ are 0 (0/0 huh) I get error.

The percentage like (96%) is good. I will make that the long string which I send to an Arduino display with the upd function over internet.

User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1179
xx Re: IF AND ???
« Reply #10 on: Jan 2nd, 2018, 3:05pm »

You can catch this- which amounts to attempting 'division by zero' with code like this...
Code:
voerc$ = "0.5"  '   both expressed as a string of ( numeric) characters
voerd$ ="13.2"  '   below I use 'val()' to turn strings into numbers for your formula

if val( voerd$) <>0 then
    percentage =100 *(val( voerd$) -val( voerc$) ) /val( voerd$)

    print percentage;                " shown as a raw decimal number."
    print using( "###", percentage); "% with decimal parts suppressed."
else
    print "Invalid operation- voerd$ =0"
end if

end
 

Glad to be of help- it's fun to have people usong LB to code real-life activities!
User IP Logged

Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: IF AND ???
« Reply #11 on: Jan 3rd, 2018, 06:20am »

Hello tenochtitlanuk,

Yes working. Now I want to send it by UDP. I have to make it back to string?
Code:
opname = (val( voerd$(i))-val( voerc$(i)))
   print opname, using( "###", percentage)
 

For sending I have to make this:

ok=UDPsend("192.168.2.18", 12080, str$(opname))

But how to make the rounded percentage:

using( "###", percentage)
If i place that in the string I get error.

Its I good and nice program with a lot of possibilitys. When I have it working I will place some photos, to get an idea where I am using it for!
User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1179
xx Re: IF AND ???
« Reply #12 on: Jan 3rd, 2018, 06:52am »

Yes, str$() is the opposite of val(), and converts strings of numeric characters to a number. So something like..
Code:

voerc$ = "0.5"  '   both expressed as a string of ( numeric) characters
voerd$ ="13.2"  '   below I use 'val()' to turn strings into numbers for your formula

if val( voerd$) <>0 then
    percentage =100 *(val( voerd$) -val( voerc$) ) /val( voerd$)

    print percentage;                " shown as a raw decimal number."
    print using( "###", percentage); "% with decimal parts suppressed."

    opname  = (val( voerd$( i)) -val( voerc$( i)))
    ok      =UDPsend( "192.168.2.18", 12080, str$( opname))

else
    print "Invalid operation- voerd$ =0"
end if

end

function UDPsend( i$, r, c$)    '   A dummy function- I know nothing of UDP!
    print "Sent.."
end function
 


And yes indeed, itb would be good to see screengrabs of your output and if you are not concerned about keeping it secret, your LB code. I and others are always glad to learn from others!
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