Android Question help! Convert VB.net to b4a

rkxo

Active Member
Licensed User
Longtime User
Hi,

Can someone help me translate this code to b4a .?

VB.net:
 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
       Dim numcount As Integer
    Dim Starttime As DateTime
        Try

            numcount = numcount + 1
                If RadioButton1.Checked = True Then
                    Starttime = New DateTime(Now.Year, Now.Month, Now.Day, 0, 0, 0)
                Else
                Starttime = New DateTime(dateTimePicker2.Value.Year, dateTimePicker2.Value.Month, dateTimePicker2.Value.Day, dateTimePicker2.Value.Hour, dateTimePicker2.Value.Minute, dateTimePicker2.Value.Second)
            End If
                Starttime = Starttime.AddSeconds(NumericUpDown2.Value)
                Dim ref As New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour, Now.Minute, Now.Second)
                ref = ref.AddSeconds(NumericUpDown3.Value)
                Dim final As TimeSpan = ref - Starttime

                Dim Resto As Double = final.TotalSeconds Mod numericUpDown1.Value
                label1.Text = Resto
                Label2.Text = ref.Second

        Catch ex As Exception

        End Try




    End Sub

i tried but nope it just worked


B4X:
Private Sub Timer1_Tick
    Try

        numcount = numcount + 1

    Starttime =  DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), 0, 0, 0)

   
   
        Dim ref As Long =DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), DateTime.GetHour(DateTime.Now), DateTime.GetMinute(DateTime.Now), DateTime.GetSecond(DateTime.Now))
        ref = ref + MaskedEditText2.text.Replace("_","")*1000
        Dim final As Long = ref -  Starttime

        Dim Resto As Long = final Mod (MaskedEditText3.text.Replace("_","")*1000)
        Label7.Text = Resto
        Label2.Text =DateTime.GetSecond(ref)

    Catch  As Exception

    End Try

End Sub

thanks for advance
 
Last edited:

rkxo

Active Member
Licensed User
Longtime User
Hi,

Can someone help me translate this code to b4a .?

VB.net:
 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
       Dim numcount As Integer
    Dim Starttime As DateTime
        Try

            numcount = numcount + 1
                If RadioButton1.Checked = True Then
                    Starttime = New DateTime(Now.Year, Now.Month, Now.Day, 0, 0, 0)
                Else
                Starttime = New DateTime(dateTimePicker2.Value.Year, dateTimePicker2.Value.Month, dateTimePicker2.Value.Day, dateTimePicker2.Value.Hour, dateTimePicker2.Value.Minute, dateTimePicker2.Value.Second)
            End If
                Starttime = Starttime.AddSeconds(NumericUpDown2.Value)
                Dim ref As New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour, Now.Minute, Now.Second)
                ref = ref.AddSeconds(NumericUpDown3.Value)
                Dim final As TimeSpan = ref - Starttime

                Dim Resto As Double = final.TotalSeconds Mod numericUpDown1.Value
                label1.Text = Resto
                Label2.Text = ref.Second

        Catch ex As Exception

        End Try




    End Sub

i tried but nope it just worked


B4X:
Private Sub Timer1_Tick
    Try

        numcount = numcount + 1

    Starttime =  DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), 0, 0, 0)

  
  
        Dim ref As Long =DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), DateTime.GetHour(DateTime.Now), DateTime.GetMinute(DateTime.Now), DateTime.GetSecond(DateTime.Now))
        ref = ref + MaskedEditText2.text.Replace("_","")*1000
        Dim final As Long = ref -  Starttime

        Dim Resto As Long = final Mod (MaskedEditText3.text.Replace("_","")*1000)
        Label7.Text = Resto
        Label2.Text =DateTime.GetSecond(ref)

    Catch  As Exception

    End Try

End Sub

thanks for advance
now work ok
B4X:
Private Sub Timer1_Tick
    Try

        numcount = numcount + 1

    Starttime =  DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), 0, 0, 0)

    
        Starttime=Starttime+MaskedEditText2.text.Replace("_","")*1000
        Dim ref As Long =DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), DateTime.GetHour(DateTime.Now), DateTime.GetMinute(DateTime.Now), DateTime.GetSecond(DateTime.Now))
        ref = ref + UpDown1.value*1000
        Dim final As Long = ref -  Starttime

        Dim Resto As Long = final Mod (MaskedEditText3.text.Replace("_","")*1000)
        Dim ty As Int=Resto/1000
        Label7.Text = ty
        Label2.Text =DateTime.GetSecond(ref)

    Catch  As Exception

    End Try

End Sub
 
Upvote 0

emexes

Expert
Licensed User
B4X:
Starttime =  DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), 0, 0, 0)

A random observation is that if this code was executed across midnight across months, then it is possible that the three separate DateTime.Now calls might not all return the same date, and that Starttime might end up being the last day of the next month or the first day of the previous month.

Eg, say that the date is rolling from 31-Jul to 01-Aug, then you could conceivably end up with 31-Aug (wrong by 30 days) or 01-Jul (also wrong by 30 days, and in the wrong direction too, ie time going backwards). It gets even worse across the December-to-January midnight.

I agree that the probability of this happening is small. :rolleyes: But it is also non-zero. ? The fix is simple:

B4X:
Dim TempNow As Long = DateTime.Now    'latch the current date and time so that it doesn't change in the middle of the next calculation
StartTime =  DateUtils.SetDateAndTime(DateTime.GetYear(TempNow), DateTime.GetMonth(TempNow), DateTime.GetDayOfMonth(TempNow), 0, 0, 0)
 
Last edited:
Upvote 0

rkxo

Active Member
Licensed User
Longtime User
A random observation is that if this code was executed across midnight across months, then it is possible that the three separate DateTime.Now calls might not all return the same date, and that Starttime might end up being the last day of the next month or the first day of the previous month.

Eg, say that the date is rolling from 31-Jul to 01-Aug, then you could conceivably end up with 31-Aug (wrong by 30 days) or 01-Jul (also wrong by 30 days, and in the wrong direction too, ie time going backwards). It gets even worse across the December-to-January midnight.

I agree that the probability of this happening is small. :rolleyes: But it is also non-zero. ? The fix is simple:

B4X:
Dim TempNow As Long = DateTime.Now    'latch the current date and time so that it doesn't change in the middle of the next calculation
StartTime =  DateUtils.SetDateAndTime(DateTime.GetYear(TempNow), DateTime.GetMonth(TempNow), DateTime.GetDayOfMonth(TempNow), 0, 0, 0)
ok , thnaks
 
Upvote 0

hassen

New Member
Hi i am 56 years old and still learning B4a .
i accomplished to write an app on vb.net . but would like the same app to run on b4a
can anyone help me to convert it to a B4a app.
would really appreciate with kind
iam really struggling

thank you in advance
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
How great that you want to learn B4A. Erel's advice is to develop a B4X program with B4J because the same source code also works for B4A. The advantage of starting in B4J is that you can first concentrate on the program code and only if this works, make specific adjustments for B4A in the source code.

You already have programming experience in VB. A good starting point is Tutorials & Examples

You could start with [B4X] B4XPages + B4XDrawer as a basis for your program. It contains a slide-out menu and a number of (expandable) subpages on which you can develop your program.

Especially since you already have VB knowledge, you can get off to a flying start with the above tips. Be aware that B4A programs in a Google Android environment must take into account all kinds of conditions and limitations that Google imposes on an Android environment. The forum contains a lot of questions and corresponding answers. It is therefore more convenient to first start in B4J to learn the B4X programming language first and then make any necessary adjustments for B4A to the version tested in B4J.

You can always enter a search query in the upper right corner that will help you find solutions with either only partial source code, or with a complete program. You can also ask a specific question here on the forum with a small source example.

Good luck with your program development.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
i accomplished to write an app on vb.net . but would like the same app to run on b4a.
You need (supposed) to create a new post on the forum explaining what you need help with, you shouldn't hijack an old post.

So start with creating a new post on the forum in the correct section as in B4A, B4J or B4i questions.

Enjoy...
 
Upvote 0
Top