PowerBuilder Functions Aggregate
F_RELATIVE_YEAR
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_relative_year // Argument Name : ad_source, Arg Type : Date, Pass By : Value // al_years, Arg Type : Long, Pass By : Value // Return Type : Date /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Given a date, will return the date +/- the number of years passed // in the second parameter. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Integer li_year Integer li_month Integer li_day //Check parameters If IsNull(ad_source) Or IsNull(al_years) Then Date ldt_null SetNull(ldt_null) Return ldt_null End If //Check for invalid date If Not f_Is_Valid_Date(ad_source) Then Return ad_source End If li_year = Year(ad_source) + al_years li_month = Month(ad_source) li_day = Day(ad_source) //Check for a valid day (i.e., February 30th is never a valid date) Do While Not f_Is_Valid_Date(Date(li_year, li_month, li_day)) And li_day > 0 li_day -- Loop Return( Date(li_year, li_month, li_day)) |
F_RELATIVE_MONTH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_relative_month // Argument Name : ad_source, Arg Type : Date, Pass By : Value // al_month, Arg Type : Long, Pass By : Value // Return Type : Date /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Given a date, will return the date +/- the number of months passed // in the second parameter. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Integer li_adjust_months Integer li_adjust_years Integer li_month Integer li_year Integer li_day Integer li_temp_month //Check parameters If IsNull(ad_source) Or IsNull(al_month) Then Date ldt_null SetNull(ldt_null) Return ldt_null End If //Check for invalid date If Not f_Is_Valid_Date(ad_source) Then Return ad_source End If //Number 12 is for the Twelve months in a year. li_adjust_months = Mod(al_month, 12) li_adjust_years = (al_month / 12) li_temp_month = Month(ad_source) + li_adjust_months If li_temp_month > 12 Then // Add one more year and adjust for the month li_month = li_temp_month - 12 li_adjust_years ++ ElseIf li_temp_month <= 0 Then // Subtract one more year and adjust for the month li_month = li_temp_month + 12 li_adjust_years -- Else // No need for any adjustments li_month = li_temp_month End If li_year = Year(ad_source) + li_adjust_years li_day = Day(ad_source) //Check for a valid day (i.e., February 30th is never a valid date) Do While Not f_Is_Valid_Date(Date(li_year, li_month, li_day)) & And li_day > 0 li_day -- Loop Return( Date(li_year, li_month, li_day)) |
F_RELATIVE_DATETIME
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_relative_datetime // Argument Name : adtm_start, Arg Type : DateTime, Pass By : Value // al_offset, Arg Type : Long, Pass By : Value // Return Type : Datetime // Relative datetime. // If any argument's value is NULL, function returns NULL. // If any argument's value is Invalid, function returns 1900-01-01. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Given a datetime, find the relative datetime +/- n seconds /////////////////////////////////////////////////////////////////////////////////////////////////////////////// DateTime ldt_null Date ld_sdate Time lt_stime Long ll_date_adjust Long ll_time_adjust, ll_time_test //Check parameters If IsNull(adtm_start) Or IsNull(al_offset) Then SetNull(ldt_null) Return ldt_null End If //Check for invalid date If Not f_Is_Valid_DateTime(adtm_start) Then Return ldt_null End If //Initialize date and time portion ld_sdate = Date(adtm_start) lt_stime = Time(adtm_start) //Find out how many days are contained //Note: 86400 is # of seconds in a day ll_date_adjust = al_offset / 86400 ll_time_adjust = Mod(al_offset, 86400) //Adjust date portion ld_sdate = RelativeDate(ld_sdate, ll_date_adjust) //Adjust time portion // Allow for time adjustments periods crossing over days // Check for time rolling forwards a day If ll_time_adjust > 0 Then ll_time_test = SecondsAfter(lt_stime,Time('23:59:59')) If ll_time_test < ll_time_adjust Then ld_sdate = RelativeDate(ld_sdate,1) ll_time_adjust = ll_time_adjust - ll_time_test -1 lt_stime = Time('00:00:00') End If lt_stime = RelativeTime(lt_stime, ll_time_adjust) //Check for time rolling backwards a day ElseIf ll_time_adjust < 0 Then ll_time_test = SecondsAfter(lt_stime,Time('00:00:00')) If ll_time_test > ll_time_adjust Then ld_sdate = RelativeDate(ld_sdate,-1) ll_time_adjust = ll_time_adjust - ll_time_test +1 lt_stime = Time('23:59:59') End If lt_stime = RelativeTime(lt_stime, ll_time_adjust) End If Return(DateTime(ld_sdate,lt_stime)) |
F_IS_VALID_TIME
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_is_valid_time // Argument Name : atm_source, Arg Type : Time, Pass By : Value // Return Type : Boolean /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Given a time, will determine if the time is valid. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Integer li_hour Integer li_minute Integer li_second // Initialize test values. li_hour = Hour(atm_source) li_minute = Minute(atm_source) li_second = Second(atm_source) // Check for nulls. If IsNull(atm_source) Or IsNull(li_hour) Or IsNull(li_minute) Or IsNull(li_second) Then Return False End If // Check for invalid values. If li_hour < 0 Or li_minute < 0 Or li_second < 0 Then Return False End If // Passed all testing. Return True |
F_IS_VALID_DATETIME
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_is_valid_datetime // Argument Name : adtm_source, Arg Type : DateTime, Pass By : Value // Return Type : Boolean /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Given a datetime, will determine if the Datetime is valid. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Date ldt_value //Check parameters If IsNull(adtm_source) Then Return False End If //There is only need to test the Date portion of the DateTime. //Can't tell if time is invalid because 12am is 00:00:00:000000 ldt_value = Date(adtm_source) //Check for invalid date If Not f_Is_Valid_Date(ldt_value) Then Return False End If Return True |
F_IS_VALID_DATE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_is_valid_date // Argument Name : ad_source, Arg Type : Date, Pass By : Value // Return Type : Boolean /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Given a date, will determine if the Date is valid. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Integer li_year Integer li_month Integer li_day // Initialize test values. li_year = Year(ad_source) li_month = Month(ad_source) li_day = Day(ad_source) // Check for nulls. If IsNull(ad_source) Or IsNull(li_year) Or IsNull(li_month) Or IsNull(li_day) Then Return False End If // Check for invalid values. If li_year <= 0 Or li_month <= 0 Or li_day <= 0 Then Return False End If // Passed all testing. Return True |
F_IS_WHITE_SPACE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_is_white_space // Argument Name : as_source, Arg Type : String, Pass By : Value // Return Type : Boolean /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Determines whether a string contains only White Space // characters. White Space characters include Newline, Tab, // Vertical tab, Carriage return, Formfeed, and Backspace. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_count = 0 Long ll_length Char lc_char[] Integer li_ascii //Check parameters If IsNull(as_source) Then Boolean lb_null SetNull(lb_null) Return lb_null End If //Get the length ll_length = Len (as_source) //Check for at least one character If ll_length = 0 Then Return False End If //Move string into array of chars lc_char = as_source //Perform loop around all characters //Quit loop if Non WhiteSpace character is found Do While ll_count < ll_length ll_count ++ //Get ASC code of character. li_ascii = Asc (lc_char[ll_count]) If li_ascii = 8 Or /* BackSpae */ & li_ascii = 9 Or /* Tab */ & li_ascii = 10 Or /* NewLine */ & li_ascii = 11 Or /* Vertical Tab */ & li_ascii = 12 Or /* Form Feed */ & li_ascii = 13 Or /* Carriage Return */ & li_ascii = 32 Then /* Space */ //Character is a WhiteSpace. //Continue with the next character. Else /* Character is Not a White Space. */ Return False End If Loop // Entire string is White Space. Return True |
F_IS_PUNCTUATION
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_is_punctuation // Argument Name : as_source, Arg Type : String, Pass By : Value // Return Type : Boolean /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Determines whether a string contains only punctuation // characters. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_count = 0 Long ll_length Char lc_char[] Integer li_ascii //Check parameters If IsNull(as_source) Then Boolean lb_null SetNull(lb_null) Return lb_null End If //Get the length ll_length = Len (as_source) //Check for at least one character If ll_length = 0 Then Return False End If //Move string into array of chars lc_char = as_source //Perform loop around all characters //Quit loop if Non Punctuation character is found Do While ll_count < ll_length ll_count ++ //Get ASC code of character. li_ascii = Asc (lc_char[ll_count]) If li_ascii = 33 Or /* '!' */ & li_ascii = 34 Or /* '"' */ & li_ascii = 39 Or /* ''' */ & li_ascii = 44 Or /* ',' */ & li_ascii = 46 Or /* '.' */ & li_ascii = 58 Or /* ':' */ & li_ascii = 59 Or /* ';' */ & li_ascii = 63 Then /* '?' */ //Character is a punctuation. //Continue with the next character. Else Return False End If Loop // Entire string is punctuation. Return True |
F_IS_COMPARISON_OPERATOR
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_is_comparison_operator // Argument Name : as_source, Arg Type : String, Pass By : Value // Return Type : Boolean /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Determines whether a string contains only Comparison // Operator characters. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_count = 0 Long ll_length Char lc_char[] Integer li_ascii //Check parameters If IsNull(as_source) Then Boolean lb_null SetNull(lb_null) Return lb_null End If //Get the length ll_length = Len (as_source) //Check for at least one character If ll_length = 0 Then Return False End If //Move string into array of chars lc_char = as_source //Perform loop around all characters //Quit loop if Non Operator character is found Do While ll_count < ll_length ll_count ++ //Get ASC code of character. li_ascii = Asc (lc_char[ll_count]) If li_ascii = 60 Or /* < less than */ & li_ascii = 61 Or /* = equal */ & li_ascii = 62 Then /* > greater than */ //Character is an Comparison Operator. //Continue with the next character. Else Return False End If Loop // Entire string is made of Comparison Operators. Return True |
F_PARSE_TO_ARRAY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_parse_to_array // Argument Name : as_source, Arg Type : String, Pass By : Value // as_delimiter, Arg Type : String, Pass By : Value // as_array[], Arg Type : String, Pass By : Reference // Return Type : Long /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Parse a string into array elements using a delimeter string. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_DelLen Long ll_Pos Long ll_count Long ll_Start Long ll_length String ls_holder //Check for NULL If IsNull(as_source) Or IsNull(as_delimiter) Then Long ll_null SetNull(ll_null) Return ll_null End If //Check for at leat one entry If Trim (as_source) = '' Then Return 0 End If //Get the length of the delimeter ll_DelLen = Len(as_delimiter) ll_Pos = Pos(Upper(as_source), Upper(as_delimiter)) //Only one entry was found If ll_Pos = 0 Then as_Array[1] = as_source Return 1 End If //More than one entry was found - loop to get all of them ll_count = 0 ll_Start = 1 Do While ll_Pos > 0 //Set current entry ll_length = ll_Pos - ll_Start ls_holder = Mid (as_source, ll_Start, ll_length) // Update array and counter ll_count ++ as_Array[ll_count] = ls_holder //Set the new starting position ll_Start = ll_Pos + ll_DelLen ll_Pos = Pos(Upper(as_source), Upper(as_delimiter), ll_Start) Loop //Set last entry ls_holder = Mid (as_source, ll_Start, Len (as_source)) // Update array and counter if necessary If Len (ls_holder) > 0 Then ll_count++ as_Array[ll_count] = ls_holder End If //Return the number of entries found Return ll_count |
F_IS_ALPHA_NUM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_is_alpha_num // Argument Name : as_source, Arg Type : String, Pass By : Value // Return Type : Boolean /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Determines whether a string contains only alphabetic and // numeric characters. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_count = 0 Long ll_length Char lc_char[] Integer li_ascii //Check parameters If IsNull(as_source) Then Boolean lb_null SetNull(lb_null) Return lb_null End If //Get the length ll_length = Len (as_source) //Check for at least one character If ll_length = 0 Then Return False End If //Move string into array of chars lc_char = as_source //Perform loop around all characters. //Quit loop if Non Alphanemeric character is found. Do While ll_count < ll_length ll_count ++ //Get ASC code of character. li_ascii = Asc (lc_char[ll_count]) // '0'= 48, '9'=57, 'A'=65, 'Z'=90, 'a'=97, 'z'=122 If li_ascii < 48 Or (li_ascii > 57 And li_ascii < 65) Or & (li_ascii > 90 And li_ascii < 97) Or li_ascii > 122 Then /* Character is Not an AlphaNumeric */ Return False End If Loop // Entire string is AlphaNumeric. Return True |
F_IS_ARITHMETIC_OPERATOR
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_is_arithmetic_operator // Argument Name : as_source, Arg Type : String, Pass By : Value // Return Type : Boolean /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Description: Determines whether a string contains only Arithmetic // Operator characters. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_count = 0 Long ll_length Char lc_char[] Integer li_ascii //Check parameters If IsNull(as_source) Then Boolean lb_null SetNull(lb_null) Return lb_null End If //Get the length ll_length = Len (as_source) //Check for at least one character If ll_length = 0 Then Return False End If //Move string into array of chars lc_char = as_source //Perform loop around all characters //Quit loop if Non Operator character is found Do While ll_count ll_count ++ //Get ASC code of character. li_ascii = Asc (lc_char[ll_count]) If li_ascii = 40 Or /* ( left parenthesis */ & li_ascii = 41 Or /* ) right parenthesis */ & li_ascii = 43 Or /* + addition */ & li_ascii = 45 Or /* - subtraction */ & li_ascii = 42 Or /* * multiplication */ & li_ascii = 47 Or /* / division */ & li_ascii = 94 Then /* ^ power */ //Character is an operator. //Continue with the next character. Else Return False End If Loop // Entire string is made of arithmetic operators. Return True |
F_DATAWINDOW_COPY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_datawindow_copy // Argument Name : adw_1, Arg Type : datawindow, Pass By : Value // adw_2, Arg Type : datawindow, Pass By : Reference // Return Type : (None) /////////////////////////////////////////////////////////////////////////////////////////////////////////////// String ls_dwcopy String ls_type String ls_name String ls_count Datawindowchild ldw_child Integer li_count Integer li_index Integer li_rc //accept text on datawindow about to be copied adw_1.AcceptText() //clear out the destination adw_2.Reset() //This section is not needed if the destination does not contain child datawindows. ls_count = adw_2.Object.DataWindow.column.count li_count = Integer (ls_count) For li_index = 1 To li_count ls_type = adw_2.Describe("#" + String(li_index) + ".edit.style") If ls_type = "dddw" Then ls_name = adw_2.Describe("#" + String(li_index) + ".name") li_rc = adw_2.GetChild(ls_name , ldw_child) If li_rc = -1 Then MessageBox("Error on DWC Retreive",String(li_rc)) Else ldw_child.SetTransObject(sqlca) ldw_child.Retrieve() End If End If Next //put the data portion of source datawindow into a string adw_1.RowsCopy(1, adw_1.RowCount(), Primary!, adw_2, 1, Primary!) |
F_PARSE_DS_OBJ_STRING
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_parse_ds_obj_string // Argument Name : dw_arg, Arg Type : datastore, Pass By : Reference // obj_list[], Arg Type : String, Pass By : Reference // obj_type, Arg Type : String, Pass By : Value // band, Arg Type : String, Pass By : Value // Return Type : Integer /////////////////////////////////////////////////////////////////////////////////////////////////////////////// String obj_string String obj_holder Integer obj_count Integer start_pos = 1 Integer tab_pos Integer count obj_string = dw_arg.Describe("datawindow.objects") tab_pos = Pos(obj_string,"~t",start_pos) Do While tab_pos > 0 obj_holder = Mid(obj_string,start_pos,(tab_pos - start_pos)) If (dw_arg.Describe(obj_holder+".type") = obj_type Or obj_type = "*") And & (dw_arg.Describe(obj_holder+".band") = band Or band = "*") Then count = count + 1 obj_list[count] = obj_holder End If start_pos = tab_pos + 1 tab_pos = Pos(obj_string,"~t",start_pos) Loop obj_holder = Mid(obj_string,start_pos,Len(obj_string)) If (dw_arg.Describe(obj_holder+".type") = obj_type Or obj_type = "*") And & (dw_arg.Describe(obj_holder+".band") = band Or band = "*") Then count = count + 1 obj_list[count] = obj_holder End If Return count |
F_MAIL_ERROR_TO_STRING
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_mail_error_to_string // Argument Name : a_mailreturncode, Arg Type : mailreturncode, Pass By : Value // a_message, Arg Type : String, Pass By : String // a_display, Arg Type : Boolean, Pass By : Boolean // Return Type : String /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // a_Message Error message to prepend to return string // a_Display Boolean (TRUE=display error messagebox) /////////////////////////////////////////////////////////////////////////////////////////////////////////////// String s Choose Case a_MailReturnCode Case mailReturnAccessDenied! s = 'Access Denied' Case mailReturnAttachmentNotFound! s = 'Attachment Not Found' Case mailReturnAttachmentOpenFailure! s = 'Attachment Open Failure' Case mailReturnAttachmentWriteFailure! s = 'Attachment Write Failure' Case mailReturnDiskFull! s = 'Disk Full' Case mailReturnFailure! s = 'Failure' Case mailReturnInsufficientMemory! s = 'Insufficient Memory' Case mailReturnInvalidMessage! s = 'Invalid Message' Case mailReturnLoginFailure! s = 'Login Failure' Case mailReturnMessageInUse! s = 'Message In Use' Case mailReturnNoMessages! s = 'No Messages' Case mailReturnSuccess! s = 'Success' Case mailReturnTextTooLarge! s = 'Text Too Large' Case mailReturnTooManyFiles! s = 'Too Many Files' Case mailReturnTooManyRecipients! s = 'Too Many Recipients' Case mailReturnTooManySessions! s = 'Too Many Sessions' Case mailReturnUnknownRecipient! s = 'Unknown Recipient' Case mailReturnUserAbort! s = 'User Abort' Case Else s = 'Other' End Choose If a_Display Then MessageBox ( 'Mail Return Code', a_Message + ' ' + s, Exclamation!) End If Return s |
F_GET_TOOLBAR_INDEXES
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_get_toolbar_indexes // Argument Name : am_source, Arg Type : Menu, Pass By : Value // ai_index[], Arg Type : Integer, Pass By : Reference // Return Type : Integer /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Arguments: // am_Source The menu whose indexes are wanted. // ai_Index[] Array to hold all unique toolbar indexes found. // // Returns: integer // The number of indexes found or -1 if an error occurs. // // Description: Get all the toolbar indexes for the menu associated // with a window. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Integer li_Limit Integer li_Cnt Integer li_ToolbarItembarindex Boolean lb_Found // Check if this item has a toolbar If Len(am_Source.ToolbarItemName) > 0 Then If am_Source.ToolbarItemBarIndex > 0 Then // Check if it has already been added to the array li_Limit = UpperBound(ai_Index) lb_Found = False For li_Cnt = 1 To li_Limit If ai_Index[li_Cnt] = am_Source.ToolbarItemBarIndex Then lb_Found = True Next // If not in array, add it If Not lb_Found Then ai_Index[li_Limit + 1] = am_Source.ToolbarItemBarIndex End If End If // Search through the rest of the menu li_Limit = UpperBound (am_Source.Item) For li_Cnt = 1 To li_Limit f_get_toolbar_indexes(am_Source.Item[li_Cnt], ai_Index) Next Return UpperBound(ai_Index) |
F_GET_TOKEN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_get_token // Argument Name : source, Arg Type : String, Pass By : Reference // separator, Arg Type : String, Pass By : Value // Return Type : String /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // String Function GET_TOKEN (ref string Source, string Separator) // // The function Get_Token receive, as arguments, the string from which // the token is to be stripped off, from the left, and the separator // character. If the separator character does not appear in the string, // it returns the entire string. Otherwise, it returns the token, not // including the separator character. In either case, the source string // is truncated on the left, by the length of the token and separator // character, if any. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Integer p String ret p = Pos(Source, separator) // Get the position of the separator If p = 0 Then // if no separator, ret = Source // return the whole source string and Source = "" // make the original source of zero length Else ret = Mid(Source, 1, p - 1) // otherwise, return just the token and Source = Right(Source, Len(Source) - p) // strip it & the separator End If Return ret |
F_CLOSEST_DATE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_closest_date // Argument Name : as_dayname, Arg Type : String, Pass By : Value // ad_testdate, Arg Type : Date, Pass By : Value // Return Type : Date // // Purpose: returns the date that is the closest day name (as_dayname) // to as_testdate /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Arguments: as_dayname a valid name of a day (Sunday, Monday, ...) // ad_testdate any valid date // // Returns: date the date which is: // 1) the closest date to as_test date AND // 2) which has the same day name as as_dayname /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Integer li_testdate Integer li_dayname Integer li_difference // Obtain the day number of ad_testdate and as_dayname li_testdate = DayNumber (ad_testdate) Choose Case as_dayname Case 'Sunday' li_dayname = 1 Case 'Monday' li_dayname = 2 Case 'Tuesday' li_dayname = 3 Case 'Wednesday' li_dayname = 4 Case 'Thursday' li_dayname = 5 Case 'Friday' li_dayname = 6 Case 'Saturday' li_dayname = 7 End Choose // If ad_testdate is already the same day name as as_dayname, then // return ad_testdate, else calculate the closest date. If li_dayname = li_testdate Then Return ad_testdate Else li_difference = li_dayname - li_testdate If li_difference < -3 Then li_difference = li_difference + 7 Else If li_difference > 3 Then li_difference = li_difference - 7 End If End If Return RelativeDate (ad_testdate, li_difference) End If |
F_SET_ACTIVE_DIRECTORY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_set_active_directory // Argument Name : as_path, Arg Type : String, Pass By : Value // Return Type : (None) /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Local External Functions : // Function boolean SetCurrentDirectoryA (string lpPathName) Library "kernel32.dll" /////////////////////////////////////////////////////////////////////////////////////////////////////////////// String ls_temp ULong lul_value Boolean lb_rc lb_rc = SetCurrentDirectoryA(as_path) |
F_GET_ACTIVE_DIRECTORY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_get_active_directory // Argument Name : (None) // Return Type : String /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Local External Functions : // Function boolean GetCurrentDirectoryA (long nBufferLength, ref string lpBuffer) // Library "kernel32.dll" /////////////////////////////////////////////////////////////////////////////////////////////////////////////// String ls_temp ULong lul_value Boolean lb_rc lul_value = 255 ls_temp = Space (255) lb_rc = GetCurrentDirectoryA (lul_value, ls_temp) Return ls_temp |
F_GET_COMPUTER_NAME
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_get_computer_name // Argument Name : (None) // Return Type : String /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Local External Functions : // Function boolean GetComputerNameA (ref String lpBuffer, ref ulong nSize) // Library "kernel32.dll" /////////////////////////////////////////////////////////////////////////////////////////////////////////////// String ls_temp ULong lul_value Boolean lb_rc lul_value = 255 ls_temp = Space(255) lb_rc = GetComputerNameA (ls_temp, lul_value) Return ls_temp |
F_PLAY_SOUND
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_play_sound // Argument Name : (None) // Return Type : (None) /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Function Long sndPlaySound (String lpszSoundName, Long uFlags) Library "winmm.dll" Alias For "sndPlaySoundA" // Function Long waveOutGetNumDevs() Library "winmm.dll" Alias For "waveOutGetNumDevs" /////////////////////////////////////////////////////////////////////////////////////////////////////////////// UInt lui_NumDevs UInt ll_modeofplay lui_NumDevs = WaveOutGetNumDevs() If lui_NewDevs > 0 Then sndPlaySound ("filename.wav", ll_modeofplay) End If |
F_GET_USER_NAME
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_get_user_name // Argument Name : (None) // Return Type : String /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Local External Functions : // Function Long GetUserName (ref String lpBuffer, Long nSize) Library "advapi32.dll" Alias For "GetUserNameA" /////////////////////////////////////////////////////////////////////////////////////////////////////////////// String ls_login_name String ls_temp ULong lul_value Boolean lb_rc lul_value = 255 ls_temp = Space (255) lb_rc = GetUserName(ls_temp, lul_value) ls_login_name = Trim(ls_temp) Return ls_login_name |
F_GET_WINDOWS_DIRECTORY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_get_windows_directory // Argument Name : (None) // Return Type : String /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Local External Functions : // Function Long GetWindowsDirectory (ref String lpBuffer, Long nSize) Library "kernel32" Alias For "GetWindowsDirectoryA" /////////////////////////////////////////////////////////////////////////////////////////////////////////////// String ls_WinPath ls_WinPath = Space (128) GetWindowsDirectory (ls_WinPath, 128) Return ls_WinPath |
F_GET_NAME_AND_PATH_APPLICATION
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_get_name_and_path_application // Argument Name : (None) // Return Type : String /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Local External Functions : // Function Long GetModuleFileName (Long hModule, ref String lpFileName, Long nSize) Library 'kernel32.dll' Alias For GetModuleFileNameA ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// String ls_AppPath String ls_FullPath String ls_Exe Integer li_Return Integer li_Pos ls_FullPath = Space (255) li_Return = GetModuleFileNameA (Handle (GetApplication ()), ls_FullPath, 255) If li_Return > 0 Then Do While (Pos (ls_FullPath, "\", li_Pos + 1) > 0) li_Pos = Pos (ls_FullPath, "\", li_Pos + 1) Loop ls_AppPath = Mid (ls_FullPath, 1, li_Pos - 1) ls_Exe = Mid (ls_FullPath, li_Pos + 1) End If Return ls_AppPath |
F_COPY_DATASTORE_TO_EXCEL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_copy_datastore_to_excel // Argument Name : apo_dwo, Arg Type : PowerObject, Pass By : Value // Return Type : Integer /////////////////////////////////////////////////////////////////////////////////////////////////////////////// DataWindow ldw_control datastore lds_control Integer li_i OleObject obj_excel_appl OleObject obj_excel_workbook If apo_dwo.TypeOf() = DataWindow! Then ldw_control = apo_dwo li_i = ldw_control.SaveAs('', Clipboard!, True) ElseIf apo_dwo.TypeOf() = datastore! Then lds_control = apo_dwo li_i = lds_control.SaveAs('', Clipboard!, True) Else MessageBox('Error', 'Invalid Object.', Exclamation!) li_i = -1 End If If li_i = 1 Then obj_excel_appl = Create OleObject If obj_excel_appl.ConnectToObject('', 'excel.application') = 0 Then obj_excel_workbook = obj_excel_appl.Workbooks.Add() obj_excel_appl.ActiveSheet.Paste() MessageBox('Done', 'Data is copied to workbook "' + & String(obj_excel_workbook.Name) + & '"', information!) Else MessageBox('Error', 'Ms Excel is not running.', Exclamation!) li_i = -1 End If Destroy obj_excel_appl End If Return li_i |
F_GET_COLOR_SYSTEM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_get_color_system // Argument Name : (none) // Return Type : Long /////////////////////////////////////////////////////////////////////////////////////////////////////////////// String ls_Value String ls_Color Integer li_pos1 Integer li_pos2 Long ll_r Long ll_g Long ll_b Long ll_Color /*Constant System Color SCROLLBAR BACKGROUND ACTIVETITLE INACTIVETITLEMENU WINDOW WINDOWFRAME MENUTEXT WINDOWTEXT TITLETEXT ACTIVEBORDER INACTIVEBORDER APPWORKSPACE HILIGHT HILIGHTTEXT BUTTONFACE BUTTONSHADOW GRAYTEXT BUTTONTEXT INACTIVETITLETEXT BUTTONHILIGHT BUTTONDKSHADOW BUTTONLIGHT INFOTEXT INFOWINDOW BUTTONALTERNATEFACE HOTTRACKINGCOLOR GRADIENTACTIVETITLE GRADIENTINACTIVETITLE */ ls_Color = "BUTTONFACE" If RegistryGet("HKEY_CURRENT_USER\Control Panel\Colors", ls_Color, RegString!, ls_Value) > 0 Then li_pos1 = Pos(ls_Value, ' ', 1) ll_r = Long(Mid(ls_Value,1,li_pos1 - 1)) li_pos2 = Pos(ls_Value, ' ', li_pos1 + 1) ll_g = Long(Mid(ls_Value,li_pos1 + 1, li_pos2 - li_pos1)) ll_b = Long(Mid(ls_Value, li_pos2)) ll_Color = RGB(ll_r, ll_g, ll_b) End If Return ll_Color |
F_PARSE_TO_ARRAY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_parse_to_array // Argument Name : as_source, Arg Type : String, Pass By : Value // as_delimiter, Arg Type : String, Pass By : Value // as_array[], Arg Type : String, Pass By : Reference // Return Type : Long /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Parse a string into array elements using a delimeter string. // // Arguments: // as_Source The string to parse. // as_Delimiter The delimeter string. // as_Array[] The array to be filled with the parsed strings, passed by reference. // // Returns: long // The number of elements in the array. // If as_Source or as_Delimeter is NULL, function returns NULL. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_DelLen Long ll_Pos Long ll_count Long ll_Start Long ll_length String ls_holder //Check for NULL If IsNull(as_source) Or IsNull(as_delimiter) Then Long ll_null SetNull(ll_null) Return ll_null End If //Check for at leat one entry If Trim (as_source) = '' Then Return 0 End If //Get the length of the delimeter ll_DelLen = Len(as_delimiter) ll_Pos = Pos(Upper(as_source), Upper(as_delimiter)) //Only one entry was found If ll_Pos = 0 Then as_Array[1] = as_source Return 1 End If //More than one entry was found - loop to get all of them ll_count = 0 ll_Start = 1 Do While ll_Pos > 0 //Set current entry ll_length = ll_Pos - ll_Start ls_holder = Mid (as_source, ll_Start, ll_length) // Update array and counter ll_count ++ as_Array[ll_count] = ls_holder //Set the new starting position ll_Start = ll_Pos + ll_DelLen ll_Pos = Pos(Upper(as_source), Upper(as_delimiter), ll_Start) Loop //Set last entry ls_holder = Mid (as_source, ll_Start, Len (as_source)) // Update array and counter if necessary If Len (ls_holder) > 0 Then ll_count++ as_Array[ll_count] = ls_holder End If //Return the number of entries found Return ll_count |
F_GLOBAL_REPLACE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_global_replace // Argument Name : as_source, Arg Type : String, Pass By : Value // as_old, Arg Type : String, Pass By : Value // as_new, Arg Type : String, Pass By : Value // ab_ignorecase, Arg Type : Boolean, Pass By : Value // Return Type : String /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Replace all occurrences of one string inside another with // a new string. // // Arguments: // as_Source The string being searched. // as_Old The old string being replaced. // as_New The new string. // ab_IgnoreCase A boolean stating to ignore case sensitivity. // // Returns: string // as_Source with all occurrences of as_Old replaced with as_New. // If any argument's value is NULL, function returns NULL. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_Start Long ll_OldLen Long ll_NewLen String ls_Source //Check parameters If IsNull(as_source) Or IsNull(as_old) Or IsNull(as_new) Or IsNull(ab_ignorecase) Then String ls_null SetNull(ls_null) Return ls_null End If //Get the string lenghts ll_OldLen = Len(as_old) ll_NewLen = Len(as_new) //Should function respect case. If ab_ignorecase Then as_old = Lower(as_old) ls_Source = Lower(as_source) Else ls_Source = as_source End If //Search for the first occurrence of as_Old ll_Start = Pos(ls_Source, as_old) Do While ll_Start > 0 // replace as_Old with as_New as_source = Replace(as_source, ll_Start, ll_OldLen, as_new) //Should function respect case. If ab_ignorecase Then ls_Source = Lower(as_source) Else ls_Source = as_source End If // find the next occurrence of as_Old ll_Start = Pos(ls_Source, as_old, (ll_Start + ll_NewLen)) Loop Return as_source |
F_ARRAYTOSTRING
///////////////////////////////////////////////////////////////////////////////////////////////////////////// //
// Function Name : f_arraytostring
// Argument Name : as_source[], Arg Type : String, Pass By : Value
// as_delimiter, Arg Type : String, Pass By : Value
// as_ref_string, Arg Type : String, Pass By : Reference
// Return Type : Long
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Description: Create a single string from an array of strings separated by
// the passed delimeter.
// Note: Function will not include on the single string any
// array entries which match an empty string.
//
// Arguments:
// as_source[] The array of string to be moved into a single string.
// as_Delimiter The delimeter string.
// as_ref_string The string to be filled with the array of strings,
// passed by reference.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Long ll_count
Long ll_ArrayUpBound
//Get the array size
ll_ArrayUpBound = UpperBound(as_source[])
//Check parameters
If IsNull(as_delimiter) Or (Not ll_ArrayUpBound > 0) Then
Return -1
End If
//Reset the Reference string
as_ref_string = ”
For ll_count = 1 To ll_ArrayUpBound
//Do not include any entries that match an empty string
If as_source[ll_count] <> ” Then
If Len(as_ref_string) = 0 Then
//Initialize string
as_ref_string = as_source[ll_count]
Else
//Concatenate to string
as_ref_string = as_ref_string + as_delimiter + as_source[ll_count]
End If
End If
Next
Return 1
F_DISTINCTVALUES
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : f_distinctvalues // Argument Name : as_table, Arg Type : String, Pass By : Value // as_table_dddw, Arg Type : String, Pass By : Value // as_column, Arg Type : String, Pass By : Value // as_dispcolumn, Arg Type : String, Pass By : Value // as_values[], Arg Type : String, Pass By : Reference // as_dispvalues[], Arg Type : String, Pass By : Reference // Return Type : (None) /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Get the distinct values from the database // // Arguments: // as_table: a SQL table name // as_column: a database column name in passed SQL table // as_values: string array, passed by reference to hold the returned values /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_rc String ls_sqlstatement String ls_Value String ls_dispvalue String ls_name // Build the SQL Select statement ls_sqlstatement = "SELECT DISTINCT " + as_column + "," +as_dispcolumn+ " FROM " + as_table + & "," + as_table_dddw + " WHERE " + as_column +" = "+ as_table_dddw + Mid(as_column,Pos(as_column,".")) // Execute the SQL Prepare sqlsa From :ls_sqlstatement; Describe sqlsa Into sqlda; Declare c_values_cursor Dynamic Cursor For sqlsa; Open Dynamic c_values_cursor Using Descriptor sqlda; Fetch c_values_cursor Using Descriptor sqlda; ll_rc = sqlca.SQLCode // Retrieve the distinct values and add them to the array Do While sqlca.SQLCode = 0 Choose Case sqlda.OutParmType[1] Case TypeString! ls_Value = GetDynamicString (sqlda, 1) Case TypeDate! ls_Value = String (GetDynamicDate (sqlda, 1)) Case TypeTime! ls_Value = String (GetDynamicTime (sqlda, 1)) Case TypeDateTime! ls_Value = String (GetDynamicDateTime (sqlda, 1)) Case Else ls_Value = String (GetDynamicNumber (sqlda, 1)) End Choose Choose Case sqlda.OutParmType[2] Case TypeString! ls_dispvalue = GetDynamicString (sqlda, 2) Case TypeDate! ls_dispvalue = String (GetDynamicDate (sqlda, 2)) Case TypeTime! ls_dispvalue = String (GetDynamicTime (sqlda, 2)) Case TypeDateTime! ls_dispvalue = String (GetDynamicDateTime (sqlda, 2)) Case Else ls_dispvalue = String (GetDynamicNumber (sqlda, 2)) End Choose as_values[UpperBound(as_values)+1] = ls_Value as_dispvalues[UpperBound(as_dispvalues)+1] = ls_dispvalue Fetch c_values_cursor Using Descriptor sqlda; ll_rc = sqlca.SQLCode Loop Close c_values_cursor; |
F_CREATE_SHORTCUT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | // Function Name : f_create_shortcut // Argument Name : (None) // Return Type : (None) OleObject ws OleObject loo_shortcut String ls_Desktop ws = Create OleObject ws.ConnectToNewObject(" WScript.Shell") ls_Desktop = ws.SpecialFolders("Desktop") // other "specialfolder" of interest // AllUsersDesktop // AllUsersStartMenu // AllUsersPrograms // AllUsersStartup // Desktop // Favorites // MyDocuments // Programs // Recent // SendTo // StartMenu // Startup loo_shortcut = ws.CreateShortcut(ls_Desktop + "\googlecom.lnk") loo_shortcut.TargetPath = "https://www.google.com.vn/" loo_shortcut.WorkingDirectory = ls_Desktop loo_shortcut.WindowStyle = 1 /* 1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. 3 Activates the window and displays it as a maximized window. 7 Minimizes the window and activates the next top-level window. */ loo_shortcut.IconLocation = ws.ExpandEnvironmentStrings("%WINDIR%\SYSTEM\url.dll,0") |
F_WAIT_TO_RUN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // Function Name : f_wait_to_run // Argument Name : (None) // Return Type : (None) OleObject ole_wsh Integer li_connect Constant Integer NORMAL = 1 Constant Integer MINIMIZED = 2 Constant Integer MAXIMIZED = 3 /* 0 Hides the window and activates another window. 1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. 2 Activates the window and displays it as a minimized window. 3 Activates the window and displays it as a maximized window. 4 Displays a window in its most recent size and position. The active window remains active. 5 Activates the window and displays it in its current size and position. 6 minimizes the specified window and activates the next top-level window in the Z order. 7 Displays the window as a minimized window. The active window remains active. 8 Displays the window in its current state. The active window remains active. 9 Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. 10 Sets the show state based on the state of the program that started the application. */ Constant Boolean WAIT = True Constant Boolean NOWAIT = False wsh = Create OleObject li_connect = wsh.ConnectToNewObject("WScript.Shell") li_connect = wsh.Run("Notepad", NORMAL, WAIT) MessageBox("Wait To Run", "I am Standing behind you.....") |
F_CALL_VBSCRIPT
1 2 3 4 5 6 7 8 9 10 11 12 13 | // Function Name : f_call_vbscript // Argument Name : (None) // Return Type : (None) OleObject ole_wsh Integer li_connect ole_wsh = Create OleObject li_connect = ole_wsh.ConnectToNewObject("MSScriptControl.ScriptControl") ole_wsh.language = "vbscript" ole_wsh.addcode("function retfnc (s) retfnc=s end function") ole_wsh.executestatement('if 1 > 1 then msgbox retfnc("true") else msgbox retfnc("false") end if') |
F_CALL_CALCULATOR_AND_SENDKEYS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // Function Name : f_call_calculator_and_sendkeys // Argument Name : (None) // Return Type : (None) Integer li_connect OleObject ole_wsh ole_wsh = Create OleObject li_connect = ole_wsh.ConnectToNewObject("WScript.Shell") ole_wsh.Run("calc") ole_wsh.AppActivate("Calculator", 100) Sleep(1000) ole_wsh.SendKeys("3{-}") Sleep(1000) ole_wsh.SendKeys("1") Sleep(1000) ole_wsh.SendKeys("=") Sleep(1000) ole_wsh.SendKeys("*4") Sleep(1000) ole_wsh.SendKeys("=") // 3 - 1 = 2 Then * 4 = 8 |
F_GET_DOMAIN_AND_USERNAME_COMPUTERNAME
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // Function Name : f_get_domain_and_username_and_computername // Argument Name : as_Domain, Arg Type : string, Pass By : Reference // as_UserName, Arg Type : string, Pass By : Reference // as_ComputerName, Arg Type : string, Pass By : Reference // Return Type : (None) Integer li_connect OleObject ole_wsh ole_wsh = Create OleObject li_connect = ole_wsh.ConnectToNewObject("WScript.Network") If li_connect = 0 Then as_Domain = ole_wsh.UserDomain as_UserName = ole_wsh.UserName as_ComputerName = ole_wsh.computername End If |
F_CALL_NOTEPAD_AND_SENDKEYS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // Function Name : f_call_notepad_and_sendkeys // Argument Name : (None) // Return Type : (None) Integer li_connect OleObject ole_wsh ole_wsh = Create OleObject li_connect = ole_wsh.ConnectToNewObject("WScript.Shell") ole_wsh.Run("Notepad") ole_wsh.AppActivate("Untitled - Notepad") Sleep(500) ole_wsh.SendKeys("Powerbuilder Functions") |
F_SET_ZOOM_DATAWINDOW
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | // Function Name : f_set_zoom_datawindow // Argument Name : apo_control, Arg Type : powerobject, Pass By : Value // as_size, Arg Type : string, Pass By : Value // Return Type : (None) DataWindow ldw_control Datawindowchild ldwc_control datastore lds_control Choose Case TypeOf( apo_control ) Case DataWindow! ldw_control = apo_control ldw_control.Modify('DataWindow.Zoom=' + as_size) Case Datawindowchild! ldwc_control = apo_control ldwc_control.Modify('DataWindow.Zoom=' + as_size) Case datastore! lds_control = apo_control lds_control.Modify('DataWindow.Zoom=' + as_size) Case Else // invalid argument type Return False End Choose Return True |
F_CREATE_DYNAMIC_DATAWINDOW
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // Function Name : f_create_dynamic_datawindow // Argument Name : adw_control, Arg Type : Datawindow, Pass By : Reference // Return Type : (None) String ls_select String ls_where String ls_order_by String ls_dwsyntax String ls_err ls_select = "Select customer_id, companyname, contactname From Customers" ls_where = " Where region IS NOT NULL" ls_order_by = " order by customerid" ls_dwsyntax = sqlca.SyntaxFromSQL(ls_select + ls_where + ls_order_by, "Style(Type=grid) ", ls_err) adw_control.Create ( ls_dwsynta, ls_err) If ls_err <> '' Then MessageBox("Error - Syntax", ls_err) Else adw_control.SetTransObject(sqlca) adw_control.Retrieve() End If |
F_GET_ALL_COLUMN_NAME
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // Function Name : f_get_all_column_name // Argument Name : adw_control, Arg Type : Datawindow, Pass By : Value // as_colname[], Arg Type : String, Pass By : Reference // Return Type : (None) Integer li_i Integer numCols numCols = Integer(adw_control.Describe("Datawindow.Column.Count")) For li_i = 1 To numCols //Get Column Name With Describe as_colName[li_i] = adw_control.Describe("#" + String(li_i) + ".Name") Next |
F_GET_DUPLICATE_ROW
1 2 3 4 5 6 7 8 9 | // Function Name : f_get_duplicate_row // Argument Name : adw_control, Arg Type : Datawindow, Pass By : Reference // Return Type : (None) adw_control.SetSort('Column_Name A') adw_control.Sort() adw_control.SetFilter('Column_Name = Column_Name[1] Or Column_Name = Column_Name[-1]') adw_control.Filter() |
F_GET_PRINTER_LIST
1 2 3 4 5 6 7 8 | // Function Name : f_get_printer_list // Argument Name : as_printers[], Arg Type : String, Pass By : Reference // Return Type : (None) Integer li_Return li_Return = RegistryKeys("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers", as_printers) |
F_CONVERT_FILE_TO_BLOB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | // Function Name : f_convert_file_to_blob // Return Type : Blob Integer li_FileNo Integer li_Reads Integer li_i Integer li_value Long ll_FileLen Blob lblb_temp String ls_docname String ls_named li_value = GetFileOpenName("Select File", ls_docname, ls_named, " ", "All Files (*.*), *.*") If li_value <> 1 Then Return li_FileNo = FileOpen(ls_docname, StreamMode!, Read!) If li_FileNo < 0 Then Return ll_FileLen = FileLength(ls_docname) //////////////////////////////////////////////////////////////////////////////////////// // //Determine the number of reads required to read the entire file ////////////////////////////////////////////////////////////////////////////////////////// If ll_FileLen > 32765 Then If Mod(ll_FileLen, 32765) = 0 Then li_Reads = ll_FileLen / 32765 Else li_Reads = (ll_FileLen / 32765) + 1 End If Else li_Reads = 1 End If For li_i = 1 To li_Reads If FileRead(li_FileNo, lblb_temp) = -1 Then Return ablb_data = ablb_data + lblb_temp Next FileClose(li_FileNo) Return ablb_data |
F_GET_ALL_SELECTED_ROW
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | // Function Name : f_get_all_selected_row // Argument Name : adw_control, Arg Type : Datawindow, Pass By : Value // al_row[], Arg Type : Long, Pass By : Reference // Return Type : Integer // Purpose: Returns the selected rows of a DataWindow into an array // // Scope: public // // Description : adw_control the DataWindow control that has rows selected // al_row[] an array of type long passed by reference that will contain // the row numbers of the selected rows in the DataWindow // // Returns: long the number of selected rows in the DataWindow Long ll_row Long ll_selected_count Long ll_index = 1 ll_row = adw_control.GetSelectedRow (0) If ll_row = 0 Then // If no rows are selected, return zero Return 0 Else // Loop through the DataWindow rows and add each row number that is selected to the array. Do al_row[ll_index] = ll_row ll_index++ ll_row = adw_control.GetSelectedRow (ll_row) Loop While ll_row > 0 Return ll_index - 1 End If |
F_WORDCAP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | //Function Name : f_wordcap //Argument Name : as_source, Arg Type : String, Pass By : Value //Return Type : String // Returns string with the first letter of each word set to // uppercase and the remaining letters lowercase if it succeeds // and NULL if an error occurs. // If any argument's value is NULL, function returns NULL. // // Description: Sets the first letter of each word in a string to a capital // letter and all other letters to lowercase (for example, // POWERBUILDER FUNCTION would be Powerbuilder Function). Integer li_Pos Boolean lb_capnext String ls_ret Long ll_stringlength Char lc_char Char lc_string[] //Check parameters If IsNull(as_source) Then String ls_null SetNull(ls_null) Return ls_null End If //Get and check length ll_stringlength = Len(as_source) If ll_stringlength = 0 Then Return as_source End If //Convert all characters to lowercase and put it into Character Array lc_string = Lower(as_source) //The first character should be capitalized lb_capnext = True //Loop through the entire string For li_Pos = 1 To ll_stringlength //Get one character at a time lc_char = lc_string[li_Pos] If Not f_IsAlpha(lc_char) Then //The next character should be capitalized lb_capnext = True ElseIf lb_capnext Then //Capitalize this Alphabetic character lc_string[li_Pos] = Upper(lc_char) //The next character should not be capitalized lb_capnext = False End If Next //Copy the Character array back to a string variable ls_ret = lc_string //Return the Return ls_ret |
F_CONVERT_DECIMAL_TO_STRING
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | //Function Name : f_convert_decimal_to_string //Argument Name : adec_value, Arg Type : decimal, Pass By : Value //Return Type : String //Example : adec_value = 5.5000 //Return : "5.5" Long ll_value_temp, ll_value_decimal, ll_Pos String ls_Value If adec_value = 0 Then Return "0" ll_value_temp = Truncate(adec_value, 0) ll_value_decimal = (adec_value - ll_value_temp) * 10000 ll_Pos = 5 If Mid(String(ll_value_decimal), 4, 1) = "0" Then ll_Pos = 4 If Mid(String(ll_value_decimal), 3, 1) = "0" Then ll_Pos = 3 If Mid(String(ll_value_decimal), 2, 1) = "0" Then ll_Pos = 2 If Mid(String(ll_value_decimal), 1, 1) = "0" Then ll_Pos = 1 End If End If End If End If If ll_value_decimal = 0 Then ll_Pos = 1 If ll_Pos - 1 = 0 Then ls_Value = String(ll_value_temp) Else ls_Value = String(ll_value_temp) + "." + Left(String(ll_value_decimal), ll_Pos - 1) End If Return ls_Value |
F_WINDOW_CENTER
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | //Function Name : f_window_center //Argument Name : aw_wnd, Arg Type : window, Pass By : ReadOnly //Return Type : (None) Int li_screenheight, li_screenwidth, li_x = 1, li_y = 1 environment lenv_obj If IsNull(aw_wnd) Or Not IsValid(aw_wnd) Then Return If GetEnvironment( lenv_obj ) = -1 Then Return li_screenheight = PixelsToUnits ( lenv_obj.ScreenHeight, YPixelsToUnits! ) li_screenwidth = PixelsToUnits ( lenv_obj.ScreenWidth, XPixelsToUnits! ) If Not li_screenheight > 0 Or Not li_screenwidth > 0 Then Return If li_screenwidth > aw_wnd.Width Then li_x = ( li_screenwidth / 2 ) - ( aw_wnd.Width / 2 ) End If If li_screenheight > aw_wnd.Height Then li_y = ( li_screenheight / 2 ) - ( aw_wnd.Height / 2 ) End If aw_wnd.Move( li_x, li_y ) Return |
F_IS_ALPHABET
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | //Function Name : f_Is_Alphabet //Argument Name : as_source, Arg Type : String, Pass By : Value //Return Type : Boolean // True if the string only contains alphabetic characters. // If any argument's value is NULL, function returns NULL. // //Description: Determines whether a string contains only alphabetic // characters. Long ll_count = 0 Long ll_length Char lc_char[] Integer li_ascii //Check parameters If IsNull(as_source) Then Boolean lb_null SetNull(lb_null) Return lb_null End If //Get the length ll_length = Len (as_source) //Check for at least one character If ll_length = 0 Then Return False End If //Move string into array of chars lc_char = as_source //Perform loop around all characters //Quit loop if Non Alpha character is found Do While ll_count ll_count ++ //Get ASC code of character. li_ascii = Asc (lc_char[ll_count]) // 'A'=65, 'Z'=90, 'a'=97, 'z'=122 If li_ascii < 65 Or (li_ascii > 90 And li_ascii < 97) Or li_ascii > 122 Then /* Character is Not an Alpha */ Return False End If Loop // Entire string is alpha. Return True |
F_GET_ALPHABET_AND_NUMBER
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | //Function Name : f_get_alphabet_and_number //Argument Name : as_source, Arg Type : String, Pass By : Value //Return Type : String //Example : AT-123-456 //Return : AT123456 Char lc_char[] Int i, li_ascii String ls_return lc_char = as_source For i = 1 To Len(as_source) //Get ASC code of character. li_ascii = Asc (lc_char[i]) If (li_ascii >= 65 And li_ascii <= 90) Or (li_ascii >= 97 And li_ascii <= 122) Or & IsNumber(Mid(as_source, i, 1)) Then ls_return += String(lc_char[i]) End If Next Return ls_return |
F_GET_ALPHABET
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | //Function Name : f_get_alphabet //Argument Name : as_source, Arg Type : String, Pass By : Value //Return Type : String //Example : AT-123-456 //Return : AT Char lc_char[] Int i, li_ascii String ls_return lc_char = as_source For i = 1 To Len(as_source) //Get ASC code of character. li_ascii = Asc (lc_char[i]) If (li_ascii >= 65 And li_ascii <= 90) Or (li_ascii >= 97 And li_ascii <= 122) Then ls_return += String(lc_char[i]) End If Next Return ls_return |
F_GET_NUMBER
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | //Function Name : f_get_number //Argument Name : as_source, Arg Type : String, Pass By : Value //Return Type : String //Example : AT-123-456 //Return : 123456 Char lc_char[] Int i, li_ascii String ls_return lc_char = as_source For i = 1 To Len(as_source) //Get ASC code of character. li_ascii = Asc (lc_char[i]) If IsNumber(Mid(as_source, i, 1)) Then ls_return += String(lc_char[i]) End If Next Return ls_return |
F_EXPORT_TO_EXCEL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | //Function Name : f_export_to_excel //Argument Name : as_path, Arg Type : string, Pass By : Value //Return Type : [None] //Init docname //GetFileOpenName or any other method OleObject Excel If dw_1.SaveAs(as_path + ".xls", HTMLTable!, True) = -1 Then MessageBox("Warning", "Unable to export data. Error writing to file!", Exclamation!) Return End If //Convert HTML file to Excel native format Excel = Create OleObject If Excel.ConnectToObject(as_path + ".xls") = 0 Then Excel.Application.DisplayAlerts = False Excel.Application.workbooks(1).Parent.Windows(Excel.Application.workbooks(1).Name).Visible = True Excel.Application.workbooks(1).SaveAs(as_path + ".xls", 39) Excel.Application.workbooks(1).Close() End If Destroy Excel |
F_SET_DEFAULT_PRINTER
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | //Function Name : f_set_default_printer //Argument Name : as_printername, Arg Type : String, Pass By : Value //Return Type : Integer Integer li_rc, li_i, li_rtn, li_nbPrinters String ls_PrinterName[], ls_PrinterName1[], ls_PrinterName2[] Boolean lb_PrinterName n_cst_string lnv_string OleObject ole_wsh ole_wsh = Create OleObject li_rc = ole_wsh.ConnectToNewObject("WScript.Network") If li_rc = 0 Then li_rtn = RegistryKeys("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers", ls_PrinterName1) If li_rtn = -1 Then Destroy ole_wsh MessageBox("Information", "Error Registry Keys : HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers", information!) Return -1 End If For li_i = 1 To UpperBound(ls_PrinterName1) ls_PrinterName1[li_i] = lnv_string.of_GlobalReplace(ls_PrinterName1[li_i], ",", "\") ls_PrinterName[UpperBound(ls_PrinterName) + 1] = ls_PrinterName1[li_i] Next li_rtn = RegistryKeys("HKEY_CURRENT_USER\Printers\Connections", ls_PrinterName2) If li_rtn = -1 Then Destroy ole_wsh MessageBox("Information", "Error Registry Keys : HKEY_CURRENT_USER\Printers\Connections", information!) Return -1 End If For li_i = 1 To UpperBound(ls_PrinterName2) ls_PrinterName2[li_i] = lnv_string.of_GlobalReplace(ls_PrinterName2[li_i], ",", "\") ls_PrinterName[UpperBound(ls_PrinterName) + 1] = ls_PrinterName2[li_i] Next li_nbPrinters = UpperBound(ls_PrinterName) For li_i = 1 To li_nbPrinters If ls_PrinterName[li_i] = as_PrinterName Then lb_PrinterName = True Exit End If Next If lb_PrinterName Then ole_wsh.SetDefaultPrinter(as_PrinterName) Else Destroy ole_wsh Return -1 End If End If Destroy ole_wsh Return 1 |
Good Luck! collection from internet