B4J Question Is it possible to split a line of code?

ranul

Member
Licensed User
Longtime User
Hi,

If I have a long line of code, like that:

B4X:
dim sts as int

sts = MyFunction("text1", "text2", "text3", "text4", "text5", "text6")

Is there a way to split the line like that:

B4X:
dim sts as int

sts = MyFunction("text1",
                "text2",
                "text3",
                "text4",
                "text5",
                "text6")

Thanks
 
Solution
Hi,

If I have a long line of code, like that:

B4X:
dim sts as int

sts = MyFunction("text1", "text2", "text3", "text4", "text5", "text6")

Is there a way to split the line like that:

B4X:
dim sts as int

sts = MyFunction("text1",
                "text2",
                "text3",
                "text4",
                "text5",
                "text6")

Thanks


B4X:
sts = MyFunction("text1", _
    "text2", _
    "text3", _
    "text4", _
    "text5", _
    "text6")

behnam_tr

Active Member
Licensed User
Longtime User
Hi,

If I have a long line of code, like that:

B4X:
dim sts as int

sts = MyFunction("text1", "text2", "text3", "text4", "text5", "text6")

Is there a way to split the line like that:

B4X:
dim sts as int

sts = MyFunction("text1",
                "text2",
                "text3",
                "text4",
                "text5",
                "text6")

Thanks


B4X:
sts = MyFunction("text1", _
    "text2", _
    "text3", _
    "text4", _
    "text5", _
    "text6")
 
Upvote 2
Solution

emexes

Expert
Licensed User
Is there a way to split the line

A longer example is the TestData at:

B4X:
Sub AppStart (Args() As String)

    ' https://x.com/i/grok/share/9oPOa9H4oWNt6arRshgetbXF7
   
    Dim TestData() As String = Array As String( _
        "English", "Thai", _
        "Afghanistan", "อัฟกานิสถาน", _
        "Albania", "แอลเบเนีย", _
        "Algeria", "แอลจีเรีย", _
        "Andorra", "อันดอร์รา", _
        "Angola", "แองโกลา", _
        "Antigua and Barbuda", "แอนทิกาและบาร์บูดา", _
        "Argentina", "อาร์เจนตินา", _
        "Armenia", "อาร์มีเนีย", _
        "Australia", "ออสเตรเลีย", _
        "Austria", "ออสเตรีย", _
        "Azerbaijan", "อาเซอร์ไบจาน", _
        "Bahamas", "บาฮามาส", _
        "Bahrain", "บาห์เรน", _
        "Bangladesh", "บังกลาเทศ", _
        "Barbados", "บาร์เบโดส", _
        "Belarus", "เบลารุส", _
        "Belgium", "เบลเยียม", _
        "Belize", "เบลีซ", _
        "Benin", "เบนิน", _
        "Bhutan", "ภูฏาน", _
        "Bolivia", "โบลิเวีย", _
        "Bosnia and Herzegovina", "บอสเนียและเฮอร์เซโกวีนา", _
        "Botswana", "บอตสวานา", _
        "Brazil", "บราซิล", _
        "Brunei", "บรูไน", _
        "Bulgaria", "บัลแกเรีย", _
        "Burkina Faso", "บูร์กินาฟาโซ", _
        "Burundi", "บุรุนดี", _
        "Cabo Verde", "กาบูเวร์ดี", _
        "Cambodia", "กัมพูชา", _
        "Cameroon", "แคเมอรูน", _
        "Canada", "แคนาดา", _
        "Central African Republic", "สาธารณรัฐแอฟริกากลาง", _
        "Chad", "ชาด", _
        "Chile", "ชิลี", _
        "China", "จีน", _
        "Colombia", "โคลัมเบีย", _
        "Comoros", "คอโมโรส", _
        "Congo (Democratic Republic of the)", "สาธารณรัฐประชาธิปไตยคองโก", _
        "Congo (Republic of the)", "สาธารณรัฐคองโก", _
        "Costa Rica", "คอสตาริกา", _
        "Côte d'Ivoire", "โกตดิวัวร์", _
        "Croatia", "โครเอเชีย", _
        "Cuba", "คิวบา", _
        "Cyprus", "ไซปรัส", _
        "Czech Republic", "สาธารณรัฐเช็ก", _
        "Denmark", "เดนมาร์ก", _
        "Djibouti", "จิบูตี", _
        "Dominica", "โดมินีกา", _
        "Dominican Republic", "สาธารณรัฐโดมินิกัน", _
        "Ecuador", "เอกวาดอร์", _
        "Egypt", "อียิปต์", _
        "El Salvador", "เอลซัลวาดอร์", _
        "Equatorial Guinea", "อิเควทอเรียลกินี", _
        "Eritrea", "เอริเทรีย", _
        "Estonia", "เอสโตเนีย", _
        "Eswatini", "เอสวาตีนี", _
        "Ethiopia", "เอธิโอเปีย", _
        "Fiji", "ฟีจิ", _
        "Finland", "ฟินแลนด์", _
        "France", "ฝรั่งเศส", _
        "Gabon", "กาบอง", _
        "Gambia", "แกมเบีย", _
        "Georgia", "จอร์เจีย", _
        "Germany", "เยอรมนี", _
        "Ghana", "กานา", _
        "Greece", "กรีซ", _
        "Grenada", "เกรเนดา", _
        "Guatemala", "กัวเตมาลา", _
        "Guinea", "กินี", _
        "Guinea-Bissau", "กินี-บิสเซา", _
        "Guyana", "กายอานา", _
        "Haiti", "เฮติ", _
        "Honduras", "ฮอนดูรัส", _
        "Hungary", "ฮังการี", _
        "Iceland", "ไอซ์แลนด์", _
        "India", "อินเดีย", _
        "Indonesia", "อินโดนีเซีย", _
        "Iran", "อิหร่าน", _
        "Iraq", "อิรัก", _
        "Ireland", "ไอร์แลนด์", _
        "Israel", "อิสราเอล", _
        "Italy", "อิตาลี", _
        "Jamaica", "จาเมกา", _
        "Japan", "ญี่ปุ่น", _
        "Jordan", "จอร์แดน", _
        "Kazakhstan", "คาซัคสถาน", _
        "Kenya", "เคนยา", _
        "Kiribati", "คิริบาส", _
        "Korea (North)", "เกาหลีเหนือ", _
        "Korea (South)", "เกาหลีใต้", _
        "Kosovo", "โคโซโว", _
        "Kuwait", "คูเวต", _
        "Kyrgyzstan", "คีร์กีซสถาน", _
        "Laos", "ลาว", _
        "Latvia", "ลัตเวีย", _
        "Lebanon", "เลบานอน", _
        "Lesotho", "เลโซโท", _
        "Liberia", "ไลบีเรีย", _
        "Libya", "ลิเบีย", _
        "Liechtenstein", "ลิกเตนสไตน์", _
        "Lithuania", "ลิทัวเนีย", _
        "Luxembourg", "ลักเซมเบิร์ก", _
        "Madagascar", "มาดากัสการ์", _
        "Malawi", "มาลาวี", _
        "Malaysia", "มาเลเซีย", _
        "Maldives", "มัลดีฟส์", _
        "Mali", "มาลี", _
        "Malta", "มอลตา", _
        "Marshall Islands", "หมู่เกาะมาร์แชลล์", _
        "Mauritania", "มอริเตเนีย", _
        "Mauritius", "มอริเชียส", _
        "Mexico", "เม็กซิโก", _
        "Micronesia", "ไมโครนีเชีย", _
        "Moldova", "มอลโดวา", _
        "Monaco", "โมนาโก", _
        "Mongolia", "มองโกเลีย", _
        "Montenegro", "มอนเตเนโกร", _
        "Morocco", "โมร็อกโก", _
        "Mozambique", "โมซัมบิก", _
        "Myanmar", "พม่า", _
        "Namibia", "นามิเบีย", _
        "Nauru", "นาอูรู", _
        "Nepal", "เนปาล", _
        "Netherlands", "เนเธอร์แลนด์", _
        "New Zealand", "นิวซีแลนด์", _
        "Nicaragua", "นิการากัว", _
        "Niger", "ไนเจอร์", _
        "Nigeria", "ไนจีเรีย", _
        "North Macedonia", "มาซิโดเนียเหนือ", _
        "Norway", "นอร์เวย์", _
        "Oman", "โอมาน", _
        "Pakistan", "ปากีสถาน", _
        "Palau", "ปาเลา", _
        "Panama", "ปานามา", _
        "Papua New Guinea", "ปาปัวนิวกินี", _
        "Paraguay", "ปารากวัย", _
        "Peru", "เปรู", _
        "Philippines", "ฟิลิปปินส์", _
        "Poland", "โปแลนด์", _
        "Portugal", "โปรตุเกส", _
        "Qatar", "กาตาร์", _
        "Romania", "โรมาเนีย", _
        "Russia", "รัสเซีย", _
        "Rwanda", "รวันดา", _
        "Saint Kitts and Nevis", "เซนต์คิตส์และเนวิส", _
        "Saint Lucia", "เซนต์ลูเชีย", _
        "Saint Vincent and the Grenadines", "เซนต์วินเซนต์และเกรนาดีนส์", _
        "Samoa", "ซามัว", _
        "San Marino", "ซานมารีโน", _
        "São Tomé and Príncipe", "เซาตูเมและปรินซีปี", _
        "Saudi Arabia", "ซาอุดีอาระเบีย", _
        "Senegal", "เซเนกัล", _
        "Serbia", "เซอร์เบีย", _
        "Seychelles", "เซเชลส์", _
        "Sierra Leone", "เซียร์ราลีโอน", _
        "Singapore", "สิงคโปร์", _
        "Slovakia", "สโลวาเกีย", _
        "Slovenia", "สโลวีเนีย", _
        "Solomon Islands", "หมู่เกาะโซโลมอน", _
        "Somalia", "โซมาเลีย", _
        "South Africa", "แอฟริกาใต้", _
        "South Sudan", "ซูดานใต้", _
        "Spain", "สเปน", _
        "Sri Lanka", "ศรีลังกา", _
        "Sudan", "ซูดาน", _
        "Suriname", "ซูรินาม", _
        "Sweden", "สวีเดน", _
        "Switzerland", "สวิตเซอร์แลนด์", _
        "Syria", "ซีเรีย", _
        "Tajikistan", "ทาจิกิสถาน", _
        "Tanzania", "แทนซาเนีย", _
        "Thailand", "ไทย", _
        "Timor-Leste", "ติมอร์-เลสเต", _
        "Togo", "โตโก", _
        "Tonga", "ตองงา", _
        "Trinidad and Tobago", "ตรินิแดดและโตเบโก", _
        "Tunisia", "ตูนิเซีย", _
        "Turkey", "ตุรกี", _
        "Turkmenistan", "เติร์กเมนิสถาน", _
        "Tuvalu", "ตูวาลู", _
        "Uganda", "ยูกันดา", _
        "Ukraine", "ยูเครน", _
        "United Arab Emirates", "สหรัฐอาหรับเอมิเรตส์", _
        "United Kingdom", "สหราชอาณาจักร", _
        "United States", "สหรัฐอเมริกา", _
        "Uruguay", "อุรุกวัย", _
        "Uzbekistan", "อุซเบกิสถาน", _
        "Vanuatu", "วานูอาตู", _
        "Vatican City", "นครวาติกัน", _
        "Venezuela", "เวเนซุเอลา", _
        "Vietnam", "เวียดนาม", _
        "Yemen", "เยเมน", _
        "Zambia", "แซมเบีย", _
        "Zimbabwe", "ซิมบับเว" _
    )  
   
    Dim MyList As List
    MyList.Initialize

    For I = 2 To TestData.Length - 1 Step 2
        Dim FourStrings As FourStringsType
        FourStrings.Original = NumberFormat(I / 2, 2, 0)
        FourStrings.English = TestData(I)
        FourStrings.Thai = TestData(I + 1)
        FourStrings.ThaiSortCode = GetThaiComparisonString(FourStrings.Thai)
        MyList.Add(FourStrings)
    Next

    MyList.SortType("ThaiSortCode", True)
   
    Dim LineSeparator As String = CRLF

    Dim sb As StringBuilder
    sb.Initialize
   
    sb.Append("INSERT INTO dt_Country (name, sortnumber, english) VALUES ")

    For I = 0 To MyList.Size - 1
        If I <> 0 Then sb.Append(", ")
        sb.Append(LineSeparator)
       
        Dim FS As FourStringsType = MyList.Get(I)
       
        sb.Append("(")
        sb.Append("'" & FS.Thai & "'")
        sb.Append(", ")
        sb.Append(I + 1)
        sb.Append(", ")
        sb.Append("'" & FS.English & "'")
        sb.Append(")")
    Next

    sb.Append(";")
   
    Log(sb.ToString)

End Sub
 
Upvote 0

emexes

Expert
Licensed User
B4X:
dim sts as int

sts = MyFunction("text1",
                 "text2",
                 "text3",
                 "text4",
                 "text5",
                 "text6")

On a related note: another way to pass lots of parameters, is as an array.
Has the advantage of enabling variable number of parameters, eg sometimes 12, othertimes 6, eg:

B4X:
Dim sts12 As Int = MyFunction( Array As String("text1", "text2", "text3", "text4", "text5", "text6", "text7", "text8", "text9", "text10", "text11", "text12") )
Dim sts6 As Int = MyFunction( Array As String("texti", "textii", "textiii", "textiv", "textv", "textvi") )

which you can also split across lines eg:

B4X:
Dim sts7 AS Int = MyFunction( Array As String( _
    "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", _
    "Saturday", "Sunday" _
) )
 
Upvote 0
Top