n_xls_subroutines.sru 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. $PBExportHeader$n_xls_subroutines.sru
  2. forward
  3. global type n_xls_subroutines from nonvisualobject
  4. end type
  5. end forward
  6. global type n_xls_subroutines from nonvisualobject
  7. end type
  8. global n_xls_subroutines n_xls_subroutines
  9. type variables
  10. public n_cst_unicode invo_uc
  11. end variables
  12. forward prototypes
  13. public function blob of_pack (character ac_conv_type, unsignedlong al_val)
  14. public function blob of_pack_hex (string as_val)
  15. public function blob of_pack (character ac_conv_type, double ad_val)
  16. public function string of_str2xls (string as_str)
  17. public function string to_ansi (blob ab_value)
  18. public function string to_ansi (blob ab_value, unsignedinteger ai_codepage)
  19. public function string to_ansi (blob ab_value, unsignedinteger ai_codepage, character ac_defaultchar)
  20. public function blob to_unicode (string as_value)
  21. public function blob to_unicode (string as_value, unsignedinteger ai_codepage)
  22. end prototypes
  23. public function blob of_pack (character ac_conv_type, unsignedlong al_val);ulong ll_val
  24. char lc_val
  25. integer li_byte_count
  26. integer li_i
  27. blob{10} lblb_val
  28. choose case ac_conv_type
  29. case "v", "V", "C", "c"
  30. choose case ac_conv_type
  31. case "v"
  32. li_byte_count = 2
  33. case "V"
  34. li_byte_count = 4
  35. case "C", "c"
  36. li_byte_count = 1
  37. if al_val < 0 then
  38. al_val = 256 - mod(al_val, 129)
  39. end if
  40. end choose
  41. ll_val = al_val
  42. for li_i = 1 to li_byte_count
  43. blobedit(lblb_val, li_i, char(mod(ll_val, 256)))
  44. ll_val = ll_val / 256
  45. next
  46. case else
  47. messagebox("Error", "Invalid argument type in of_pack('" + ac_conv_type + "', ulong)")
  48. end choose
  49. return blobmid(lblb_val, 1, li_byte_count)
  50. end function
  51. public function blob of_pack_hex (string as_val);blob lblb_val
  52. blob{100} lblb_buff
  53. integer li_buff_size = 100
  54. integer li_buff_pos = 1
  55. integer li_i
  56. integer li_cnt
  57. string ls_str[2]
  58. integer li_j
  59. integer li_val
  60. setnull(lblb_val)
  61. li_cnt = len(as_val)
  62. lblb_buff=blob(space(li_buff_size))
  63. for li_i = 1 to li_cnt step 2
  64. if li_i = li_cnt then
  65. ls_str[1] = "0"
  66. ls_str[2] = mid(as_val, li_i, 1)
  67. else
  68. ls_str[1] = mid(as_val, li_i, 1)
  69. ls_str[2] = mid(as_val, li_i + 1, 1)
  70. end if
  71. li_val = 0
  72. for li_j = 1 to 2
  73. li_val = li_val * 16
  74. choose case ls_str[li_j]
  75. case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
  76. li_val += integer(ls_str[li_j])
  77. case "A"
  78. li_val = li_val + 10
  79. case "B"
  80. li_val = li_val + 11
  81. case "C"
  82. li_val = li_val + 12
  83. case "D"
  84. li_val = li_val + 13
  85. case "E"
  86. li_val = li_val + 14
  87. case "F"
  88. li_val = li_val + 15
  89. end choose
  90. next
  91. blobedit(lblb_buff, li_buff_pos, char(li_val))
  92. li_buff_pos ++
  93. if li_buff_pos = li_buff_size then
  94. if isnull(lblb_val) then
  95. lblb_val = lblb_buff
  96. else
  97. lblb_val = lblb_val + lblb_buff
  98. end if
  99. li_buff_pos = 1
  100. end if
  101. next
  102. if li_buff_pos > 1 then
  103. if isnull(lblb_val) then
  104. lblb_val = lblb_buff
  105. else
  106. lblb_val = lblb_val + lblb_buff
  107. end if
  108. end if
  109. return lblb_val
  110. end function
  111. public function blob of_pack (character ac_conv_type, double ad_val);blob{8} lb_ret
  112. Int li
  113. if ac_conv_type = "d" then
  114. li=blobedit(lb_ret, 1, ad_val)
  115. else
  116. messagebox("Error", "Invalid argument type in of_pack('" + ac_conv_type + "', double)")
  117. end if
  118. IF li>0 Then
  119. lb_ret= BlobMid(lb_ret, 1, li -1 )
  120. ELSE
  121. lb_ret=Blob("")
  122. END IF
  123. return lb_ret
  124. end function
  125. public function string of_str2xls (string as_str);long ll_pos
  126. ll_pos = pos(as_str, char(13)+"~n")
  127. do while ll_pos > 0
  128. as_str = replace(as_str, ll_pos, 2, "~n")
  129. ll_pos = pos(as_str, char(13)+"~n")
  130. loop
  131. ll_pos = pos(as_str, char(13))
  132. do while ll_pos > 0
  133. as_str = replace(as_str, ll_pos, 2, "~n")
  134. ll_pos = pos(as_str, char(13))
  135. loop
  136. return as_str
  137. end function
  138. public function string to_ansi (blob ab_value);return invo_uc.of_unicode2ansi(ab_value)
  139. end function
  140. public function string to_ansi (blob ab_value, unsignedinteger ai_codepage);return invo_uc.of_unicode2ansi(ab_value,ai_codepage)
  141. end function
  142. public function string to_ansi (blob ab_value, unsignedinteger ai_codepage, character ac_defaultchar);return invo_uc.of_unicode2ansi(ab_value,ai_codepage,ac_defaultchar)
  143. end function
  144. public function blob to_unicode (string as_value);RETURN invo_uc.of_ansi2unicode(as_value)
  145. end function
  146. public function blob to_unicode (string as_value, unsignedinteger ai_codepage);return invo_uc.of_ansi2unicode(as_value,ai_codepage)
  147. end function
  148. on n_xls_subroutines.create
  149. call super::create
  150. TriggerEvent( this, "constructor" )
  151. end on
  152. on n_xls_subroutines.destroy
  153. TriggerEvent( this, "destructor" )
  154. call super::destroy
  155. end on