Changing form label text (more than once within the code)

Hello,

I’m new to XOJO, and really have only programmed some macros for a CAD package I have at work, but I’m trying to help my son with a school project. Part of the code he is supposed to do is to display a letter on a label for one second, then display another letter for a second, etc- 5 times, (i assume on the same label, however i suppose it could clear the first one and go to a new label each time).

with five letters defined, we go to this:

Label2.Text = str(Letter1)
App.SleepCurrentThread(1000)
Label2.Text = str(Letter2)
App.SleepCurrentThread(1000)

etc, but the problem is it doesn’t even show letter 1, it just displays the last letter.

we’ve also tried this in place of the sleep command (while declaring this also: Dim Timer1 As New Timer):
Timer1.Mode = 2
Timer1.Period = 1000

I also tried a method with:
Xojo.Core.Timer.CallLater(1000, AddressOf ClearLabel)

None of these work, are we on the right track here??

Thanks!

Look at INVALIDATE (just a hint… since this IS a homework assignment it seems)

remember that unlike the days of old, modern GUI are event driven, so controls don’t refresh just because you change the content, they refresh with an event tells them to.

I would use the ACTION event of a timer

Dave,

try not to laugh as i describe this, but i created a timer, and then an action under that. i inserted the code to display the letter, then set the mode and period, then did those three lines again for letter two.

this action is supposed to occur upon clicking a button (like ‘start’), but as you may have guessed it happens as soon as i run it, but it just keeps going… at the end of all this, we need to have all the letters put into a string, and ask the user to input what they saw in a text field. I have no clue on how to ‘make the code go’ from one pushbutton action to an action for a timer, to an action for another pushbutton…

unfortunately nowadays there is no book for the class, so all we are going by is what we can find online and in the docs.

Why would I laugh… learning is no laughing matter… :slight_smile:

  • create a module
  • create an integer variable in the module… call it NextChar
  • create a label (call it ShowChar)
  • create a timer (call it Timer1, set the period to 1000 … this will be 1 second), set mode to to timer.modeOff
  • in the ACTION of the time put this code
dim s as string="ABCDEFGHIJK" // or what ever characters you want displayed
NextChar=NextChar+1
if NextChar>S.Len then NextChar=1 // so it starts over again once it comes to the end of the list of characters
ShowChar.text=Mid(s,NextChar,1) // put the next character into the label
ShowChar.Invalidate
  • create a BUTTON on the screen (call it btnStart)
  • in the ACTION of the button put
If timer1.mode=timer.modeoff then 
timer1.mode=timer.modeMultiple
else
timer1.mode=timer.modeoff
end if

Note there is TIMER1 and TIMER both used in above code… :slight_smile: Timer1 is the control, Timer is to reference properties of “A Timer”

This should (assuming I made no mistakes typeing this off the top of my head), give you a window with a label and a button. Pressing the button will start and stop the timer, when the timer is running, the letter in the label should change once per second.

So as to no confuse… the Button, the label and the timer contols go on a window
the Module is just to allow NextChar variable to be “global” to all parts of the app

Dave,

I appreciate the time you are spending helping us. I think its starting to click. We started a new program with what you have above though, and when we run it it gives us an error in the action for the timer, as it states ‘NextChar’ doesn’t exist on the three lines it is used.

Somehow we think that the dim NextChar as Integer that is in the module is not global. Perhaps we created that wrong? We added a method in the module, and then added the NextChar there.

We’ve been working on this for a while and we may take this back up in the morning.

Thanks for your help!

[quote=237865:@Bradford Whitten]
unfortunately nowadays there is no book for the class, so all we are going by is what we can find online and in the docs.[/quote]

Not sure what book you might be looking for but there is one that Xojo inc had produced
You might try referring to http://xojo.com/learn/index.php

NextChar must be defined to the MODULE… don’t create a method and “dim” it there.
And it must have a scope of PUBLIC…

we cannot figure out how to get into the code editor for the module. after its created, we click on it and it just says ‘no editor’.

Norman, we have been referencing that doc, and we tried adding a property as it says on page 209/210. However the example there is based on a longer project that we did not do, and it didn’t work or we didn’t apply it correctly.

You dont edit a module
You add methods, properties or other items to it and you edit those
select the module, right click or select the “Insert” menu and add a “property” or “method”

Dave, thanks for the help with the above code. Norman, we looked at adding a property a bit more and noticed that it can be added not in the text area, but rather on the right hand side in the pane…

Anyhow now that we have gone this far I’m thinking we can figure out the rest, how to piece it together.

Thanks! We’ll let you know how it turns out.

[quote=237961:@Bradford Whitten]Dave, thanks for the help with the above code. Norman, we looked at adding a property a bit more and noticed that it can be added not in the text area, but rather on the right hand side in the pane…

Anyhow now that we have gone this far I’m thinking we can figure out the rest, how to piece it together.

Thanks! We’ll let you know how it turns out.[/quote]
I sent you a private message… did you see it?