home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 November / VPR9811A.BIN / VPR_DATA / Program / Vb / FormMain.frm next >
Text File  |  1998-08-31  |  9KB  |  277 lines

  1. VERSION 5.00
  2. Begin VB.Form FormMain 
  3.    BorderStyle     =   1  '固定(実線)
  4.    Caption         =   "FormMain"
  5.    ClientHeight    =   6465
  6.    ClientLeft      =   585
  7.    ClientTop       =   1140
  8.    ClientWidth     =   9195
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   6465
  13.    ScaleWidth      =   9195
  14.    Begin VB.CommandButton CommandCopy 
  15.       Caption         =   "Copy"
  16.       Height          =   375
  17.       Left            =   8040
  18.       TabIndex        =   4
  19.       Top             =   5400
  20.       Width           =   1095
  21.    End
  22.    Begin VB.CommandButton CommandPaste 
  23.       Caption         =   "Paste"
  24.       Height          =   375
  25.       Left            =   8040
  26.       TabIndex        =   3
  27.       Top             =   960
  28.       Width           =   1095
  29.    End
  30.    Begin VB.CommandButton CommandDataGenerate 
  31.       Caption         =   "データ作成"
  32.       Height          =   375
  33.       Left            =   8040
  34.       TabIndex        =   2
  35.       Top             =   2040
  36.       Width           =   1095
  37.    End
  38.    Begin VB.TextBox TextMain 
  39.       BeginProperty Font 
  40.          Name            =   "MS ゴシック"
  41.          Size            =   9
  42.          Charset         =   128
  43.          Weight          =   400
  44.          Underline       =   0   'False
  45.          Italic          =   0   'False
  46.          Strikethrough   =   0   'False
  47.       EndProperty
  48.       Height          =   3495
  49.       Left            =   120
  50.       MultiLine       =   -1  'True
  51.       ScrollBars      =   2  '垂直
  52.       TabIndex        =   1
  53.       Top             =   2880
  54.       Width           =   7815
  55.    End
  56.    Begin VB.TextBox TextSource 
  57.       BeginProperty Font 
  58.          Name            =   "MS ゴシック"
  59.          Size            =   9
  60.          Charset         =   128
  61.          Weight          =   400
  62.          Underline       =   0   'False
  63.          Italic          =   0   'False
  64.          Strikethrough   =   0   'False
  65.       EndProperty
  66.       Height          =   2655
  67.       Left            =   120
  68.       MultiLine       =   -1  'True
  69.       ScrollBars      =   2  '垂直
  70.       TabIndex        =   0
  71.       Top             =   120
  72.       Width           =   7815
  73.    End
  74. End
  75. Attribute VB_Name = "FormMain"
  76. Attribute VB_GlobalNameSpace = False
  77. Attribute VB_Creatable = False
  78. Attribute VB_PredeclaredId = True
  79. Attribute VB_Exposed = False
  80.  
  81. '改行ごとに切り分ける
  82. Function StrCrLf(ByVal sourceStr As String, ByRef distStr As String, ByVal strPntOld As Integer) As Integer
  83.     Dim strPointer As Integer
  84.     
  85.     If sourceStr = "" Then
  86.         StrCrLf = -1    '文字列が空なら-1を返す
  87.         Exit Function
  88.     End If
  89.     strPointer = InStr(strPntOld + 1, sourceStr, vbCrLf)
  90.     
  91.     If strPointer > 0 Then
  92.         strPointer = strPointer - 1 '末尾が改行なら、改行分ポインターを前にずらす
  93.     Else
  94.         strPointer = Len(sourceStr) '文字列の末尾に改行がないなら、文字変数の末尾にポインターを置く
  95.     End If
  96.     If strPointer >= strPntOld Then  'ポインターが正常なら、現在行の文字列を切り取る
  97.         distStr = Mid(sourceStr, strPntOld + 1, strPointer - strPntOld)
  98.     Else
  99.         StrCrLf = -1    '異常、あるいは文字変数の末尾までチェック済みなら、-1を返す
  100.         Exit Function
  101.     End If
  102.     StrCrLf = strPointer + 2    'ポインターを改行分だけ後ろにずらす
  103. End Function
  104. '改行コード直前にある、不可視コードを削除
  105. Function RemoveLineLastSpace(TextSource As String) As String
  106.     Dim ptr As Long
  107.     Dim strBuf As String
  108.     
  109.     ptr = Len(TextSource)
  110.     Do While ptr > 0
  111.         Select Case Mid(TextSource, ptr, 1)
  112.             Case " ", " ", vbTab
  113.                 ptr = ptr - 1
  114.             Case Else
  115.                 Exit Do
  116.         End Select
  117.     Loop
  118.     RemoveLineLastSpace = Left(TextSource, ptr)
  119. End Function
  120. '行頭にある、不可視コードを削除
  121. Function RemoveLineFirstSpace(TextSource As String) As String
  122.     Dim ptrLast As Long
  123.     Dim ptr As Long
  124.     Dim strBuf As String
  125.     
  126.     ptrLast = Len(TextSource)
  127.     ptr = 1
  128.     Do While ptr < ptrLast
  129.         Select Case Mid(TextSource, ptr, 1)
  130.             Case " ", " ", vbTab
  131.                 ptr = ptr + 1
  132.             Case Else
  133.                 Exit Do
  134.         End Select
  135.     Loop
  136.     RemoveLineFirstSpace = Right(TextSource, ptrLast - ptr + 1)
  137. End Function
  138. '1行が指定文字数以上の単一の文字で埋められているかどうか
  139. Function CheckUnificationCharactor(TextSource As String, valLimit As Integer) As Boolean
  140.     Dim ptr As Long
  141.     Dim strDistination As String
  142.     
  143.     If Len(TextSource) < valLimit Then
  144.         CheckUnificationCharactor = False
  145.         Exit Function
  146.     End If
  147.     
  148.     strDistination = ""
  149.     For ptr = 0 To valLimit - 1
  150.         strDistination = strDistination + Right(TextSource, 1)
  151.     Next ptr
  152.     CheckUnificationCharactor = (Right(TextSource, 10) = strDistination)
  153.  
  154. End Function
  155. 'データ作成
  156. Private Sub CommandDataGenerate_Click()
  157.     Dim sourceText As String
  158.     Dim distText As String
  159.     Dim pointText As Integer
  160.     Dim pointNew As Integer
  161.     Dim bufText As String
  162.     Dim lineBufText As String
  163.     Dim tempText As String
  164.     Dim flgAddCrLfBef As Boolean
  165.     Dim flgAddCrLfPre As Boolean
  166.     Dim flgAddCrLfPost As Boolean
  167.     Dim strCond1(10) As String
  168.     Dim strCond2(10) As String
  169.     Dim strCond3(10) As String
  170.     Dim booFS As Boolean
  171.     Dim booCR As Boolean
  172.     Dim booURL As Boolean
  173.     Dim booChar As Boolean
  174.     Dim valChar As Integer
  175.     
  176.     sourceText = TextSource.Text
  177.     
  178.     pointText = 0
  179.     lineBufText = ""
  180.     flgAddCrLfBef = True
  181.     FormPref.getPref strCond1, strCond2, strCond3, booFS, booCR, booURL, booChar, valChar
  182.        
  183.     Do
  184.         '一行取り出し
  185.         pointNew = StrCrLf(sourceText, distText, pointText)
  186.         If pointNew = -1 Then Exit Do
  187.         pointText = pointNew
  188.         flgAddCrLfPre = False
  189.         flgAddCrLfPost = False
  190.         
  191.         lineBufText = RemoveLineLastSpace(distText)
  192.         
  193.         If booFS Then
  194.             lineBufText = RemoveLineFirstSpace(lineBufText)
  195.         End If
  196.         
  197.         '改行だけの行
  198.         '改行だけの行を付加
  199.         If booCR And (distText = "") Then
  200.             flgAddCrLfPost = True
  201. '            flgAddCrLfPre = True
  202.         End If
  203.         
  204.         tempText = Left(distText, 1)
  205.         '特定の文字が行頭の時に、前の行の行末に改行を付加
  206.         '" ", " ", "■", "★", "▼", "○", "●", "※", vbTab
  207.         '直前が改行だった場合は、改行を付加しない
  208.         Select Case tempText
  209.             Case strCond1(0), strCond1(1), strCond1(2), strCond1(3), strCond1(4), strCond1(5), strCond1(6), strCond1(7), strCond1(8)
  210.                 flgAddCrLfPre = True
  211.         End Select
  212.         
  213.         '特定の文字が行頭の時に、行末に改行を付加
  214.         '">", ">", "■", "★", "▼", "○", "●":
  215.         Select Case tempText
  216.              Case strCond3(0), strCond3(1), strCond3(2), strCond3(3), strCond3(4), strCond3(5), strCond3(6)
  217.                 flgAddCrLfPost = True
  218.         End Select
  219.         
  220.         '特定の文字が行末の時に、行末に改行を付加
  221.         '"。", ".", "."    ")", ")", "」", ">", ">":
  222.         Select Case Right(distText, 1)
  223.             Case strCond2(0), strCond2(1), strCond2(2), strCond2(3), strCond2(4), strCond2(5), strCond2(6), strCond2(7)
  224.                 flgAddCrLfPost = True
  225.         End Select
  226.         
  227.         '一行が単一の文字で埋められている場合
  228.         If booChar And CheckUnificationCharactor(lineBufText, valChar) Then
  229.             flgAddCrLfPost = True
  230.         End If
  231.         
  232.         'URLの場合
  233.         If booURL And ("http://" = Left(lineBufText, 7)) Then
  234.             flgAddCrLfPost = True
  235.         End If
  236.         
  237.         '改行の付加
  238.         If flgAddCrLfPre And (Not flgAddCrLfBef) Then
  239.             bufText = bufText + vbCrLf
  240.         End If
  241.         bufText = bufText + lineBufText
  242.         flgAddCrLfBef = False
  243.         If flgAddCrLfPost Then
  244.             bufText = bufText + vbCrLf
  245.             flgAddCrLfBef = True
  246.         End If
  247.     Loop
  248.     
  249.     TextMain.Text = bufText
  250.  
  251. End Sub
  252.  
  253. Private Sub CommandCopy_Click()
  254.     Clipboard.SetText TextMain.Text
  255.  
  256. End Sub
  257. 'クリップボードからペースト
  258. Private Sub CommandPaste_Click()
  259.     TextSource.Text = Clipboard.GetText
  260.     
  261. End Sub
  262.  
  263. Private Sub Form_Load()
  264.     Top = GetSetting(App.Title, Me.Name, "Top", 0)
  265.     Left = GetSetting(App.Title, Me.Name, "Left", 0)
  266.     FormMain.Caption = App.Title
  267.     FormPref.Show
  268.     
  269. End Sub
  270.  
  271. Private Sub Form_Unload(Cancel As Integer)
  272.     SaveSetting App.Title, Me.Name, "Top", Top
  273.     SaveSetting App.Title, Me.Name, "Left", Left
  274.     Unload FormPref
  275.     
  276. End Sub
  277.