Skip to Content
author's profile photo Former Member
Former Member

How to pass date value to an UDF

Hi,

I am working in SDK UI. I have created a form. In this form there is a edit text box. I have to pass a date value to that object. I have taken a variable and pass a date value in "yyyy/mm/dd" format. When I am assign this variable to the object to pass the date value to that object then I am getting an error. The error is "Unable to cast object of type 'system.string' to 'system.IFormatProvider' ".

I have written the code like this :------>

Dim AtenDate As String

AtenDate = '2007/08/01' ' format "yyyy/mm/dd"

Dim txtEditDt As SAPbouiCOM.EditText

oItem = oForm.Items.Item("11")

txtEditDt = oItem.Specific

txtEditDt.String = AtenDate.ToString("dd/MM/yyyy")

After the last line the error is getting fire.

Please help me how I can pass the date value to that object.

Please help me. It is very urgent.

Add a comment
10|10000 characters needed characters exceeded

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2008 at 12:56 PM

    Hi Amit Shai

    Before save data I'm using ANSI2DATE(str) function to convert String value in DateTime.

    Hope to help

    BR

    Sierdna S.

    Save function what scroll all lines in matrix and call Ansi 2 Date function to convert String in DateTime.

    Private Function Save() As Boolean
      Dim b As Boolean = True
      ...
      If Not oDBDataSource.GetValue("U_Data", i) Is Nothing Then
        sU_Data = ANSI2DATE(oDBDataSource.GetValue("U_Data", i))
      End If
      ...
      Return b
    End Function
    

    ANSI 2 DATE function to convert String in DateTime.

    Public Function S2ANSI2Date(ByVal inString As String) As DateTime
      Dim outDate As DateTime
      Try
        If Not inString Is Nothing Then
          If inString.Equals("") Then Exit Try
          outDate = New DateTime( _
    	      CInt(Mid$(inString, 1, 4)), _
    	      CInt(Mid$(inString, 5, 2)), _
    	      CInt(Mid$(inString, 7, 2)))
        End If
      Catch ex As Exception
        ' log exception
      End Try
      Return outDate
    End Function
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 30, 2007 at 02:37 AM

    Try to:

    txtEditDt.String = AtenDate.ToString("dd.MM.yyyy")

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 01, 2007 at 06:47 AM

    Hi..

    oEditText.String = System.DateTime.Today.Date.ToString("dd/MM/yy");

    DateTime DT=dateTime.parse(oEditText.String)

    try this code .. Hope so u will get help

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 01, 2007 at 10:49 AM

    hi,

    the better option is:-

    take the userdatasource type of Date (length-8) and bind with the edittext.

    string strDatecheck = string.Empty;

    strDatecheck = Convert.ToDateTime(strDatecheck ).ToString("dd-MMM-yyyy");

    -


    then pass this string value in the database.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 01, 2007 at 12:48 PM

    Date and Double conversion is really a confusing thing in B1-SDK programming in the beginning.

    But once you got it it's okay.

    When working with date-time and doubles (System and SBO-Price/SBO-Quantity), you should always take care about the language of...

    ...system (windows)

    ...SBO User Interface

    These two formats could make trouble when the programming has been made only for a specific configuration of these two.

    The third format for SDK-Programming is

    ...the SBO-DB-Format, which is language-independent and always a String

    Here are some rules:

    <b>EditText.String</b> ALWAYS returns the value you see on the SBO GUI. It depends on the SBO Date, Price etc.-Format the USER has configured in the Administration. Consider that the user has (for example) the possibility to choose a "#" (or whatever) as decimal-seperator. Direct (implicit) conversion of such a string to a double will fail at the latest now.

    The savest way to get a .NET-Double or DateTime- Value from EditText.String are the conversion methods of SBOBobs-Object (see SDK-help -> BoBridge, Format_MoneyToString...etc.).

    I think it's a good idea to write some wrapper functions for that methods, cause they always need a recordset which blows up the code too much.

    <b>EditText.Value</b> always (system/sbo-language independent) returns the value as a String in DB-Format (Double as "12345.126700" and date as "20070930".

    For that you must asure that the EditText is bounded to a format-corresponding datasource. Price, Quantitiy.... if you need a double.

    If your "price"-field would be bound to ShortText and the user wants (assuming the example from above) a "#" for decimal-point, then a GUI-seen value like "12,421#12" is also returned as "12,421#12" by EditText.Value. But If bound to Price-DataSource it's "12421.120000"

    => So always do a DataBind to the Data - Type which is needed is recommended for this to work!

    In my case EditText.String and -Value is mostly (only...? 😉 needed for B1-System-Forms where using of DataSources is restricted.

    The prefered way of read/write values is the

    <b>UserDataSource.ValueEx and DBDataSource.GetValue/SetValue</b>-method. It's also always in DB-Format as EditText.Value before, but gives much more performance.

    Once you got some conversion-functions for "DB-Format-String" to ".NET-DataType" and vice verca (I've defined some .NET - System.Globalization.XXXFormatInfo-Objects for that) all of your problems are things of the past 😉

    Regards,

    Roland

    null

    Message was edited by:

    Roland Toschek

    Edited by: Roland Toschek on Jan 22, 2008 5:32 PM

    Trying to clarify a sentence

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 23, 2008 at 05:03 AM

    Hi Amit,

    txtEditDt.String = AtenDate.ToString("MMddyyyy")

    this can do.try it

    Thanks & Regards

    Shiva shanker

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.