UDP.WRITE with String and Variable

Code tips and tricks for beginners
Post Reply
Helmut_number_one
Posts: 93
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 36 times
Been thanked: 8 times

UDP.WRITE with String and Variable

Post by Helmut_number_one »

I want split the UDP String

Code: [Local Link Removed for Guests]

udp.write "192.168.0.44", 20057, "OSV17=1" ' this is ok
with a Variable i

Code: [Local Link Removed for Guests]

for i=17 to 22
udp.write "192.168.0.44", 20057, "OSV",i,"=1"   ' i try this 
NEXT i
but it isn't run ( Syntax error by udp.write)
Can a user explane the syntax?
Best regards
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: UDP.WRITE with String and Variable

Post by Electroguard »

Don't mix string variables and numeric variables in the same instruction, convert numbers to string and append them, eg:
a$= "number="
n=99
wlog a$ + " " + str$(n)

Then you can extract later using val()
Helmut_number_one
Posts: 93
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 36 times
Been thanked: 8 times

Re: UDP.WRITE with String and Variable

Post by Helmut_number_one »

Thankyou, very helpfull !!
Edit
I found in the help-file this example by

onUDP Event:

Code: [Local Link Removed for Guests]

udp.begin 5001  'set the UDP commmunication using port 5001
onudp goudp
'Write several messages to the port
for i = 0 to 100
   udp.write "192.168.1.44", 5001, "Hello " + str$(i)
next i
wait

goudp:
v$ = udp.read$ 'receive the UDP data

print v$
return
the i write this cmd and it run

Code: [Local Link Removed for Guests]

 udp.write "192.168.0.44", 20057, "OSV" + str$(i) +"=1"
Post Reply