Report Bugs Here

Moderator: Mmiscool

User avatar
By decathlon65
#95685 Hi Mike,

I'm a newbie for programming with your ESP Basic, I'm trying to program for me a short program which will save some values in a array, but it doesn't work.
I have try both versions to dim the array, but I can't fill the arrays with values. Here are my code:

memclear
dim date_array(20) as string
dim time_array(20) as string
dim alter_wert(20) as string
x = 0
zaehler = 1245
nenner = 90
' gosub [zaehler_wandeln]
io(po,d1,1)
interrupt d1, [change]
textbox zaehler
textbox nenner
button Speichern, [delete]
wait

[change]
if io(laststat,d1) = 0 then
delay 100 ' 100ms warten
' print "Pin is High"
nenner = nenner + 1
if nenner > 99 then
zaehler = zaehler + 1
nenner = 00
endif
if nenner <10 then
nenner = "0" & nenner
endif
endif
wait
[delete]
x = x + 1
print x
alter_wert(x) = zaehler & "." & nenner
date_array(x) = time("day-month-year")
time_array(x) = time("hour:min")
textbox date_array(x)
textbox time_array(x)
textbox alter_wert(x)
wait
end

Thanks in advance for your time and help,
Christoph
User avatar
By rooppoorali
#95910 It seems like there are a few issues with your code.

The subroutine [zaehler_wandeln] is not defined anywhere in the code, this will result in an error.
memclear is not an ESP Basic command, and will result in an error.
You are using textbox without assigning it to any UI element. This will result in an error.
Here's a corrected version of your code:
Code: Select all      'Remove the memclear command
dim date_array(20) as string
dim time_array(20) as string
dim alter_wert(20) as string
x = 0
zaehler = 1245
nenner = 90

' Set up interrupt on pin d1
interrupt d1, [change]

' Display values of zaehler and nenner in textboxes
textbox "zaehler", zaehler
textbox "nenner", nenner

' Add a button to save values to arrays
button "Speichern", [delete]

' Wait for user input
wait

[change]
  if io(laststat,d1) = 0 then
    delay 100 ' 100ms wait
    nenner = nenner + 1
    if nenner > 99 then
      zaehler = zaehler + 1
      nenner = 00
    endif
    if nenner <10 then
      nenner = "0" & nenner
    endif
  endif
  wait
 
[delete]
  x = x + 1
  alter_wert(x) = zaehler & "." & nenner
  date_array(x) = time("day-month-year")
  time_array(x) = time("hour:min")
 
  ' Display the values in textboxes
  textbox "date_array(" & x & ")", date_array(x)
  textbox "time_array(" & x & ")", time_array(x)
  textbox "alter_wert(" & x & ")", alter_wert(x)
 
  wait
end