ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý]¥HByte¬°³æ¦ì±N¦r¦ê¤©¥H°µ©î¤À¡A½Ð°ÝVBA­n¦p¦ó³B²z¡H

[µo°Ý]¥HByte¬°³æ¦ì±N¦r¦ê¤©¥H°µ©î¤À¡A½Ð°ÝVBA­n¦p¦ó³B²z¡H

¦r¦êªºªø«×¬O 120 ­Ó Bytes
¦pªG­n¨C60­Ó Bytes ­n°µ¤@­Ó¦r¦ê

´ú¸Õ¦r¦ê¦p¤U¡A¦@¬° 120 ­Ó Bytes
³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1

¥Øªº¬O­n©î¤À¦¨
³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1
³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1

¦ý¬O¥Î VBA ¼g¥X¨Ó·|Åܦ¨
³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1
³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1
³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1


VBA»~»{¬°
60=15(¤¤¤å¦r)*2+15(­^¤å¦r¤]·|Åܦ¨2­ÓByte)*2
60=15(¤¤¤å¦r)*2+15(­^¤å¦r¤]·|Åܦ¨2­ÓByte)*2
40=10(¤¤¤å¦r)*2+10(­^¤å¦r¤]·|Åܦ¨2­ÓByte)*2

¹ê»Ú¤W ¥»¤Hªº»{ª¾¬O
45=15(¤¤¤å¦r)*2+15*1
45=15(¤¤¤å¦r)*2+15*1
30=10(¤¤¤å¦r)*2+10*1

µo°Ý¤º®e.zip (10.14 KB)

¥»©«³Ì«á¥Ñ Baracuda ©ó 2013-4-4 23:08 ½s¿è
  1. Option Explicit
  2. Option Base 1
  3. Const Max_Length = 60

  4. Const Test_String = "³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1"
  5. ' 30  ªø«× "³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1"
  6. ' 120 ªø«× "³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1"

  7. Sub main()
  8.     Call Process_Over_Length_XX_Byte(Test_String)
  9. End Sub

  10. Sub Process_Over_Length_XX_Byte(Stg_Input As String)
  11. ' ±N©Ò¿é¤Jªº¦r¦ê¡A¦pªG¶W¹L60­Ó Byte «á¡A¤©¥H¤À¬° N¦C  , Max_Length =60
  12. Dim Total_Char_Byte As Integer, Total_Line_Output As Integer, i As Integer, CountDown_No As Integer
  13. Dim First_Max_Length_Stg As String, Tmp_Integer As Integer

  14.     Total_Char_Byte = LenB(Stg_Input)
  15.     Total_Line_Output = 1 + Int(Total_Char_Byte / Max_Length)
  16.     ' Á`¦@¦³´X­Ó Line ­n³B²z                   Max_Length = 60
  17.     CountDown_No = Total_Line_Output
  18.    
  19.     For i = 1 To Total_Line_Output
  20.         If CountDown_No = 1 Then
  21.         ' ¦pªG¬O³Ì«á¤@¦C®É¡A§Y¬O³Ì«á¤@¦¸¿é¥X
  22.             Debug.Print (Stg_Input)
  23.             Exit Sub
  24.         Else
  25.         ' ¦pªG¤£¬O³Ì«á¤@¦C®É¡ACountDown_No ªº¼Æ¦r§Y´î 1
  26.             CountDown_No = CountDown_No - 1
  27.             First_Max_Length_Stg = LeftB(Stg_Input, Max_Length) 'Max_Length = 60
  28.             Tmp_Integer = LenB(First_Max_Length_Stg)
  29.             Debug.Print First_Max_Length_Stg
  30.             Stg_Input = RightB(Stg_Input, LenB(Stg_Input) - Max_Length)
  31.             ' ±N¦r¦ê¤©¥H­«¸m¡A¥h°£«e¤è60 ­Ó¦r¤¸                              Max_Length = 60
  32.             Tmp_Integer = LenB(Stg_Input)
  33.         End If
  34.     Next i
  35. End Sub
½Æ»s¥N½X
Option Explicit
Option Base 1
Const Max_Length = 60

Const Test_String = "³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1"
' 30  ªø«× "³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1"
' 120 ªø«× "³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1³ü1¶L1°Ñ1¥|1¥î1³°1¤C1®Ã1¨h1¬B1"

Sub main()
    Call Process_Over_Length_XX_Byte(Test_String)
End Sub

Sub Process_Over_Length_XX_Byte(Stg_Input As String)
' ±N©Ò¿é¤Jªº¦r¦ê¡A¦pªG¶W¹L60­Ó Byte «á¡A¤©¥H¤À¬° N¦C  , Max_Length =60
Dim Total_Char_Byte As Integer, Total_Line_Output As Integer, i As Integer, CountDown_No As Integer
Dim First_Max_Length_Stg As String, Tmp_Integer As Integer

    Total_Char_Byte = LenB(Stg_Input)
    Total_Line_Output = 1 + Int(Total_Char_Byte / Max_Length)
    ' Á`¦@¦³´X­Ó Line ­n³B²z                   Max_Length = 60
    CountDown_No = Total_Line_Output
   
    For i = 1 To Total_Line_Output
        If CountDown_No = 1 Then
        ' ¦pªG¬O³Ì«á¤@¦C®É¡A§Y¬O³Ì«á¤@¦¸¿é¥X
            Debug.Print (Stg_Input)
            Exit Sub
        Else
        ' ¦pªG¤£¬O³Ì«á¤@¦C®É¡ACountDown_No ªº¼Æ¦r§Y´î 1
            CountDown_No = CountDown_No - 1
            First_Max_Length_Stg = LeftB(Stg_Input, Max_Length) 'Max_Length = 60
            Tmp_Integer = LenB(First_Max_Length_Stg)
            Debug.Print First_Max_Length_Stg
            Stg_Input = RightB(Stg_Input, LenB(Stg_Input) - Max_Length)
            ' ±N¦r¦ê¤©¥H­«¸m¡A¥h°£«e¤è60 ­Ó¦r¤¸                              Max_Length = 60
            Tmp_Integer = LenB(Stg_Input)
        End If
    Next i
End Sub

TOP

ªþ¤Wµ{¦¡¤º®e¥H§K¦³µLªk¤U¸üªº°ÝÃD

TOP

¦^´_ 3# Baracuda
³Ìª½±µªº¤èªk¬O§PÂ_¦r¤¸½X¨Ó¨M©w¦r¤¸ªº¦ì¤¸¼Æ
  1. Sub ex()
  2. Dim k&, t%, i%, c%, s%
  3. k = Len(Test_String)
  4. t = 1
  5. Do Until i = k
  6.    Do Until s = Max_Length
  7.    i = i + 1
  8.    c = Asc(Mid(Test_String, i, 1))
  9.    s = s + IIf(c >= 0 And c <= 255, 1, 2) '§PÂ_¦r¤¸½X¬O§_¬°ASCII,¬O«h¦r¤¸ªº¦ì¤¸¼Æ¬°1§_«h¬°2
  10.    Loop
  11.    MsgBox Mid(Test_String, t, i - t + 1)
  12.    t = i + 1
  13.    s = 0
  14. Loop
  15. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦³´ú¸Õ¹L¡AÃä¬É­È·|¦³°ÝÃD

Bug ·|²£¥Íªº±¡ªp
­n¸ó¹L Max_Length ®É¡A¥¿¦n¹J¨ì¤¤¤åor¥þ«¬¦r¡C

Ex:
Max_Length=4
³ü1¶L1°Ñ1

³ü1¶L ¹ê»Ú¬O5­Ó Byte
Do Until s = Max_Length
¦]¬°¦pªG

TOP

Hsieh ª©¥D
³o­Ó¸ò§Ú­ì¨Ó·Qªº°µªk¡A¤è¦¡¤j­P¬Û¦P¡C
·Q»¡¬Ý¦³µL¤ñ¸û¦nªº¤èªk°µ¡C
³o¼Ë¬Ý¨Ó¦³¨Ç¥Î¡u¼É¤O¡v¸ÑÃD¡C
¬Ý¨Ó VBA ¤]¨S¦³¨ä¥L¨ç¼Æ¤ñ¸û¦n¥Î¡C
[­è«öªº¤Ó§Ö]
Ex:
Max_Length=4
³ü1¶L1°Ñ1

³ü1¶L ¹ê»Ú¬O5­Ó Byte
Do Until s = Max_Length
³o¼Ë·|¸ó¹L¤@­Ó¦r¡C

ª©¥D¡A³o­Ó Bug §Ú·Q§Ú¥i¥H¦Û¦æ¸Ñ¨M¡C
¦pªG¦³·sªº VBA Defalult Function ªº¸Ü¡A¦A§i¶D¡C

TOP

  1. Const Contatenate_Char = "_"
  2. Const Max_Length = 78
  3. '================================´ú¸Õ¤º®e========================================================================
  4. 'Hsiehª©¥D´ú¸Õ¤º®e¡A·|¦³ Bug
  5. '³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6
  6. '¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2


  7. '180="³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0"
  8. 'Max_Length = 78
  9. '³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°
  10. '_6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0³ü1
  11. '_¶L2°Ñ3¥|4¥î5³°6¤C7®Ã8¨h9¬B0

  12. Sub main()
  13.         Call Process_Over_Length_XX(Test_String)
  14. End Sub

  15. Function If_ASCII_Stg(Stg_Test As String) As Boolean
  16. ' ´ú¸Õ¦r¤¸½X¬O§_¬°ASCII ¡A¦pªG¬O >= 0 ¥B <= 255 ®É¡A«h¬° ASCII
  17. ' ¦ý¬O¦r¤¸ªø«×¤j©ó 1®É¡Aµ{¦¡·|§ì²Ä1­Ó¦r¤¸°µ§PÂ_
  18.     If Asc(Stg_Test) >= 0 And Asc(Stg_Test) <= 255 Then
  19.         If_ASCII_Stg = True
  20.     Else
  21.         If_ASCII_Stg = False
  22.     End If
  23. End Function

  24. Sub Process_Over_Length_XX(Stg_Input As String)
  25. Dim Total_Pesudo_Char_Byte As Integer
  26. Dim Skip_1_or_2 As Byte, Current_Stg_Process_Position As Integer
  27. Dim Current_Stg As String, Ctr As Integer, Ctr_I As Integer
  28. Dim Counter_Stg_ProC_Bytes As Integer, Output_Stg As String
  29. Dim Line_1_Or_Not As Boolean
  30. Dim IS_ASCII_Boolean As Boolean

  31. ' ¦pªG¶W¹LN­Ó¦r®É¡A´N¤À«e¬qªº³¡¤À
  32. ' ==========   «Å§i¦r¦êÁ`ªø«×  & ¦r¦ê²{¦b³B²zªº¦ì¸m  ==========================
  33.     Total_Pesudo_Char_Byte = Len(Stg_Input): Ctr = 0: Ctr_I = 0             '¥ý³]©w¬°ªÅ¦r¦ê  & ¬°0
  34.     Current_Stg_Process_Position = 1: Current_Stg = "" '¥ý³]©w¬°ªÅ¦r¦ê  & ¬°0
  35.    
  36.     Do Until Ctr = Total_Pesudo_Char_Byte
  37.         Do Until Counter_Stg_ProC_Bytes >= Max_Length - 1 Or Ctr = Total_Pesudo_Char_Byte  ' ¦pªG¶W¹L Max Length ®É¡A´N­n¸õ¤U¤@­Ó¦r¤¸
  38.             Ctr = Ctr + 1
  39.             Current_Stg = Mid(Test_String, Ctr, 1) ' ¦V«e±À¶i 1­Ó¦r¤¸
  40.             IS_ASCII_Boolean = If_ASCII_Stg(Current_Stg)
  41.             Skip_1_or_2 = IIf(IS_ASCII_Boolean, 1, 2)   ' ­n Skip ´X­Ó Byte  ¦pªG ¦r¤¸½X¬OASCII,«h ¸õ¹L ¦ì¤¸¼Æ¬°1 §_«h¬°2
  42.             Counter_Stg_ProC_Bytes = Counter_Stg_ProC_Bytes + Skip_1_or_2
  43.             ' ²{¦b¦b¨º¤@­Ó String Byte ªº¦ì¸m
  44.             If Counter_Stg_ProC_Bytes >= Max_Length And Not IS_ASCII_Boolean Then
  45.             ' ¦pªG¤w¬O±µªñ¨C¦æªº (³Ì¤j¼Æ-1) ®É¡A­nª`·N¬O§_¦³ ¥¿¦n¹J¨ì¤¤¤åor¥þ«¬¦r¡A¨Ï±o¥[2«á¡A·|¶W¹L1­Ó¦r¡C
  46.                 Counter_Stg_ProC_Bytes = Max_Length: Ctr = Ctr - 1     '°h«á1­Ó¦r ±j¨î¸õ¥X¦^°é¡A¥H³B²zªºByte ±j¨î¤Æ¬°³Ì¤j­È
  47.             End If
  48.            
  49.         Loop
  50.         Output_Stg = Mid(Stg_Input, Current_Stg_Process_Position, Ctr - Current_Stg_Process_Position + 1)
  51.         Debug.Print (Output_Stg)
  52.         Current_Stg_Process_Position = Ctr + 1
  53.         Counter_Stg_ProC_Bytes = 0  ' ¤©¥HÂk 0
  54.     Loop
  55. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : «Î¼e¤£¦p¤ß¼e¡C
ªð¦^¦Cªí ¤W¤@¥DÃD