auto-group

Dim letters As Integer ‘声明模块级变量,此变量计算字母个数

Dim space As Integer ‘空格个数

Dim digit As Integer ‘数字个数

Dim others As Integer ‘其他字符个数

Function auto_level() As Integer

Dim space_num As Integer

Dim str1 As String

Dim begin_line As Integer

Dim end_line As Integer

Dim mid_line As Integer

begin_line = 0

end_line = 0

mid_line = 0

SumRows = Sheet1.UsedRange.Rows.Count

‘find the "echo"

For i = 1 To SumRows

str1 = Sheet1.Cells(i, 1)

str2 = Split(str1, " ")

j = UBound(str2)

For jj = 0 To j

If str2(jj) = "" Then

‘ do nothing

Else

‘MsgBox "comment of str2 is :" & str2(jj) & " jj is " & jj & " row " & i

If str2(jj) = "echo" Then

If begin_line = 0 Then

mid_line = begin_line

begin_line = i + 1

Else

If end_line = 0 Then

end_line = i - 1

Else

begin_line = end_line + 2

end_line = i - 1

End If

‘MsgBox "line number is " & begin_line & end_line & " i = " & i

Call recursion_group(begin_line + 1, end_line - 1)

End If

Exit For

End If

Exit For

End If

Next

‘MsgBox str2(1) & "  len of str2 is: " & j & " row " & i

Next

‘start recursion group the rows (i,j)

str1 = Sheet1.Cells(14, 1)

space_num = get_space_num(str1)

‘MsgBox "space_num is :" & space_num & "SumRows is " & SumRows

End Function

Sub auto_leve()

Call auto_level

End Sub

Function recursion_group(begin_lin As Integer, end_lin As Integer)

Dim begin_line As Integer

Dim end_line As Integer

Dim space_num1 As Integer

Dim space_num2 As Integer

Dim str1 As String

Dim i As Integer

begin_line = begin_lin

end_line = end_lin

str1 = ""

str1 = Sheet1.Cells(begin_line, 1)

space_num1 = get_space_num(str1)

For i = begin_line + 1 To end_line

str1 = Sheet1.Cells(i, 1)

space_num2 = get_space_num(str1)

If space_num1 = space_num2 Then

If i - begin_line > 1 Then

Call create_group1(begin_line + 1, i)

Call recursion_group(begin_line + 1, i - 1)

If i < end_line Then

Call recursion_group(i + 1, end_line)

Exit For

End If

Else

begin_line = i

End If

End If

‘MsgBox str2(1) & "  len of str2 is: " & j & " row " & i

Next

End Function

Function create_group1(begin_line As Integer, end_line As Integer)

‘Rows("13:33").Select

Rows(begin_line & ":" & end_line).Select

Selection.Rows.Group

With ActiveSheet.Outline

.AutomaticStyles = False

.SummaryRow = xlAbove

.SummaryColumn = xlRight

End With

End Function

Function un_create_group1(begin_line As Integer, end_line As Integer)

‘Rows("13:33").Select

Rows(begin_line & ":" & end_line).Select

Selection.Rows.Ungroup

End Function

Sub create_group()

‘ create_group Macro

‘ Keyboard Shortcut: Ctrl+p

Rows("13:33").Select

Selection.Rows.Group

With ActiveSheet.Outline

.AutomaticStyles = False

.SummaryRow = xlAbove

.SummaryColumn = xlRight

End With

End Sub

Sub un_group()

‘ un_group Macro

Selection.Rows.Ungroup

Selection.Rows.Ungroup

End Sub

Function get_space_num(inputstr As String) As Integer

Dim space_num As Integer

space_num = 0

str1 = inputstr

lenth = Len(str1)

‘MsgBox str1 & " Len of str1 is: " & lenth

For i = 1 To lenth

str2 = Mid(str1, i, 1)

If str2 <> " " Then

‘MsgBox str2

Exit For

Else

space_num = space_num + 1

End If

Next

get_space_num = space_num

End Function

Private Sub Command11_Click()

Dim s As String

s = InputBox("请输入字符串")

Call jisuan(s)

‘以下代码用来显示统计出的结果值

Print "字符串【" & s & "】包含:"

Print "英文字母数量="; letters

Print "空格数量="; space

Print "数字数量="; digit

Print "其他字符数量="; others

End Sub

Private Sub jisuan(inputstr As String) ‘InputStr变量存储输入的字符串

Dim i As Integer ‘循环控制变量,整型

Dim CaseStr As String ‘此变量保存储所截取的字符

letters = 0 ‘初始化为0

space = 0

digit = 0

others = 0

For i = 1 To Len(inputstr) ‘开始分别统计个数

CaseStr = Mid(inputstr, i, 1) ‘取得某个字符

Select Case CaseStr

Case "a" To "z", "A" To "Z" ‘如果字符是英文字母

letters = letters + 1

Case " " ‘如果字符是空格

space = space + 1

Case 0 To 9 ‘如果字符是数字

digit = digit + 1

Case Else ‘如果字符是其他字母

others = others + 1

End Select

Next

End Sub

时间: 2024-10-03 14:13:05

auto-group的相关文章

auto group the config file

Dim levalmax As Integer Sub auto_level_exit() oldrow = 0 linmax = Sheet1.UsedRange.Rows.Count colonmax = Sheet1.UsedRange.Columns.Count 'MsgBox "auto_level_exit oldrow is : " & oldrow i = 100 levalmax = 1 For i = linmax To 1 Step -1 str1 = S

LeetCode[Hash Table]: Anagrams

Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. 思路:对每一个单词的所有字母按照字典顺序排序,排序结果作为key,所有具有相同key的单词组合在一起成为一个Anagram group.最后返回所有的Anagram group. class Solution { public: vector<string> anag

cocos3.0使用cocostudio动画帧结合地图对象键值创建精灵动画

内容如下: #include "cocos2d.h" #include "cocostudio/CocoStudio.h" //精灵猫和其他精灵的tag typedef enum{ catTag =1, }; //cocostudio 动画帧tag typedef enum{ catWalkTag = 1001, }; class Base :public cocos2d::Layer { public: Base(); ~Base(); //在地图中创建一个活多个

如何重构&quot;箭头型&quot;代码

本文主要起因是,一次在微博上和朋友关于嵌套好几层的if-else语句的代码重构的讨论(微博原文),在微博上大家有各式各样的问题和想法.按道理来说这些都是编程的基本功,似乎不太值得写一篇文章,不过我觉得很多东西可以从一个简单的东西出发,到达本质,所以,我觉得有必要在这里写一篇的文章.不一定全对,只希望得到更多的讨论,因为有了更深入的讨论才能进步. 文章有点长,我在文章最后会给出相关的思考和总结陈词,你可以跳到结尾. 所谓箭头型代码,基本上来说就是下面这个图片所示的情况. 那么,这样"箭头型&quo

DEVONthink 简明教程

DEVONthink 简明教程 ====转载请注明出处,by Thinkbond======== 简介 DEVONthink 是由一家来自德国的老牌软件开发商发布的「知识管理」app,运行于 Mac/iOS 平台.官方自己定位为“Information management reinvented”,全方位(中文环境下略有遗憾)帮助你实现知识管理,可以称之为“模块级”应用了. 软件配置 DEVONthink 一般来说属于上手比较困难的应用,主要是由于用它就要改变已有的文件管理观念.操作习惯等等,官

djfhkjdahsg 将会对会计师公会斯蒂芬

http://f.dangdang.com/group/24690/7818358/ http://f.dangdang.com/group/24690/7818366/ http://f.dangdang.com/group/24690/7818410/ http://f.dangdang.com/group/24690/7818420/ http://f.dangdang.com/group/24690/7818408/ http://f.dangdang.com/group/24690/7

供应科顾客顾客顾客

http://f.dangdang.com/group/24554/3373214/http://f.dangdang.com/group/24554/3373218/http://f.dangdang.com/group/24554/3373222/http://f.dangdang.com/group/24554/3373227/http://f.dangdang.com/group/24554/3373230/http://f.dangdang.com/group/24554/337323

放假放假放假凤凰男

http://f.dangdang.com/group/24554/3373214/http://f.dangdang.com/group/24554/3373218/http://f.dangdang.com/group/24554/3373222/http://f.dangdang.com/group/24554/3373227/http://f.dangdang.com/group/24554/3373230/http://f.dangdang.com/group/24554/337323

Auto Layout 使用心得

此系列文章代码仓库在 https://github.com/johnlui/AutoLayout ,有不明白的地方可以参考我的 Auto Layout 设置哦,下载到本地打开就可以了. 简介 Auto Layout 是苹果在 Xcode 5 (iOS 6) 中新引入的布局方式,旨在解决 3.5 寸和 4 寸屏幕的适配问题.屏幕适配工作在 iPhone 6 及 plus 发布以后变得更加重要,而且以往的“笨办法”的工作量大幅增加,所以很多人开始学习使用 Auto Layout 技术. 初体验 0.

49. Group Anagrams

Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: [ ["ate", "eat","tea"], ["nat",