About Invalid Double?

Theera

Well-Known Member
Licensed User
Longtime User
Hi all,
I have problem my source code after ran my widget.
B4X:
Sub BtnSearch_click
   'if Questions.get(i) is checked will shown Answer.get(i)
   Dim i, row As Int
   Dim lstQ, lstA As List
   Dim Amt As Double
   Amt = 0

   lstQ.Initialize
   lstA.Initialize
   
   Log(CurrentPage)
   lstQ = Questions.Get(CurrentPage)
   lstA = Answers.Get(CurrentPage)
   Log(lstQ.Size)
   pnlAnswers.Visible = True
   pnlAnswers.BringToFront
   
   lblPlant.Text = Plants.Get(CurrentPage)
   
   Dim pnl As Panel
   pnl = container.GetPageObject(CurrentPage)
   Dim scv As ScrollView
   scv = pnl.GetView(0)
   Log(scv.Panel.NumberOfViews)
   Dim i As Int
   Dim txt As String
   txt = ""
   ' added Step 4 because you have 4 views per row
   ' so should check only every 4th view
   For i = 0 To scv.Panel.NumberOfViews - 1 Step 4
      row = i / 4
      Dim chk As CheckBox
      chk = scv.Panel.GetView(i)
      If chk.Checked = True Then
         If txt <> "" Then
            txt = txt & CRLF & CRLF
         End If
         ' answer in one line
'         txt = txt & CRLF & CRLF & lstQ.Get(row) & CRLF & "    " & lstA.Get(row) 
         ' answers in x lines
         txt = txt & lstQ.Get(row)
         Dim str() As String
         str = Regex.Split("\+", lstA.Get(row))
         Dim j As Int
         For j = 0 To str.Length - 1
            txt = txt & CRLF & "    " & str(j)
         Next
         Dim Val1, Val2, Total As Double    
         Total = 0
         Dim edt As EditText
            edt = scv.Panel.GetView(chk.Tag * 4 + 1) ' the view with index 1 is the EditText
            Val2 = edt.Text
         Dim z As Int   
         For z = 0 To str.Length-1
            Dim TargerStr() As String
            TargerStr = Regex.Split(" ", str(z))
            If IsNumber(TargerStr(1)) = True Then
               Val1 = TargerStr(1)   ' checks if the number is in TargerStr(1)
            Else 
               Val1 = TargerStr(2)   ' or in TargerStr(2)
            End If   
            Total =Total + (Val1 * Val2)
         Next   
         txt = txt & CRLF & "    "&"ซื้อจำนวน"&" "&edt.Text&"  ชุด"
         txt = txt & CRLF & "    "&"ยอดเงิน:"&" "&NumberFormat(Total,0,2) &" บาท"
         Amt = Amt + Total
      End If
   Next
    AccuTxtAnswers=AccuTxtAnswers & CRLF & CRLF & txt
   GrandTotal=GrandTotal+Amt
   txt = txt & CRLF &"ยอดเงินรวม:"&" "&NumberFormat(Amt,0,2) &" บาท"
   lblAnswers.Text = txt
   Dim h As Int
   h = stu.MeasureMultilineTextHeight(lblAnswers, txt)
   lblAnswers.Height = h
   scvAnswers.Panel.Height = h
   DoEvents
End Sub

Please help me looking for the problem which is belows

Best Regards
Theera
 
Last edited:

JonPM

Well-Known Member
Licensed User
Longtime User
It looks like your problem might be from Val2. If the user doesn't enter a Double in edt, then the error is with Val2.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Error is occurred after I changed the db

Hi all,
Please look at the "Capture" picture belows,I selected only the blue rectange (only line 1-6). The red circle could to be val1. The line 2 is used for "Test1" picture which has error.The line 3 is used for "Test2" picture which has the same error and the line 4 is used for "Test3" picture which has not error. (In picture Test1-3 ,the number could be val 2)

P.S. the line 4 and line 5 are not have error because they have only one "+".
if my English make you terrible,please give me up.

Best Regards
Theera
 
Last edited:
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Still not work?

Hi all,
Here is my sourcecode.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem is in your inconsistent data.
You have blank characters where there shouldn't be one and on other places multiple blank characters !?

Example: one blank character at the beginning and three blank character in the middle (I replaced the blank character by a dot).
.แซม(100-130ซีซี)...380.บาท

You are splitting on " " and get
TargerStr(0) = ""
TargerStr(1) = "แซม(100-130ซีซี)"
TargerStr(2) = ""
TargerStr(3) = ""
TargerStr(4) = "380"
TargerStr(5) = "บาท"

You must either clean up your data ot modify the splitting function!

You should learn to debug your programs:
- Run the IDE in Debug mode.
- When an error appears the program stops and shows the wrong line in yellow.
- Hovering above variables you'll see their content.
- In your cas the program stops in the line 492
- Put the cursor on TargerStr(1) and click on it and you will see the image below
15022d1355493636-about-invalid-double-variablecontent.jpg


and see the content I have shown above.

Best regards.
 

Attachments

  • VariableContent.jpg
    VariableContent.jpg
    48.8 KB · Views: 345
Last edited:
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Hi Klaus,
Many thanks for debug technique. I have never used it before because I don't know debug mode and release mode are different? Now I will read your guide,I think surely,must have. Thank you again everything ,you help me.


Best Regards
Theera :)
 
Last edited:
Upvote 0
Top