Flickering in HTML

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

Flickering in HTML

Post by Helmut_number_one »

How can i Prevent that Flickering in HTML
With this code i have flickering, bad...

Code: [Local Link Removed for Guests]

  CLS
     ' HTML " Momentane Leistungsaufnahme: " + TEXTAREA$(Ergebnis$) + " W"
     HTML " Momentane Leistungsaufnahme: " + TEXTBox$(Ergebnis$) + " W"
User avatar
cicciocb
Site Admin
Posts: 2195
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 470 times
Been thanked: 1461 times
Contact:

Re: Flickering in HTML

Post by cicciocb »

Simply don't use CLS all the time but use autorefresh

The value will be refreshed automatically
Helmut_number_one
Posts: 122
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 54 times
Been thanked: 14 times

Re: Flickering in HTML

Post by Helmut_number_one »

Well, I read a data source in a continuous loop and without CLS the text in the HTML output would be rewritten a thousand times...

I found a demo:
[Local Link Removed for Guests]
No, it doesn't help me, this is my code and in HTML it is flickering:

Code: [Local Link Removed for Guests]

'MODBUS example - write and read in the HOLD_REGISTER 0
READ_HOLD_REGISTER = 3
READ_INPUT_REGISTER = 4
'WRITE_HOLD_REGISTER = 6
SERVER_ID = 1
' MODBUS.CONNECT IP$, [port] [,timeout] [,idleTimeout]
onWgetAsync modbus_received 'set the event handler function
pause 200
modbus.connect "192.168.0.200", 4196,  1000', 10 'address of the remote server
pause 200
for z = 1 to 1000 ' 100 X read ----  Anzahl der Leseung
'modbus.request 4567, SERVER_ID , READ_HOLD_REGISTER , 4157, 1  ' 16 bit
modbus.request 4567, SERVER_ID , READ_HOLD_REGISTER , 4157, 2 ' 32 Bit
pause 100
next z
end
modbus_received:
r$ = WGETRESULT$
'wlog r$
print r$
token$ = word$(r$, 1) 'extract the token (first word)
if (token$ ="4567") then ' if the token correspond to the read request
  if (word$(r$, 2) <> "Error") then 'if is not an error
    'assemble the 2 bytes in one 16 bits word
    'value$ = "&h"+ word$(r$, 5) + word$(r$, 6)
     'assemble the 4 bytes in one 32 bits word, it dosn't running
    value$ = "&h"+ word$(r$, 5) + word$(r$, 6) + word$(r$, 7) + word$(r$, 8)
    Ergebnis1= val(value$)
    'wlog val(value$) 'converts from hex to integer
    
   Ergebnis =  ( CONVERT.FROM_IEEE754(Ergebnis1) * 1000)
   Vortext$ = " Momentane Leistungsaufnahme: " 
   Ergebnis$ = str$(Ergebnis,"%6.2f") + " Watt"

   CLS
  ' HTML " Momentane Leistungsaufnahme: " + TEXTAREA$(Ergebnis$) + " W"
   ' or
   HTML " Momentane Leistungsaufnahme: " + TEXTBox$(Ergebnis$) + " W"
  ' wlog Ergebnis
  end if
endif
return

Last edited by Helmut_number_one on Sun Apr 14, 2024 3:17 pm, edited 1 time in total.
User avatar
cicciocb
Site Admin
Posts: 2195
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 470 times
Been thanked: 1461 times
Contact:

Re: Flickering in HTML

Post by cicciocb »

You must just create the object once and then with autorefresh it will be refreshed automatically.

Examples :

Code: [Local Link Removed for Guests]

cls
Ergebnis = 0
HTML " Momentane Leistungsaufnahme: " + TEXTBox$(Ergebnis) + " W"
autorefresh 500 ' refresh automatically each 500msec

for z = 0 to 1000
  Ergebnis = z * 10
  pause 1000
next z
User avatar
cicciocb
Site Admin
Posts: 2195
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 470 times
Been thanked: 1461 times
Contact:

Re: Flickering in HTML

Post by cicciocb »

Or you can create one and refresh manually :

Code: [Local Link Removed for Guests]

cls
Ergebnis = 0
HTML " Momentane Leistungsaufnahme: " + TEXTBox$(Ergebnis) + " W"

for z = 0 to 1000
  Ergebnis = z * 10
  refresh
  pause 1000
next z
User avatar
Electroguard
Posts: 946
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 310 times
Been thanked: 352 times

Re: Flickering in HTML

Post by Electroguard »

Or only refresh the screen if a value changes.
Helmut_number_one
Posts: 122
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 54 times
Been thanked: 14 times

Re: Flickering in HTML

Post by Helmut_number_one »

Hm,
Well, the data source is my power consumption, it's constantly changing, I thought I could just update the textbox contents without rewriting the HTML page.
Post Reply