It has been discussed in other places on wish lists etc that each time we compile our projects under B4A that it would nice to have a BUILD number increment by 1.
Using the CustomBuildAction described in this tutorial
http://www.b4x.com/android/forum/threads/modules-attributes.24721/
I have managed to accomplish a BUILD increment operation.
I used the Windows scripting program called wscript and a jscript file as follows
Use Notepad and save the following lines in Italics to a file somewhere convenient on your PC. In my case I used d:\myscript.js Must have js extension.
Now you will need to change ONE line your script file to match where your project is on PC.
This is highlighted below. (note the \\ in the path of the filename)
var fst, f, fileCount;
var ForReading = 1, ForWriting = 2;
var filename = "D:\\MyProject\\Files\\mybuild.txt";
fst = new ActiveXObject("Scripting.FileSystemObject");
//create file if its not found
if (! fst.FileExists(filename))
{
f = fst.OpenTextFile(filename, ForWriting, true);
f.Write("0");
f.Close();
}
f = fst.OpenTextFile(filename, ForReading);
fileCount = parseInt(f.ReadAll());
//make sure the input is a whole number
if (isNaN(fileCount))
{
fileCount = 0;
}
fileCount = fileCount + 1;
f = fst.OpenTextFile(filename, ForWriting, true);
f.Write(fileCount);
f.Close();
then in the ProjectAttributes section add the line below
#CustomBuildAction: 1, c:\windows\system32\wscript.exe, d:\myscript.js
where d:\myscript.js is the name I used for my scripting file above.
Add the file mybuild.txt to your Files directory by using the RHS Tab and Add Files.
Each time you compile the script runs, opens the file, increments the number by 1
and saves it again.
Then in your code can simply have a subroutine like below to get your current build number.
Sub get_current_build
'
Dim myline As String
txt_reader.Initialize(File.OpenInput(File.DirAssets,"mybuild.txt"))
myline = txt_reader.ReadLine
txt_reader.Close
current_build=myline
'
End Sub
Trust this helps others.
Using the CustomBuildAction described in this tutorial
http://www.b4x.com/android/forum/threads/modules-attributes.24721/
I have managed to accomplish a BUILD increment operation.
I used the Windows scripting program called wscript and a jscript file as follows
Use Notepad and save the following lines in Italics to a file somewhere convenient on your PC. In my case I used d:\myscript.js Must have js extension.
Now you will need to change ONE line your script file to match where your project is on PC.
This is highlighted below. (note the \\ in the path of the filename)
var fst, f, fileCount;
var ForReading = 1, ForWriting = 2;
var filename = "D:\\MyProject\\Files\\mybuild.txt";
fst = new ActiveXObject("Scripting.FileSystemObject");
//create file if its not found
if (! fst.FileExists(filename))
{
f = fst.OpenTextFile(filename, ForWriting, true);
f.Write("0");
f.Close();
}
f = fst.OpenTextFile(filename, ForReading);
fileCount = parseInt(f.ReadAll());
//make sure the input is a whole number
if (isNaN(fileCount))
{
fileCount = 0;
}
fileCount = fileCount + 1;
f = fst.OpenTextFile(filename, ForWriting, true);
f.Write(fileCount);
f.Close();
then in the ProjectAttributes section add the line below
#CustomBuildAction: 1, c:\windows\system32\wscript.exe, d:\myscript.js
where d:\myscript.js is the name I used for my scripting file above.
Add the file mybuild.txt to your Files directory by using the RHS Tab and Add Files.
Each time you compile the script runs, opens the file, increments the number by 1
and saves it again.
Then in your code can simply have a subroutine like below to get your current build number.
Sub get_current_build
'
Dim myline As String
txt_reader.Initialize(File.OpenInput(File.DirAssets,"mybuild.txt"))
myline = txt_reader.ReadLine
txt_reader.Close
current_build=myline
'
End Sub
Trust this helps others.
Last edited: