Despite of checking many questions relating error 13, I could not find answers to my problem, so I am giving a shot here:
I am building my code to save information from a userform, but first I am testing to see if mandatory textboxes are empty. Since I am using a 64 bits machine I have used Trevor Eyre´s CalendarForm.
However while testing the code I hit a problem with the empty textboxes that receives the dates from CalendarForms:
In this line:
Dim dteCompraDataOps As Date: dteCompraDataOps = Me.txtTesouro_Compra_DataOps.value
This part is highlighted and returns Runtime Error 13:
dteCompraDataOps = Me.txtTesouro_Compra_DataOps.value
When I check the values coming from empty TextBoxes I get:
dteCompraDataOps = "00:00:00"`
Which is correct since it should be treated as Date, but this:
Me.txtTesouro_Compra_DataOps.value = ""
Is coming as a string.
I did a little search and noticed that Date data types are tricky when the textbox they come from are empty.
I could find a solution: creating a Select Case to test the mandatory fields before declaring the variables but I would like o learn how to deal with the empty textboxes that are supposed to be empty.
Any chance you can shed some light into my conundrum?
Thanks in advance.
Cub4_RJ
There are two ways to handle this.
a) Check for Null:
With Me.txtTesouro_Compra_DataOps
If Not IsNull(.Value) Then
If IsDate(.Value) Then dteCompraDataOps = . Value
End if
End With
b) Introduce a new variable of Variant type which accepts everything (including nulls) and check it's value.
Dim rawData As variant
rawData = Me.txtTesouro_Compra_DataOps.Value
If Not IsNull(rawData) Then
If IsDate(rawData) Then dteCompraDataOps = rawData
End If
The problem with approach A, is that the value 123 is treated as a date, however option B will catch it.
Related
I'm very new in using Cognos report studio and trying to filter some of the values and replace them into others.
I currently have values that are coming out as blanks and want to replace them as string "Property Claims"
what i'm trying to use in my main query is
CASE WHEN [Portfolio] is null
then 'Property Claims'
ELSE [Portfolio]
which is giving me an error. Also have a different filter i want to put in to replace windscreen flags to a string value rather than a number. For example if the flag is 1 i want to place it as 'Windscreen Claims'.
if [Claim Windscreen Flag] = 1
then ('Windscreen')
Else [Claim Windscreen Flag]
None of this works with the same error....can someone give me a hand?
Your first CASE statement is missing the END. The error message should be pretty clear. But there is a simpler way to do that:
coalesce([Portfolio], 'Property Claims')
The second problem is similar: Your IF...THEN...ELSE statement is missing a bunch of parentheses. But after correcting that you may have problems with incompatible data types. You may need to cast the numbers to strings:
case
when [Claim Windscreen Flag] = 1 then ('Windscreen')
else cast([Claim Windscreen Flag], varchar(50))
end
In future, please include the error messages.
it might be syntax
IS NULL (instead of = null)
NULL is not blank. You might also want = ' '
case might need an else and END at the bottom
referring to a data type as something else can cause errors. For example a numeric like [Sales] = 'Jane Doe'
For example (assuming the result is a string and data item 2 is also a string),
case
when([data item 1] IS NULL)Then('X')
when([data item 1] = ' ')Then('X')
else([data item 2])
end
Also, if you want to show a data item as a different type, you can use CAST
I am writing an Excel VBA program that validates a school course schedule. A key component is a global dictionary object that keeps track of the course number (the key) and the number of times that course is scheduled (the item). I have successfully created and loaded the dictionary. I'm trying to lookup the value associated with the course key, but have been unable to do so using the one-line examples I've found at this site. I'd like to use this line of code:
intCourseCnt = gdicCourses("BAAC 100")
or
intCourseCnt = gdicCourses.Item("BAAC 100")
but neither work (actually, the "BAAC 100" part is a string variable, but it won't even work if I hardcode a course in.) Instead, I have to use the kludgy loop code below to lookup the course count:
Private Function Check_Course_Dup_Helper(strCourse As String) As Boolean
Dim k As Variant
Check_Course_Dup_Helper = False
' Read thru dictionary. Look to see if only 1 occurrence then jump out.
For Each k In gdicCourses.Keys
If k = strCourse Then
If gdicCourses.Item(k) = 1 Then
Check_Course_Dup_Helper = True
Exit Function
End If
Exit Function
End If
Next
End Function
Is there a way to rewrite this so that I can lookup of the item value without the loop?
Thank you.
Thanks for the prompt replies. Answers below:
David, the gdicCourses("BAAC 100") code value while the program is running is "empty" which makes the receiving variable equal to 0. The result is the same if I use strCourse variable. Also, the dictionary populating code is shown below. I do not believe it is a problem because I can correctly access the values elsewhere in the program where For-Each-Next loops that use a range variable are employed. Whitespace and non-printable characters are not present.
My guess is that I need to use a range to reference the position in the dictionary rather than a string. I've tried pretty much every combination of this that I can think of, but the value is still "empty".
Set gdicCourses = New Scripting.Dictionary
For Each c In Worksheets("Tables").Range("combined_courses").Cells
If Not (gdicCourses.Exists(c)) Then
gdicCourses.Add c, (Application.WorksheetFunction.CountIF(Range("MWF_Table_Full"), c
(Application.WorksheetFunction.CountIf(Range("TTh_Table_Full"), c)))
End If
Next
I'm getting a error I can't quite explain I have a Excel list I want to load into memory, to see if the next row is still a relative row I check if the cell has a value by doing If value = "" Then but the value is 1012738 and it gives me a unhandled exception...
I can't quite understand why the code is giving a error, the cell value is formatted just like all previous cells that were checked. But here a error is thrown.
Maybe i'm just not seeing it, and someone can explain?
You should check the value each time.
Dim o As Object = oSheet.Range(xxx).Value
If (o IsNot Nothing) Then
Select Case o.GetType
Case GetType(Double)
' do work here
Case GetType(Integer)
' do work here
...
End Select
Else
...
End If
Your image isn't showing up for me.
Most exceptions in excel are datatype related. Most likely, you either have a NULL or a string that looks like an integer to the human eye. You can blindly try using trim(), int() or str() etc as needed to make sure you're actually testing an integer or matching a string if thats what you are about or you can test them in a programmatic method.
First, the programmatic method of testing ... isEmpty or isNull are needed to ensure the cell is good ...
if isEmpty(value) Then
<do something>
This will most likely catch the error which is causing the message. If empty is failing, try testing with isNull. One means the cell is empty, the other means that it wasn't initialize (rarely an issue in excel, but if using vba code it can happen).
Also ... your if statement is setup in a less than optimal... used <> in place of if then + else ...
Your code ...
If value = "" Then
General formula when you want to test that something is not something else, use the not equals ...
if value <> "value" Then
"some operation"
I have this problem with a very simple function written in an XLL, using VS2012. I have tried reading up in MSDN and Steve Dalton's book, and I cannot see what I am doing wrong.
The tricky bit is that I need my function to read values in worksheet cells other than the one from which it is called. The function takes no arguments, and returns an integer. I have declared it as J# (the # signifying that it can call XLM functionality as advised by Dalton...although I still get the same problem without the #). I have not included the declaration of my function to save space, but it is simple and I do not think it is the cause of the problem.
This first block of code works fine. I wrote it just to build confidence.
//This block works correctly. A trial copied from the old Excel 97 documentation
XLOPER12 xlInput1, xlOutput2;
/* Evaluate the string "2+3" */
xlInput1.xltype = xltypeStr;
xlInput1.val.str = L"\0032+3"; //prefix with string length in Octal
Excel12(xlfEvaluate, &xlOutput2, 1, (LPXLOPER12) &xlInput1);
//works OK, and xlOutput2 contains 5
But this second block does not work. I cannot see why. I am trying to read a value from a cell, which is a different cell from that from which the function was called. What I get is an return XLOPER12 that contains an error (xltypeErr) and junk values in the val.num field (the worksheet cell does contain an integer value).
//This block does not work
XLOPER12 xlInput3, xlOutput3;
/* Look up the name Tst on the active sheet called Sht */
xlInput3.xltype = xltypeStr;
xlInput3.val.str = L"\003Tst"; //this also gives problems regardless of whether the string is defined as \004!Tst or \007Sht!Tst
Excel12(xlfEvaluate, &xlOutput3, 1, (LPXLOPER12) &xlInput3); //xlOutput3 now has a type of xltypeErr, rather than the correct integer value on the worksheet
Can you kindly explain what is going wrong?
If you're trying to read a value from a cell that is different from the cell calling the function you'll need a parameter to refer to that different cell. For example in A1 you may have '=myfunc(A2)'. Then your C++ extension func will need to be declared 'JP#', with the P corresponding to the A2 cell reference parameter. If Excel can resolve the 'A2' reference it will pass in an XLOPER with that value as xltypeNum, xltypeInt or xltypeStr depending on the the contents of A2. If not you may get an xltypeSRef.
xlfEvaluate: here's the MS doc https://msdn.microsoft.com/en-us/library/office/bb687913(v=office.15).aspx
Note that MS specify that the string passed to xlfEvaluate must 'contain only functions, not command equivalents'. I suspect L"\003Tst" doesn't correspond to any function known to your Excel. There's no built in function called Tst in my Excel 2013. It's possible you have an addin that supplies a function called Tst, but I'm guessing not. So try changing xlInput3.val.str to L"\006RAND()" and see what happens.
Good Day Everyone,
There is this something i've been trying to exercise in abap and that is the Displaying of column datas in ALV by retrieving the values from excel file into an internal table. I've been trying to debug my program for quite some time now and i can't seem to solve the error it's been stating which is "Field symbol has not yet been assigned" please guide me. I already made some research on how to solve this short dump error but most of the other issues posted on the net is selected from some specific table with column fields. I was just wondering that maybe my case is a little bit different from others.
The function that retrieved the values from excel is properly working and i have no problem at all in displaying them.Below is the code i constructed.
TYPE-POOLS: truxs,
slis.
TYPES: BEGIN OF t_itab,
col1 TYPE char20,
col2 TYPE char20,
col3 TYPE char20,
col4 TYPE char20,
col5 TYPE char20,
END OF t_itab,
t_it_itab type STANDARD TABLE OF t_itab.
Data: gt_tab TYPE t_it_itab,
wa_tab TYPE t_itab,
g_numrows TYPE i.
PARAMETERS: p_fname TYPE c LENGTH 50.
INITIALIZATION.
AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN.
AT SELECTION-SCREEN on VALUE-REQUEST FOR p_fname.
DATA: l_filename LIKE IBIPPARMS-PATH.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = '1000'
IMPORTING
FILE_NAME = l_filename
.
p_fname = l_filename.
START-OF-SELECTION.
DATA: lc_fname TYPE RLGRAP-FILENAME,
lt_tab TYPE TRUXS_T_TEXT_DATA.
lc_fname = p_fname.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_TAB_RAW_DATA = lt_tab
I_FILENAME = lc_fname
TABLES
I_TAB_CONVERTED_DATA = gt_tab
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
WRITE 'Error'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
" Delete First Row / HEADER
DELETE gt_tab INDEX 1.
IF gt_tab[] is INITIAL.
MESSAGE 'No Record(s) found' TYPE 'I'.
EXIT.
ELSE.
PERFORM DisplayALv.
ENDIF.
FORM DISPLAYALV.
DATA: l_it_fcat type SLIS_T_FIELDCAT_ALV,
l_wa_fcat TYPE SLIS_FIELDCAT_ALV.
l_wa_fcat-fieldname = 'col1'.
l_wa_fcat-ref_tabname = 'gt_tab'.
l_wa_fcat-reptext_ddic = 'Column 1'.
l_wa_fcat-outputlen = '30'.
APPEND l_wa_fcat TO l_it_fcat.
CLEAR l_wa_fcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IT_FIELDCAT = l_it_fcat
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = gt_tab[].
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC .
ENDIF.
ENDFORM.
Any tips, tricks and advice in my program would be highly sought. Thanks in Advance
You're using a type which is not defined in the data dictionary. This requires a different approach when creating the ALV fieldcat. Try this:
l_wa_fcat-fieldname = 'COL1'.
l_wa_fcat-inttype = 'C'.
l_wa_fcat-outputlen = '30'.
l_wa_fcat-text_fieldname = 'Column 1'.
l_wa_fcat-seltext_s = 'Column 1'.
Also make sure you enter the fieldname value with capitalized letters.
I'm no ABAP expert but I noticed 2 things in the code you posted:
you said the error is "Field symbol has not yet been assigned" but you have no field symbol in your code. Maybe it's used inside one of the function modules you call. If so, try to post the code where the error pops up;
you use gt_tab[] which, if I remember well, is the way to access the body of an internal table with header line. In your code gt_tab is not an internal table with header line, but you use it to store one with function 'TEXT_CONVERT_XLS_TO_SAP' ;
Try to post the code where the error is being generated.
Regards,
Sergiu