Formatting Date From A Date Input Panel

218 views Asked by At

I'm got a user interface to input a date via an input panel. I'm building the panel as shown below. It's a DATEPANEL so it automatically adds the input mask (forward slahes e.g. mm/dd/yyyy):

RepurchaseDatePanel = oMstrCmp.AddPanel(DATEPANEL)
    oMstrCmp.AddMessage RepurchaseDatePanel,"SALE/REPURCH/MNT Date"
    If IsDate(strRepurchaseDate) Then
        oMstrCmp.AddItems RepurchaseDatePanel, strRepurchaseDate
    End If
        oMstrCmp.MoveVertDivider RepurchaseDatePanel, 75
    oMstrCmp.Panels(RepurchaseDatePanel).CaptionFont.Style = 1

Then, I am grabbing the text from the panel and defining the string globally as follows:

strRepurchaseDate = oMstrCmp.GetText(RepurchaseDatePanel)
strRepurchaseDate = Left(strRepurchaseDate,2) + "/" +Mid(strRepurchaseDate,3,2) + "/" + Right(strRepurchaseDate,2)

Next, I am trying to enter that date in MMDDYY format onto a 3270 emulator screen. The format for the date panel is MM/DD/YYYY and I'm trying to format it to MMDDYY format to fit the screen. Below is how I am attempting to enter it on the screen:

subMoveCursor 11, 10        
    If (InStr(1, Trim(strRepurchaseDate), "/") <> 0) Then
        strHold_Date = funcFormatDate(strRepurchaseDate)
        subPressKey "@F"
        subEnterData strHold_date
    End If

I'm using funcFormatDate to format the date from the panel from MM/DD/YYYY format to MMDDYY format. Below is funcFormatDate:

Function funcFormatDate(strRepurchaseDate)
   Dim strhld_mm
   Dim strhld_dd
   Dim strhld_yy
   Dim nMM_pos
   Dim nDD_len
   Dim nDD_pos

   nMM_pos   = InStr(1,strRepurchaseDate,"/")

   strhld_mm = Left(strRepurchaseDate,nMM_pos - 1)
   strhld_mm = Right("00" & strhld_mm,2) ' zero fill field upt to 2 pos

   nDD_pos   = InStr(nMM_pos + 1,strRepurchaseDate,"/")
   nDD_len   = (nDD_pos - nMM_pos) - 1

   strhld_dd = Left(strRepurchaseDate,nDD_pos - 1)
   strhld_dd = Mid(strRepurchaseDate,nMM_pos + 1, nDD_len)
   strhld_dd = Right("00" & strhld_dd,2) ' zero fill field upt to 2 pos

   strhld_yy = Right(strRepurchaseDate,2)

   funcFormatDate = strhld_mm & strhld_dd & strhld_yy

End Function

However, the result I am getting is "0000//". When I enter "08/13/2018" I always get the result "0000//" as if the function is working, but I am not "getting" the text from the panel. I can't get the actual text from the panel to write "081318" onto the screen, every time it gives me "0000//".

Can anyone assist?

1

There are 1 answers

0
UndergroundMan On BEST ANSWER

So, I got it working. The issue was quite simple, and something I wasn't aware of. I had the variable strRepurchaseDate defined globally and it was also defined in my function to create the user interface. For whatever reason, it couldn't be defined in the function and globally at the same time. I simply removed the variable from my function that creates the user interface, and it worked. So funcFormatDate works for reformatting the date while using a DATEPANEL. Thanks for your assistance.