Goal: Avoid hard coding the control's name in my VBA data verification function
I have a control which has a data validation rule.
It calls a user defined function that measures how many decimals have been entered in the control.
Function GetDPstr() As Integer
' Returns for the number of decimal places in a string
Dim NumberBox As Control
'Error here: I would like to be able to implicitly access the control's value without
'having to hard code the control's name so I can reuse the code for other controls
'as opposed to using "Me.Controls!ControlName"
Set NumberBox = Me.txtbox
If Len(NumberBox) - Len(Replace(NumberBox, ".", "")) = 0 Then ' test for decimal point separator
GetDPstr = 0
Else
GetDPstr = Len(RTrim(NumberBox)) - InStr(RTrim(NumberBox), ".")
End If
End Function
I have one gridview. Can I check any how that In one column if it contains any string or number. and If it contains any string than I want to do some funtion
Create a loop that goes through each item in that column, and pass that value as strValue to this handler:
If String.IsNullOrEmpty(strValue) = False Then
' Do something if it contains something
end if
Reference: https://learn.microsoft.com/en-us/dotnet/api/system.string.isnullorempty?view=netframework-4.7.2
Im using getPrivateProfileString to read from an API. Here I call the method and get a store number
Rec = String(255, 0)
NC = GetPrivateProfileString("ConfigInfo", "store", "", Rec, 255, "C:\MyPath")
Now when I debug Rec has no value
However when I use Rec in a message box it shows its value as expected.
Why is the variable Rec an empty variable instead of holding my store number as expected? Why does Rec's value seem to be as expected in a message box?
In my report why is it that when I set the ControlSource on a textbox in a report to a field name like this: txtSomeTextBox.ControlSource = [Expr1] it populates as expected but when I define a user defined function like this:
Public Function GetString(strValues As String) As String
GetString = "Values: " & strValues
End Function
Then set the ControlSource property to txtSomeTextBox.ControlSource = GetString([Expr1]) it doesn't know what to do! In fact the textbox displays: "#Type!" Why can't I pass the value of [Expr1] to the function?
You need a = to evaluate a function.
=GetString([Expr1]) as controlsource works for me.
how to insert data to custom table in db using selection screen?
Is there standard class or method that can be use or need to create custom class?
requirement: after user give the input in the ADD selection-screen page, and hit the button 'add', data will be insert to the respective custom table in db.
How to proceed from here?
REPORT YTEST3.
tables YNAH_CUS_OBJ_REQ.
tables sscrfields.
type-pools : slis.
"DATA: flag TYPE c.
"DATA it_ucomm TYPE TABLE OF sy-ucomm.
TYPES: BEGIN OF TY_YNAH_CUS_OBJ_REQ, "CREATE STRUCTURE -1
REQID TYPE YNAH_REQ_ID,
REQUESTOR TYPE YNAH_REQUESTOR,
BUSINESS_OWNER TYPE YNAH_BUS_OWN,
FUNCTIONAL_OWNER TYPE YNAH_FUNC_OWN,
REQNUM TYPE YNAH_SERVICE_REQ_NUM,
PROJECT_ID TYPE YNAH_PRO_ID,
SYSTEM_ID TYPE YNAH_SYS_ID,
FUNCTIONAL_AREA TYPE YNAH_FUNC_AREA,
REQUEST_DATE TYPE YNAH_REQ_DATE,
REQUEST_TIME TYPE YNAH_REQ_TIME,
END OF TY_YNAH_CUS_OBJ_REQ.
DATA: IT_YNAH_CUS_OBJ_REQ TYPE TABLE OF TY_YNAH_CUS_OBJ_REQ,
WA_YNAH_CUS_OBJ_REQ TYPE TY_YNAH_CUS_OBJ_REQ.
DATA: it_fcat TYPE slis_t_fieldcat_alv.
DATA: wa_fcat TYPE slis_fieldcat_alv.
DATA MYALV TYPE REF TO CL_SALV_TABLE.
DATA MYFUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS_LIST.
DATA MYCOLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE.
**********SELECTION-SCREENS*********************
*SELECTION-SCREEN FOR RADIO BUTTON 1
SELECTION-SCREEN BEGIN OF BLOCK menu WITH FRAME TITLE text-000.
selection-screen begin of line.
PARAMETER : P_SEARCH RADIOBUTTON GROUP g1 USER-COMMAND ONE DEFAULT 'X'.
selection-screen comment 7(9) for field p_search.
PARAMETER : P_ADD RADIOBUTTON GROUP g1.
selection-screen comment (9) for field p_add.
selection-screen end of line.
*SELECTION-SCREEN FOR RADIO BUTTON 1
SELECTION-SCREEN BEGIN OF BLOCK rad1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:
s_reqid FOR WA_YNAH_CUS_OBJ_REQ-REQID MODIF ID ONE,
s_req FOR WA_YNAH_CUS_OBJ_REQ-REQUESTOR NO-EXTENSION NO INTERVALS MODIF ID ONE,
s_date FOR WA_YNAH_CUS_OBJ_REQ-REQUEST_DATE MODIF ID ONE.
SELECTION-SCREEN: BEGIN OF LINE,
pushbutton 55(12) BUT1 user-command search MODIF ID ONE.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK rad1.
*SELECTION-SCREEN FOR RADIO BUTTON 2
SELECTION-SCREEN BEGIN OF BLOCK rad2 WITH FRAME TITLE text-002.
PARAMETER:
p_req TYPE TY_YNAH_CUS_OBJ_REQ-REQUESTOR MODIF ID TWO,
p_busown TYPE TY_YNAH_CUS_OBJ_REQ-BUSINESS_OWNER MODIF ID TWO,
p_funown TYPE TY_YNAH_CUS_OBJ_REQ-FUNCTIONAL_OWNER MODIF ID TWO,
p_srvreq TYPE TY_YNAH_CUS_OBJ_REQ-REQNUM MODIF ID TWO,
p_proid TYPE TY_YNAH_CUS_OBJ_REQ-PROJECT_ID MODIF ID TWO,
p_sysid TYPE TY_YNAH_CUS_OBJ_REQ-SYSTEM_ID MODIF ID TWO,
p_funare TYPE TY_YNAH_CUS_OBJ_REQ-FUNCTIONAL_AREA MODIF ID TWO.
SELECTION-SCREEN: BEGIN OF LINE,
pushbutton 55(12) BUT2 user-command add MODIF ID TWO.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK rad2.
SELECTION-SCREEN END OF BLOCK menu.
*---------------------------
AT SELECTION-SCREEN OUTPUT.
*---------------------------
BUT1 = 'SEARCH'.
BUT2 = 'ADD'.
*CLICK OF FIRST RADIO BUTTON
"IF p_search = 'X'.
LOOP AT SCREEN.
IF screen-group1 = 'ONE'.
IF P_SEARCH = 'X'.
screen-invisible = '0'.
screen-active = '1'.
ELSE.
screen-invisible = '1'.
screen-active = '0'.
ENDIF.
MODIFY SCREEN.
ENDIF.
IF screen-group1 = 'TWO'.
IF P_ADD = 'X'.
screen-invisible = '0'.
screen-active = '1'.
ELSE.
screen-invisible = '1'.
screen-active = '0' .
ENDIF.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
at selection-screen. "after processing user input
case SSCRFIELDS.
when 'SEARCH'.
SSCRFIELDS-UCOMM = 'ONLI'.
endcase.
"fetch data using select for SEARCH
START-OF-SELECTION.
SELECT *
FROM YNAH_CUS_OBJ_REQ "Database
INTO CORRESPONDING FIELDS OF TABLE IT_YNAH_CUS_OBJ_REQ "Into internal table
WHERE
REQID in s_reqid and
REQUESTOR in s_req and
REQUEST_DATE in s_date.
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = MYALV
CHANGING
T_TABLE = IT_YNAH_CUS_OBJ_REQ.
CATCH CX_SALV_MSG.
ENDTRY.
MYCOLUMNS = MYALV->GET_COLUMNS( ).
MYCOLUMNS->SET_OPTIMIZE( ).
MYFUNCTIONS = MYALV->GET_FUNCTIONS( ).
MYFUNCTIONS->SET_ALL( ).
CALL METHOD MYALV->DISPLAY.
I don't see any INSERT or MODIY statements in your code. You don't need any custom class for that. Check help for these statements.
TABLES YNAH_CUS_OBJ_REQ.
DATA WA TYPE YNAH_CUS_OBJ_REQ.
WA-REQID = '1'.
WA-REQUESTOR = p_req.
WA-BUSINESS_OWNER = p_busown.
...<<<add other fields also>>>
INSERT INTO YNAH_CUS_OBJ_REQ VALUES WA.