Results 1 to 9 of 9

Thread: Call a function into Textbox Report Viewer

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2022
    Posts
    48

    Call a function into Textbox Report Viewer

    I have a function named NoToTxt converts numbers to words into Arabic language
    I pasted it in the Code place of Report Properties then I tried to call it inside a textbox expression using this code

    Code:
    Code.NoToTxt (Fields!Number.Value)
    but it didn’t work, I don’t know what exactly went wrong
    any help please, I'm using Report Viewer VB 2012

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,440

    Re: Call a function into Textbox Report Viewer

    Can you have the function return its results to a string variable and then use that variable for whatever use you may need? Just a thought.

  3. #3
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Re: Call a function into Textbox Report Viewer

    Hi Talajeen,

    If this is what you did then I don't think it will work:

    Attachment 186763

    What you have to do is to create a Class with your function and then in you textbox expression e.g.
    Code:
    =MyFunctions.NoToTxt(Fields!Number.value)
    where MyFunctions is the name of the class and NoToTxt is the name of the function

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,677

    Re: Call a function into Textbox Report Viewer

    Quote Originally Posted by Tajaldeen View Post
    I have a function named NoToTxt converts numbers to words into Arabic language
    I pasted it in the Code place of Report Properties then I tried to call it inside a textbox expression using this code

    Code:
    Code.NoToTxt (Fields!Number.Value)
    but it didn’t work, I don’t know what exactly went wrong
    any help please, I'm using Report Viewer VB 2012
    What does "it didn't work" mean exactly? Error? Nothing? Garbage? Finger fall off?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Re: Call a function into Textbox Report Viewer

    I realize that it is actually not as straightforward as my example in #3. I'm not sure if the OP will read is - it seems sometimes people post questions and they either don't come back for an answer or "tx" is too much effort.

    I'm going to make a tutorial on this and maybe it can help someone in the future. In 6 years I battled hours and days with RDLC reports it feels like I should have 20 years experience 🙂

  6. #6
    Junior Member
    Join Date
    Feb 2023
    Posts
    20

    Re: Call a function into Textbox Report Viewer

    Quote Originally Posted by schoemr View Post
    Hi Talajeen,

    If this is what you did then I don't think it will work:

    Attachment 186763

    What you have to do is to create a Class with your function and then in you textbox expression e.g.
    Code:
    =MyFunctions.NoToTxt(Fields!Number.value)
    where MyFunctions is the name of the class and NoToTxt is the name of the function
    Hi, its me (Tajaldeen) This is my function , could you please tell me how to include it inside a class , if i could do that i wouldn't be need my parameters, so the iTextSharp will work just fine.
    Code:
    Function NoToTxt(ByVal TheNo As Double, ByVal MyCur As String, ByVal MySubCur As String) As String
            Dim MyArry1(0 To 9) As String
            Dim MyArry2(0 To 9) As String
            Dim MyArry3(0 To 9) As String
            Dim MyNo As String = ""
            Dim GetNo As String = ""
            Dim RdNo As String = ""
            Dim My100 As String = ""
            Dim My10 As String = ""
            Dim My1 As String = ""
            Dim My11 As String = ""
            Dim My12 As String = ""
            Dim GetTxt As String = ""
            Dim Mybillion As String = ""
            Dim MyMillion As String = ""
            Dim MyThou As String = ""
            Dim MyHun As String = ""
            Dim MyFraction As String = ""
            Dim MyAnd As String = ""
            Dim i As Integer
            Dim ReMark As String = ""
    
    
            If TheNo > 999999999999.99 Then
    
            End If
    
    
            If TheNo = 0 Then
                Salem = "صفر"
                Exit Function
            End If
    
            MyAnd = " و"
            MyArry1(0) = ""
            MyArry1(1) = "مائة"
            MyArry1(2) = "مائتان"
            MyArry1(3) = "ثلاثمائة"
            MyArry1(4) = "أربعمائة"
            MyArry1(5) = "خمسمائة"
            MyArry1(6) = "ستمائة"
            MyArry1(7) = "سبعمائة"
            MyArry1(8) = "ثمانمائة"
            MyArry1(9) = "تسعمائة"
    
            MyArry2(0) = ""
            MyArry2(1) = " عشر"
            MyArry2(2) = "عشرون"
            MyArry2(3) = "ثلاثون"
            MyArry2(4) = "أربعون"
            MyArry2(5) = "خمسون"
            MyArry2(6) = "ستون"
            MyArry2(7) = "سبعون"
            MyArry2(8) = "ثمانون"
            MyArry2(9) = "تسعون"
    
            MyArry3(0) = ""
            MyArry3(1) = "واحد"
            MyArry3(2) = "اثنان"
            MyArry3(3) = "ثلاثة"
            MyArry3(4) = "أربعة"
            MyArry3(5) = "خمسة"
            MyArry3(6) = "ستة"
            MyArry3(7) = "سبعة"
            MyArry3(8) = "ثمانية"
            MyArry3(9) = "تسعة"
            '======================
            GetNo = Format(TheNo, "000000000000.00")
    
            i = 0
            Do While i < 15
    
                If i < 12 Then
                    MyNo = Mid$(GetNo, i + 1, 3)
                Else
                    MyNo = "0" + Mid$(GetNo, i + 2, 2)
                End If
    
                If (Mid$(MyNo, 1, 3)) > 0 Then
    
                    RdNo = Mid$(MyNo, 1, 1)
                    My100 = MyArry1(RdNo)
                    RdNo = Mid$(MyNo, 3, 1)
                    My1 = MyArry3(RdNo)
                    RdNo = Mid$(MyNo, 2, 1)
                    My10 = MyArry2(RdNo)
    
                    If Mid$(MyNo, 2, 2) = 11 Then My11 = "إحدى عشر"
                    If Mid$(MyNo, 2, 2) = 12 Then My12 = "إثنى عشر"
                    If Mid$(MyNo, 2, 2) = 10 Then My10 = "عشرة"
    
                    If ((Mid$(MyNo, 1, 1)) > 0) And ((Mid$(MyNo, 2, 2)) > 0) Then My100 = My100 + MyAnd
                    If ((Mid$(MyNo, 3, 1)) > 0) And ((Mid$(MyNo, 2, 1)) > 1) Then My1 = My1 + MyAnd
    
                    GetTxt = My100 + My1 + My10
    
                    If ((Mid$(MyNo, 3, 1)) = 1) And ((Mid$(MyNo, 2, 1)) = 1) Then
                        GetTxt = My100 + My11
                        If ((Mid$(MyNo, 1, 1)) = 0) Then GetTxt = My11
                    End If
    
                    If ((Mid$(MyNo, 3, 1)) = 2) And ((Mid$(MyNo, 2, 1)) = 1) Then
                        GetTxt = My100 + My12
                        If ((Mid$(MyNo, 1, 1)) = 0) Then GetTxt = My12
                    End If
    
                    If (i = 0) And (GetTxt <> "") Then
                        If ((Mid$(MyNo, 1, 3)) > 10) Then
                            Mybillion = GetTxt + " مليار"
                        Else
                            Mybillion = GetTxt + " مليارات"
                            If ((Mid$(MyNo, 1, 3)) = 2) Then Mybillion = " مليار"
                            If ((Mid$(MyNo, 1, 3)) = 2) Then Mybillion = " ملياران"
                        End If
                    End If
    
                    If (i = 3) And (GetTxt <> "") Then
    
                        If ((Mid$(MyNo, 1, 3)) > 10) Then
                            MyMillion = GetTxt + " مليون"
                        Else
                            MyMillion = GetTxt + " ملايين"
                            If ((Mid$(MyNo, 1, 3)) = 1) Then MyMillion = " مليون"
                            If ((Mid$(MyNo, 1, 3)) = 2) Then MyMillion = " مليونان"
                        End If
                    End If
    
                    If (i = 6) And (GetTxt <> "") Then
                        If ((Mid$(MyNo, 1, 3)) > 10) Then
                            MyThou = GetTxt + " ألف"
                        Else
                            MyThou = GetTxt + " آلاف"
                            If ((Mid$(MyNo, 3, 1)) = 1) Then MyThou = " ألف"
                            If ((Mid$(MyNo, 3, 1)) = 2) Then MyThou = " ألفان"
                        End If
                    End If
    
                    If (i = 9) And (GetTxt <> "") Then MyHun = GetTxt
                    If (i = 12) And (GetTxt <> "") Then MyFraction = GetTxt
                End If
    
                i = i + 3
            Loop
    
            If (Mybillion <> "") Then
                If (MyMillion <> "") Or (MyThou <> "") Or (MyHun <> "") Then Mybillion = Mybillion + MyAnd
            End If
    
            If (MyMillion <> "") Then
                If (MyThou <> "") Or (MyHun <> "") Then MyMillion = MyMillion + MyAnd
            End If
    
            If (MyThou <> "") Then
                If (MyHun <> "") Then MyThou = MyThou + MyAnd
            End If
    
            If MyFraction <> "" Then
                If (Mybillion <> "") Or (MyMillion <> "") Or (MyThou <> "") Or (MyHun <> "") Then
                    NoToTxt = ReMark + Mybillion + MyMillion + MyThou + MyHun + " " + MyCur + MyAnd + MyFraction + " " + MySubCur
                Else
                    NoToTxt = ReMark + MyFraction + " " + MySubCur
                End If
            Else
                NoToTxt= ReMark + Mybillion + MyMillion + MyThou + MyHun + " " + MyCur
            End If
        End Function
    Last edited by SALIAHM; Feb 6th, 2023 at 02:43 AM.

  7. #7
    Junior Member
    Join Date
    Feb 2023
    Posts
    20

    Resolved Re: Call a function into Textbox Report Viewer

    Hello guys, its me Tajaldeen
    this is the code i was looking for
    Code:
    =Code.FunctionName(Fields!FieldName1, Fields!FiedlName1.Value, "")
    First FieldName1 is the field that funciton will apply to (Conver Number into Text).
    Second Fieldname1 is the same field but without function (Number to Number).
    if you want only the field with function you can apply any other empty filed instead of second FieldName1.

    Now my function works directly from the rdcl perfectly

  8. #8
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Re: Call a function into Textbox Report Viewer

    Hi Taljadeem,

    Thank you very much for coming back to share that information 🙂

  9. #9
    New Member
    Join Date
    Feb 2024
    Posts
    1

    Re: Call a function into Textbox Report Viewer

    Can you provide more details about the specific error or issue you encountered when attempting to call the function inside the textbox expression, and how did you address or resolve it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width