Android Question How to step thru dB and change label?

anOparator

Active Member
Licensed User
Longtime User
' This (in Sub Activity_Create) puts the name of current day on Label5.
B4X:
Dim WeekDaysStr() As String
WeekDaysStr = Array As String ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
Label5.text= WeekDaysStr(DateTime.GetDayOfWeek(DateTime.Now) - 1)
thanks to: http://www.b4x.com/android/forum/threads/getdayofmonth.15104/

B4X:
Sub nex_Click
Dim WeekDaysStr() As String
WeekDaysStr = Array As String ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
' This on nex_Click changes day name on Label5 randomly when used with the Previous_Click button
dadate.text= WeekDaysStr(DateTime.GetDayOfWeek(DateTime.Now) - i)
' This on nex_Click changes day name to a number
' dadate.text= DateTime.GetDayOfWeek(DateTime.Now) - 1
' Edited
The rest of Sub nex_Click using variable i does step through the 3 records in the database using a nex and a previous button..
B4X:
'Log ("B4 If " & (i))
If i <= 1 Then
   i = i + 1  
     End If
  Cursor1 = SQL1.ExecQuery("SELECT * FROM Names")
  Cursor1.Position = i 'example location3  'set the cursor
  EditText1.Text = Cursor1.GetString("First name")  'read the value of the FirstName column
  EditText2.Text = Cursor1.GetString("Name")  'read the value of the LasstName column
  Cursor1.Close
       Log ("AFTER If " & (i))
End Sub

How would I get Label5 to show the day name changes as the dB changes? :bangs head:
 

edgar_ortiz

Active Member
Licensed User
Longtime User
Hi...
I don't understand what do you want to do? :(

In your code:

B4X:
'Log ("B4 If " & (i))
If i <= 1 Then
   i = i + 1 
     End If
  Cursor1 = SQL1.ExecQuery("SELECT * FROM Names")
  Cursor1.Position = i 'example location3  'set the cursor
  EditText1.Text = Cursor1.GetString("First name")  'read the value of the FirstName column
  EditText2.Text = Cursor1.GetString("Name")  'read the value of the LasstName column
  Cursor1.Close
       Log ("AFTER If " & (i))
End Sub

You only access one record (Cursor1.Position = 1)

Regards

Edgar
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
Hi...
I don't understand what do you want to do? :(

In your code:

B4X:
'Log ("B4 If " & (i))
If i <= 1 Then
   i = i + 1
     End If
  Cursor1 = SQL1.ExecQuery("SELECT * FROM Names")
  Cursor1.Position = i 'example location3  'set the cursor
  EditText1.Text = Cursor1.GetString("First name")  'read the value of the FirstName column
  EditText2.Text = Cursor1.GetString("Name")  'read the value of the LasstName column
  Cursor1.Close
       Log ("AFTER If " & (i))
End Sub

You only access one record (Cursor1.Position = 1)

Regards

Edgar
That's '(Cursor1.Position =i) ' , the ninth letter, a variable that gets incremented or decremented to Get the next or previous recordset in a database. That code words, it's Label5 which shows GetDayOfWeek that I want to update as the database does it's Next and Previous things.

thanks in advance
 

Attachments

  • dB with Label Change.zip
    8.7 KB · Views: 133
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
it was programmed to run, I hope it will be useful

Regards,

Edgar
thanks for the pointers , the label updating code is :banghead intense ( to me ) and very helpful.
I'm going to work on merging it into my pre-alpha activity module.

ps: I'm thinking that Timer1 is not needed since I will use DateTime.GetDayOfWeek(DateTime.Now) to get the current day. Yes /No?

B4a is starting to seem like pouring water into a glass , the more I learn and the more water I pour in ~ the larger the glass gets :)
 
Upvote 0
Top