How to make number increment without database xojo

Can we create a increment number in a textfield without using a database

Really vague question…

TextField1.Text = str(Val(TextField1.Text) + 1)


Ok the code work but If I want my number to follow each time I click on the new button when I open my application is it possible

Then use the same code when the button is pressed.

Since we dot not know more on what you wish to do, that may be a wrong way to do it.

For example:

  • The text field should be set with the latest number used.
  • For that purpose, you need to save the latest number somewhere persistent after the application is closed.
  • What if the user clicks to button multiple time without completing the process ?
  • …

If on relaunching your application you need the Value (Text) of the TextField to be updated with the last value you had in it before closing the application then you need a way to persist the data. An SQLite database is what I would use for that. Back in the day I used .ini files to store such data but working with an SQLite database is a lot more simple in my opinion.

1 Like

You could use a Computed Property. eg “NextValue”

First, create a normal property in a module, window or class.
Right-Click the property in the project browser and choose “convert to computed property”.

This will create a getter, a setter and a private property, prefixed with a lower case m.
The getter normally returns the value of the private property, mNextValue :

Return mNextValue

You can change the value before the value is going to be returned. That would look something like this:

mNextValue = mNextValue + 1
Return mNextValue

Every time you use the property value, it is increased by one.

So, Something like this will happen:

Var A, B, C As Integer
A = NextValue ' A will be set to 1
B = NextValue ' B will be set to 2
C = NextValue ' C will be set to 3

But if you bind this to a button, you might want to add the possibilities like Gilles pointed out. Especially when a user clicks a button multiple times. Maybe you could briefly disable the button after it is being clicked. When you are done with your process, you could enable the button again.

In the Action event of the button:

Me.Enabled = False

Var A As Integer = NextValue ' remember, this is that incremented value
// process whatever you need to process with the incremented value
// But use the acquired value that is stored in a variable, here I used the "A" variable
// Because, when you call "NextValue" again, it will increase the value again, of course

Me.Enabled = True

Screen Shot 2022-07-05 at 9.31.33 AM
To have a sequential number for all the job

Out of curiosity: why would you not use the database’s numbering capability?

Because a save in a file not in database

1 Like

You need to save the value to a file that your app will read when you open the application and set the value.

1 Like

It has to be stored somewhere between app restarts, whether a database, text file, binary file, registry/system setting, web service etc. If you pick one people can help you with some code.


If you are already SAVING it on a file, what is the problem reading it again the last value and adding one to it? :face_with_raised_eyebrow:

When I create another file the number will be the same I want incremental number that is the problem

You have spent more time waiting for responses that don’t help you than you have writing out what it is that you actually want. Being a programmer is about giving full and complete instructions to a machine. The least you can do is provide full and complete instructions to us.

Since you can’t provide us a full description of what you’re trying to do, perhaps you should start with the Introduction to Xojo Programming book instead.


Is there a specific reason for which you cannot use a database?

1 Like

Save the last state of the number to a text file and when the program runs again read the saved number back in

Ok if I use a database how can I save and retrieve by number. Ex. my first file is 1234 and the second is 12345. And how to make the sequential number with each new file

I’v always found the people in the forum very helpulf. But to get help you need to do some basic things first:

  1. As @Tim_Parnell said, state your question very clearly.
  2. Do your homework first. In this case may I ask if you have read how to create an SQLite database and get Xojo to connect to it? If not, then that’s the first place you should start. If you have a specific question about how to handle that then feel free to ask a clear question about it.

We will try to help you along the way as long as you are willing to help yourself :slight_smile:

Can you explain a little better what your program is trying to do?
For me is not clear:

Ex. my first file is 1234 and the second is 12345.

What are these files?
Are you creating these files?
Are you getting and processing these files external to your application?

what does it mean

make the sequential number with each new file

Does file 1234 will be 1 and file 12345 will be 2?

as you see, I don’t understand how your program works so I can’t help you with the sequential number.

Maybe the solution is as easy as having one file (or database) that holds this sequential number. That you program in which events it is incremented and save that increment to the file/database. But if that depends on the file that you open and if you open file 1234 then file 12345 I don’t know if that number should be increased by 2 (one for each file) or increased to 1234 for the first file and to 12345 to the second file. Or a different way.

When I press new, I want to create a new folder with a number i.e. the folder will have a unique number (Example: folder no. C4567 .) After saving if I want to create a new file this one will have to carry the Number C4568 and so on.