1. duyanning
  2. womacs

Commits

duyanning  committed 73754a0

refactor C-u and frmUniArg

  • Participants
  • Parent commits be00632
  • Branches default

Comments (0)

Files changed (5)

File develop_src/EmacsLikeCommands.bas

View file
 
 
 
-Public num_arg As Integer  ' numeric argument
-Public self_ins_text As String
+Public num_arg As Long  ' numeric argument
+' template to process num_arg
 '    While num_arg < 0
 '        do_a()
 '
 End Sub
 Sub forward_word()
 'M-f
+'    While num_arg < 0
+'        do_a()
+'
+'        num_arg = num_arg + 1
+'    Wend
+'
+
+'    While num_arg > 0
+'
+'        num_arg = num_arg - 1
+'    Wend
+
     If mark_set Then
         Selection.MoveRight Unit:=wdWord, Count:=num_arg, Extend:=wdExtend
     Else
 Sub universal_argument()
 'C-u
     frmUniArg.Show
+    
+    If frmUniArg.get_quit_reason() = dqrCancel Then
+        Unload frmUniArg
+        Exit Sub
+    End If
+    
     ' deal with self insert command
-    If self_ins_text <> "" Then
+    'Dim num_arg_value As Long
+    Dim self_ins_string As String
+    
+    frmUniArg.get_two_parts num_arg, self_ins_string
+    
+    'num_arg = num_arg_value
+    
+    If self_ins_string <> "" Then
         While num_arg > 0
-            Selection.TypeText Text:=self_ins_text
+            Selection.TypeText Text:=self_ins_string
 
             num_arg = num_arg - 1
         Wend
         num_arg = 1
     End If
+    
+    Unload frmUniArg
 End Sub
 
 

File develop_src/frmISearch.frx

Binary file modified.

File develop_src/frmUniArg.frm

View file
 ' womacs
 Option Explicit
 
-Dim num_arg_value As Long
-Dim self_ins_string As String
+'Dim num_arg_value As Long
+'Dim self_ins_string As String
 
-'    Dim raw_input
-'    Dim space_pos As Long
-'    Dim num_arg_part
-'    Dim self_ins_part
-'    Dim prompt As String
-'
-'    prompt = "usage:" & vbCrLf & _
-'                vbTab & "N [string_to_insert]"
-'
-'    raw_input = LTrim(InputBox(prompt, "universal argument"))
-'    Debug.Print raw_input
-'
-'    space_pos = InStr(raw_input, " ")
-'    Debug.Assert (space_pos = 0 Or space_pos > 1)
-'
-'    If space_pos > 1 Then
-'        num_arg_part = Left(raw_input, space_pos - 1)
-'        self_ins_part = Mid(raw_input, space_pos + 1)
-'    Else
-'        num_arg_part = raw_input
-'        self_ins_part = ""
-'    End If
-'
-'    If num_arg_part = "" Then
-'        num_arg = 4
-'    Else
-'        num_arg = num_arg_part
-'    End If
-'
-'    Debug.Print num_arg
-'
-'    ' deal with self insert command
-'    If self_ins_part <> "" Then
-'        While num_arg > 0
-'            Selection.TypeText Text:=self_ins_part
-'
-'            num_arg = num_arg - 1
-'        Wend
-'        num_arg = 1
-'    End If
+Public Enum DialogQuitReason
+    dqrCancel
+    dqrEnter
+End Enum
 
 
-Sub get_two_parts()
+Dim quit_reason As DialogQuitReason
+
+
+Function get_quit_reason() As DialogQuitReason
+    get_quit_reason = quit_reason
+End Function
+
+
+Sub get_two_parts(num_arg_value As Long, self_ins_string As String)
     '������ֽ�Ϊǰ�������֣�ǰ������ֵ���֣�������Բ����ַ�������
     Dim raw_input As String
     raw_input = tbInput.Text
 
 
 Sub inc_arg_num()
-    get_two_parts
+    Dim num_arg_value As Long
+    Dim self_ins_string As String
+    
+    get_two_parts num_arg_value, self_ins_string
     num_arg_value = num_arg_value * 4
+    
     Dim num_arg_part As String
     num_arg_part = LTrim(str(num_arg_value))
+    
     tbInput.Text = num_arg_part & " " & self_ins_string
 End Sub
 
 
 Sub when_key_down(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
     If KeyCode = vbKeyReturn Then
-        get_two_parts
-        num_arg = num_arg_value
-        self_ins_text = self_ins_string
-        Unload Me
+        quit_reason = dqrEnter
+        Me.hide
         Exit Sub
     End If
 
         '�رնԻ���
     Select Case KeyCode
     Case vbKeyG
-        num_arg = 0
-        self_ins_text = ""
-        Unload Me
+        quit_reason = dqrEnter
+        Me.hide
     Case vbKeyU
         inc_arg_num
     Case Else

File develop_src/frmUniArg.frx

Binary file modified.

File develop_src/test.bas

View file
 End Sub
 
 
+Function foobar(t As String, i As Long) As String
+    't = "xyz"
+    i = 99
+    foobar = t
+End Function
+
+
+Sub test_return()
+    Dim s As String
+    s = "abc"
+    Dim ss As String
+    Dim i As Long
+    i = 2
+    ss = foobar(s, i)
+    ss = "xyz"
+End Sub