Worked yesterday today it doesn't

CD Tom

Member
Licensed User
Longtime User
I just don't understand B4a anymore. Yesterday the program worked fine today it doesn't.
Here's what's happening.
I have a folder with photos they are numbered 00001.jpg on up to 10155.jpg this number are that same as my members number 00001 matches the jpg for the photo.
The data is loaded without the leading zeros my member number is 08142 is loads as 8142 I do a file.exists to see if there is a photo in the photo folder and if no photo exists I display a noimage.jpg.
Today when I do the file.exists on my number 8142 it doesn't find the photo. In the photo folder the photo is 01842.jpg. Yesterday I didn't need the leading zero today it seems to have to have the leading zero. I guess what I'm going to have to do is check the length of the Id and if it's four or less add leading zeros. If that can be done. Or can someone tell me why I'm having this problem.
If I do a search in the photo folder the search doesn't need leading zeros to find the photo I search 8142.jpg and it's there.
In testing my app in the file.exists command I've put the actual number in 8142.jpg and it didn't find the photo when I entered it as 08142.jpg it did find it. That was how I determined the I now needed leading zeros.
If I had hair I'd be pulling it out.
 

CD Tom

Member
Licensed User
Longtime User
Ok by checking the length of the members number and adding a 0 or multiple 0's to the from of the members number I'm able to get the photo to come up. I guess I don't understand why I didn't need to do this before.
If someone can explain this I would appreciate it.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Before pulling out hair, please check how you declare the members' IDs. Seems to me, you defined them as strings when you prepaired the images, but then you get them as integers when you lookup. If you could show us the subs of image creation and lookup, I am quite sure the solution will be found :)
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Ok here's the code where I lookup the member and try and find the photo.
the member number is located in mbr_prox, in the table mbr_prox is a string field.
B4X:
Sub sv_ItemClick(Value As String)
   Dim id As String
   Dim idc As String
   Dim zero As String
   Dim VYes As String
   Dim m As Map
   Dim Val() As String
   VYes = "Yes"
   LblFName.Visible = True
   lblDJoined.Visible = True
   lblbdate.Visible = True
   lblassoc.Visible = True
   lblpaid.Visible = True
   imgview.Visible = True
   lblsign.Visible = True
   btnAssoc.Visible = True
   btnFLName.Visible = True
   lblEmail.Visible = True
   lblsign.Visible = True
   lblrel.Visible = True
   btnAssoc.Visible = True
   Val = Regex.Split(",", Value)
   m = DBUtils.ExecuteMap(SQL1, "SELECT mbr_first_name, mbr_last_name, address_1, city, state, zip_code, e_mail, home_phone, datej, description, birthd, duesp, assc_last_name, assc_first_name, mbr_prox, assoc_prox, reldate, ActCert FROM mbrsdata where mbr_prox = ?", Array As String(Val(0)))
   If m.IsInitialized = True Then
      id = m.Get("mbr_prox") ' load mbr number into id
      idc = m.Get("actcert") ' check for range certified
      If idc = VYes Then
         imgCert.Visible = True
         picture = LoadBitmap(File.DirRootExternal,"mbrsphotos/Rangecert.jpg")
         imgCert.SetBackgroundImage(picture) ' this will set picture
      End If
      If idc = "No " Then
         imgCert.Visible = False
      End If
      If File.Exists(File.DirRootExternal,"mbrsphotos/"&id&".jpg") = True Then   
         picture = LoadBitmap(File.DirRootExternal,"mbrsphotos/"&id&".jpg") 'this will load picture 
         imgview.SetBackgroundImage(picture) 'this will set picture
      Else
         picture = LoadBitmap(File.DirRootExternal,"mbrsphotos/Noimages.jpg")
         imgview.SetBackgroundImage(picture)
      End If
      btnFLName.Text = m.Get("mbr_first_name") & "   " & m.Get("mbr_last_name")
      lblAddress.Text = m.Get("address_1")
      lblCSZ.Text = m.Get("city") & ", " & m.Get("state") & " " & m.Get("zip_code")
      lblPhone.Text = m.Get("home_phone")
      lblStatus.Text = m.Get("description")
      lblEmail.Text = m.Get("e_mail")
      lblJoined.Text = m.Get("datej")
      lblBirth.text = m.Get("birthd")
      lblduespaid.Text = m.Get("duesp")
      btnAssoc.Text = m.Get("assc_first_name") & "  " & m.Get("assc_last_name")
      lblrel.Text = m.Get("reldate")
   End If
   If File.Exists(File.DirRootExternal,"/mbrsnotes/"&id&".txt") = True Then
      btnNotes.Text = "Read Notes"
   Else
      btnNotes.Text = "Add notes"
   End If
End Sub
This is the code that should display the photo when it reads the file.exists statement it is false and loads the noimages.jpg.
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
not sure what you mean by spinner but here's the code that loads the table.
B4X:
Sub CreateTables
   SQL1.ExecNonQuery("DROP TABLE IF EXISTS mbrsdata")
   SQL1.ExecNonQuery("CREATE TABLE mbrsdata (mbr_prox TEXT, mbr_first_name TEXT, mbr_last_name TEXT, address_1 TEXT, city TEXT, state TEXT, zip_code TEXT, e_mail TEXT, home_phone TEXT, datej TEXT, description TEXT, assc_last_name TEXT, assc_first_name TEXT, birthd TEXT, duesp Text, mbr_number TEXT, assoc_prox Text, reldate text, ActCert Text)")
End Sub

Sub btnupdate_click
   Dim su As StringUtils
   Dim table As List
   Dim table2 As List
   Dim table3 As List
   Dim items() As String
   Dim items1() As String
   Dim myzip As String
   Dim Answ As Int
   Dim m As Map
   Dim i As Int
   Dim j As Int
   Dim k As Map
   ProgressDialogShow2("Loading Members...", False)
   If File.Exists(File.DirRootExternal,"mbrsnotes/*.*") = False Then
      File.MakeDir(File.DirRootExternal,"mbrsnotes")
   End If
   If File.Exists(File.DirRootExternal,"download/appexport.zip") = True Then
      If File.Exists(File.DirRootExternal,"mbrsphotos/*.*") = False Then
         File.MakeDir(File.DirRootExternal,"mbrsphotos")
      End If
      Arc.UnZip(File.DirRootExternal, "download/AppExport.zip", File.DirRootExternal & "/mbrsphotos","")
      File.Delete(File.DirRootExternal, "download/appexport.zip")
      File.Copy(File.DirRootExternal, "mbrsphotos/NewMBRS.csv", File.dirDefaultExternal, "NewMBRS.csv")
      File.Delete(File.DirRootExternal, "mbrshotos/NewMBRS.csv")
   End If
   If File.Exists(File.DirRootExternal,"download/NewMBRS.csv") = True Then
      File.Copy(File.DirRootExternal,"download/NewMBRS.csv",File.DirDefaultExternal, "NewMBRS.csv")

      File.Delete(File.DirRootExternal, "download/NewMBRS.csv")
   'Else
   '   Msgbox("No new data file available","Membership")
   End If
   mbrdata = SQL1.ExecQuerySingleResult("Select count(*) from mbrsdata")
   If mbrdata > 1 Then
      'Answ = Msgbox2("Overwrite?", "Load new members? If select YES if no new data the old members will be loaded.", "Yes", "", "", Null)
      'If Answ = DialogResponse.POSITIVE Then
         Try
            SQL1.ExecNonQuery("Delete from mbrsdata") ' clear the members table
         Catch
         End Try
            table = su.LoadCSV(File.DirDefaultExternal, "NewMBRS.csv", ", ")
            table2.Initialize
            For i = 0 To table.Size - 1
               items = table.Get(i)
               'items1 = MbrsList.Get(i)
                  m.Initialize
                  m.Put("mbr_prox", items(0))
                  m.Put("mbr_first_name", items(1))
                  m.Put("mbr_last_name", items(2))
                  m.Put("address_1", items(3))
                  m.Put("city", items(4))
                  m.Put("state", items(5))
                  m.Put("zip_code", items(6))
                  m.Put("e_mail", items(7))
                  m.Put("home_phone", items(8))
                  m.Put("datej", items(9))
                  m.Put("description", items(10))
                  m.Put("assc_last_name", items(11))
                  m.Put("assc_first_name", items(12))
                  m.Put("birthd", items(13))
                  m.Put("duesp", items(14))
                  m.Put("mbr_prox", items(15))
                  m.Put("assoc_prox", items(16))
                  m.Put("reldate", items(17))
                  m.Put("ActCert", items(18))
                  table2.Add(m)
            Next
            DBUtils.InsertMaps(SQL1, "mbrsdata", table2)

            Msgbox("Overwritten","")
      'Else
      '   Return
      'End If
   Else
      table = su.LoadCSV(File.DirDefaultExternal, "NewMBRS.csv", ", ")
      table2.Initialize
       For i = 1 To table.Size -1
               items = table.Get(i)
               'items1 = MbrsList.Get(i)
                  m.Initialize
                  k.Initialize
                  m.Put("mbr_prox", items(0))
                  m.Put("mbr_first_name", items(1))
                  m.Put("mbr_last_name", items(2))
                  m.Put("address_1", items(3))
                  m.Put("city", items(4))
                  m.Put("state", items(5))
                  m.Put("zip_code", items(6))
                  m.Put("e_mail", items(7))
                  m.Put("home_phone", items(8))
                  m.Put("datej", items(9))
                  m.Put("description", items(10))
                  m.Put("assc_last_name", items(11))
                  m.Put("assc_first_name", items(12))
                  m.Put("birthd", items(13))
                  m.Put("duesp", items(14))
                  m.Put("mbr_prox", items(15))
                  m.Put("assoc_prox", items(16))
                  m.Put("reldate", items(17))
                  m.Put("ActCert", items(18))
                  table2.Add(m)
            Next
       DBUtils.InsertMaps(SQL1, "mbrsdata", table2)
   End If
   members.Initialize
   Dim cursor1 As Cursor
   Dim Vmlname As String
   Dim Vmfname As String
   Dim vmnumber As String
   Dim VList As String
   cursor1 = SQL1.ExecQuery("Select mbr_prox, mbr_last_name, mbr_first_name from mbrsdata")
   Dim Rcount As Int
   
   For i = 0 To cursor1.RowCount -1
      cursor1.Position = i
      Vmlname = cursor1.GetString("mbr_last_name")
      Vmfname = cursor1.GetString("mbr_first_name")
      vmnumber = cursor1.GetString("mbr_prox")
      VList = (vmnumber & ", " & Vmlname & ", " & Vmfname)
      members.Add(VList)
   Next
   cursor1.Close
   ProgressDialogHide      
End Sub
I'm putting the mbr_prox into two places trying to figure out what was happening.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Unfortunately I'm not in front of a pc with b4a right now, but can you do me a favor?
From inside the last sub, please
B4X:
log(items(15)):log(items(0))
and see if the leading zeros appear. I also noticed you entered a space in your loadCSV
B4X:
", "
. Why not simply
B4X:
","
?
Another thing is how your csv is really constructed. Can you see in it, the column containing the imageFile name, with leading zeros?
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
the csv file doesn't contain leading zeros. This didn't seem to matter yesterday. Both item 15 and 0 don't have leading zeros. Changing the ", " did matter anyway. I do have this working by putting a leading 0 in front of the Id and I can live with that, I just don't understand why it was working yesterday without leading zeros and today it isn't.
The csv file I'm using is the same one I've been using for the last few days and it has never had leading zeros.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
the csv file doesn't contain leading zeros. This didn't seem to matter yesterday. Both item 15 and 0 don't have leading zeros. Changing the ", " did matter anyway. I do have this working by putting a leading 0 in front of the Id and I can live with that, I just don't understand why it was working yesterday without leading zeros and today it isn't.
The csv file I'm using is the same one I've been using for the last few days and it has never had leading zeros.
I had a copy of an old csv file you uploaded. I checked it, and it contained the leading zeros. Perhaps in a later version, you had these columns (perhaps the program) interpreted to integers (quite luckily),thus the exported csv had no leading zeros. The important is that the issue seems to be solved :)
 
Upvote 0
Top