Android Question B4XStringFunctionVB

Theera

Well-Known Member
Licensed User
Longtime User
Hi all again,
I have just get Magret's stringfunction2 sourcecode. I think B4X should be easy for the beginner or non-expert about manage string.
After I have learned from the experts. I have tried converting Magret's stringfunction2 sourcecode to be supported B4X. I attached the files for the experts help me check it correctly.
If it has mistake,please help me coding. The credits is still be Magret. I love her library.

Best Regards
Theera
 

Attachments

  • B4XStringFunctionVB.rar
    11.9 KB · Views: 151

BlueVision

Active Member
Licensed User
Longtime User
Hello Theera,
Since no one is really answering you, I'll try my hand at it. I also used exactly this library under B4A for a long time and loved it, because it ports familiar BASIC terms to B4A (left, right, mid). Unfortunately, this library did not run under B4J.
I have not yet been able to look at your work due to time constraints. But: There are built-in string functions in both B4A and B4J that work similarly and are well documented...

Imagine, you have a given string named MYSTRING, then try this in the IDE:

MYSTRING.Substring(.........................)
MYSTRING.Substring2(........................)

Follow the description for setting the pointers. It is a little bit different, but very similar when it comes to basic stringoperations.
I was able to remove Magret's stringfunctions completely. As good as it is, it is better to work with the built-in functions already available. My opinion.
Sure, there are some nice features within Magret's library (I think a low-level encryption and such things). But nowadays this library is like a 5th wheel on a car. Not necessary IMHO.

This is only a friendly advice I want to give. Not meant in a bad way. Many roads lead to rome...
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Hello Theera,
Since no one is really answering you, I'll try my hand at it. I also used exactly this library under B4A for a long time and loved it, because it ports familiar BASIC terms to B4A (left, right, mid). Unfortunately, this library did not run under B4J.
I have not yet been able to look at your work due to time constraints. But: There are built-in string functions in both B4A and B4J that work similarly and are well documented...

Imagine, you have a given string named MYSTRING, then try this in the IDE:

MYSTRING.Substring(.........................)
MYSTRING.Substring2(........................)

Follow the description for setting the pointers. It is a little bit different, but very similar when it comes to basic stringoperations.
I was able to remove Magret's stringfunctions completely. As good as it is, it is better to work with the built-in functions already available. My opinion.
Sure, there are some nice features within Magret's library (I think a low-level encryption and such things). But nowadays this library is like a 5th wheel on a car. Not necessary IMHO.

This is only a friendly advice I want to give. Not meant in a bad way. Many roads lead to rome...
Thank you for your opinion. I think the library is useful for only non-expert,it is only selection way. We can select use it or not. I think if we need to promote B4X for all of world wide users. We must make B4X be the easiest.
Best Regards,
Theera
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
I think we should have something familiar for members who come from different language, like Clipper, VB, Python etc.
Once they feel at home they can move to the built-in functions.

I made Clipper (DOS) like command syntax for my juniors to use in XBase++ GUI (Win).
Once they had experience, they shifted to direct XBase++ commands.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The credits is still be Magret. I love her library.
I retrieved all 12 date functions you have in the B4XStringFunctionVB. bas file you posted in post #1 and created a B4XPages project with them. They all ran well. I also created the equivalent of those functions using only Datetime and/or DateUtils to compare the two methods. Each of the methods I used has only one line of code. The comparison was also good. I concluded that you really do not need Margret’s functions for any of those date functions. If you are interested I can post the B4XPages project.
As an example your code is:
B4X:
Log(CurrentWeek( "01/31/2019"))   'Theera
B4X:
Sub CurrentWeek (MyDate As String) As Int
    Private Ticks As Long = DateTime.DateParse( MyDate)
    Private df As String = DateTime.DateFormat
    DateTime.DateFormat = "w"
    Private res As String = DateTime.date( Ticks)
    DateTime.DateFormat = df
    Return res    'as int
End Sub
Below is the equivalent code I wrote which yields the same result is:
B4X:
Log(DateTime.GetDayOfWeek(DateTime.dateparse("01/31/2019")))   'Mahares
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I retrieved all 12 date functions you have in the B4XStringFunctionVB. bas file you posted in post #1 and created a B4XPages project with them. They all ran well. I also created the equivalent of those functions using only Datetime and/or DateUtils to compare the two methods. Each of the methods I used has only one line of code. The comparison was also good. I concluded that you really do not need Margret’s functions for any of those date functions. If you are interested I can post the B4XPages project.
As an example your code is:
B4X:
Log(CurrentWeek( "01/31/2019"))   'Theera
B4X:
Sub CurrentWeek (MyDate As String) As Int
    Private Ticks As Long = DateTime.DateParse( MyDate)
    Private df As String = DateTime.DateFormat
    DateTime.DateFormat = "w"
    Private res As String = DateTime.date( Ticks)
    DateTime.DateFormat = df
    Return res    'as int
End Sub
Below is the equivalent code I wrote which yields the same result is:
B4X:
Log(DateTime.GetDayOfWeek(DateTime.dateparse("01/31/2019")))   'Mahares
Many thanks for advice. Everyone can editted by yourself. This library is own everyone. (Not belongs to me) credits for Magret and others who help adjust better. Please don't forget to give the sourcecode for me for studying.
**Made with love in B4X **
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It will be helpful for people from another computer language
Everyone can editted by yourself
Attached is a B4XPages project tested in B4A and B4J which compares the calculations done by Margret's date functions to B4X date functions. Margret's date functions were compiled by @Theera in B4XStringFunctionVB.bas file. Notice that every Margret's function output can be reproduced by B4X dates functions with one line of code using Datetime and/or DateUtils. If you improve on it and expand it, please share with the community.
 

Attachments

  • ComparingMargretToB4XDateFunctions.zip
    13.9 KB · Views: 138
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I retrieved all 12 date functions you have in the B4XStringFunctionVB. bas file you posted in post #1 and created a B4XPages project with them. They all ran well. I also created the equivalent of those functions using only Datetime and/or DateUtils to compare the two methods. Each of the methods I used has only one line of code. The comparison was also good. I concluded that you really do not need Margret’s functions for any of those date functions. If you are interested I can post the B4XPages project.
As an example your code is:
B4X:
Log(CurrentWeek( "01/31/2019"))   'Theera
B4X:
Sub CurrentWeek (MyDate As String) As Int
    Private Ticks As Long = DateTime.DateParse( MyDate)
    Private df As String = DateTime.DateFormat
    DateTime.DateFormat = "w"
    Private res As String = DateTime.date( Ticks)
    DateTime.DateFormat = df
    Return res    'as int
End Sub
Below is the equivalent code I wrote which yields the same result is:
B4X:
Log(DateTime.GetDayOfWeek(DateTime.dateparse("01/31/2019")))   'Mahares


But with all that above if I only use this function 3 times in a year which function will I remember?

B4X:
Log(DateTime.GetDayOfWeek(DateTime.dateparse("01/31/2019"))) 'Mahares

Yes, I know what it does but re writing it, thinking about it? Looking at it again 2 years later and wondering what it does?
And the new guy on looking over your code?

How about:
B4X:
Sub CurrentWeek (MyDate As String) As Int
return (DateTime.GetDayOfWeek(DateTime.dateparse(MyDate)))
End Sub

If you post your code on GitHub what is more readable?
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I agree with BlueVision.
B4X developers should familiarise with using Substring function. The function is not difficult to use.

Difficult to use for who? What is your target audience? Your a professional programmer.
What if I am the guy who learned BASIC in University 30 years ago and just want to play on a weekend?
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Hi all again,
I have just get Magret's stringfunction2 sourcecode. I think B4X should be easy for the beginner or non-expert about manage string.
After I have learned from the experts. I have tried converting Magret's stringfunction2 sourcecode to be supported B4X. I attached the files for the experts help me check it correctly.
If it has mistake,please help me coding. The credits is still be Magret. I love her library.

Best Regards
Theera

I would rename it B4XClassicStrFunctions
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I would rename it B4XClassicStrFunctions
It still be B4XStringfFunctionVB because it is refered to VB6.0. Thank you for replies. I don't need to have cantrasting between B4X members.
Mahares is one of the experts who is my idol.
 
Last edited:
Upvote 0
Top