Android Question How can I use List in SmartString Literal

JNG

Member
Licensed User
Hi !

I wanted to display the values use smart string literal.

Simple variable display is possible
B4X:
 Dim item_quantity As Int
   Dim item_price As Double
   Dim subtotal As Double
   Dim total As String
   item_quantity = 5
   item_price = 3.5
   subtotal = item_quantity*item_price
   total = $"${item_quantity} x $1.2{item_price} = $1.2{subtotal}"$
   Log(total)

Now I wanted to pick the values either from list or string

B4X:
 Dim item_quantity() As Int
    Dim item_price() As Double
 
 
    item_quantity = Array As Int(2,3,6,8)
    item_price =  Array As Double(3.5,5.1,2.2,1.5)
    Dim total(item_price.length) As String
    Dim subtotal(item_price.length) As Double
    For i = 0 To item_quantity.length - 1
        subtotal(i) = item_quantity(i)*item_price(i)
        total(i) = $"${item_quantity(i)} x $1.2{item_price(i)} = $1.2{subtotal(i)}"$  ------Here I can I Do it
    Next

Basically I wanted to use it in creating HTML.

regards
jng
 

Mahares

Expert
Licensed User
Longtime User
Is this what you are after:
B4X:
Dim item_quantity() As Int
    Dim item_price() As Double
    item_quantity = Array As Int(2,3,6,8)
    item_price =  Array As Double(3.5,5.1,2.2,1.5)
    Dim total(item_price.length) As String
    Dim subtotal(item_price.length) As Double
    For i = 0 To item_quantity.length - 1
        For j=0 To item_price.Length-1
            subtotal(j) = item_quantity(i)*item_price(j)
            total(i) = $"${item_quantity(i)} x $1.2{item_price(j)} = $1.2{subtotal(j)}"$  
            Log(total(i))
        Next
    Next
The log will show:
2 x 3.5 = 7
2 x 5.1 = 10.2
2 x 2.2 = 4.4
2 x 1.5 = 3
3 x 3.5 = 10.5
3 x 5.1 = 15.3
3 x 2.2 = 6.6
3 x 1.5 = 4.5
6 x 3.5 = 21
6 x 5.1 = 30.6
6 x 2.2 = 13.2
6 x 1.5 = 9
8 x 3.5 = 28
8 x 5.1 = 40.8
8 x 2.2 = 17.6
8 x 1.5 = 12
 
Upvote 0
Top