使用excel在Visual Basic中生成大写字母和大写字母
我想用Vb CODE在Excel中创建密码 首字母大写和末字母大写 示例:A245F
Public Sub CmdCreatePassword_Click()
Dim i As Integer, j As Integer
For i = 1 To 70
j = Int(Rnd(99) * 100)
k = Int(Rnd(9))
Cells(i, "a") = Chr(97 + Int(Rnd(26) * 26)) & IIf(j < 10, j + 27, j) & IIf(k < 9, k + 9, k) & Chr(122 - Int(Rnd(26) * 26))
Next i
End Sub
Private Sub CmdCreatePassword_KeyDown(ByVal KeyCode As
MSForms.ReturnInteger, ByVal Shift As Integer)
CmdCreatePassword_Click
End Sub
答案 0 :(得分:1)
class Main extends React.Component {
constructor(props) {
super();
this.handleData = this.handleData.bind(this);
this.handleHigh = this.handleHigh.bind(this);
}
componentDidMount() {
const { getTasks } = this.props;
getTasks();
}
render() {
const { data, loading } = this.props;
if (!loading) {
this.handleData(data);
return (
{data.map(task => {
if (task.obj_status === 'active')
return (
// Doing some stuff with data here
);
} else {
return <div>Loading</div>;
}
}
}
const mapStateToProps = state => ({
data: state.main.data,
loading: state.main.loading
});
const mapDispatchToProps = dispatch => ({
...bindActionCreators(
{
getTasks: loadTasks,
dispatch
},
dispatch
)
});
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(Main)
);
使用生成的密码添加Ucase函数。它将所有字符转换为大写。
希望对您有用!
答案 1 :(得分:1)
为什么不是简单的公式呢?
=UPPER(LEFT(A1,1))&MID(A1,2,LEN(A1)-2)&UPPER(RIGHT(A1, 1))
产生预期的结果
编辑:如评论中所指出的,如果您不太在意其他潜在字符变为大写,或者您的数据始终遵循alpha num num num alpha
格式,则可以使用这个简化的公式改为:
=UPPER(A1)
答案 2 :(得分:0)
从任何ASCII table中都可以找到,字符'a'为97,'z'为122。此外,'A'为65,'Z'为90。因此,如果您使用大写字母,而不是小写字母,分别用65和90替换97和122值。
即:
Cells(i, "a") = Chr(65 + Int(Rnd(26) * 26)) & IIf(j < 10, j + 27, j) & IIf(k < 9, k + 9, k) & Chr(90 - Int(Rnd(26) * 26))
答案 3 :(得分:0)
在下面替换第六行
Cells(i, "a") = Chr(65 + Int(Rnd(26) * 26)) & IIf(j < 10, j + 27, j) & IIf(k < 9, k + 9, k) & Chr(90 - Int(Rnd(26) * 26))
答案 4 :(得分:0)
这有点烦躁,有点懒。它使用正则表达式模式[a-z]
将小写字母替换为大写字母。在这种情况下,它就像在开始和结束时一样起作用,并且您想同时替换两者。有点懒,好像首字母和尾字母都匹配,这仍然尝试替换。
Option Explicit
Public Sub CmdCreatePassword_Click()
Dim i As Long, j As Long, k As Long
For i = 1 To 70
j = Int(Rnd(99) * 100)
k = Int(Rnd(9))
Cells(i, "a") = UcaseString(Chr(97 + Int(Rnd(26) * 26)) & IIf(j < 10, j + 27, j) & IIf(k < 9, k + 9, k) & Chr(122 - Int(Rnd(26) * 26)), "[a-z]")
Next i
End Sub
Public Function UcaseString(Text As String, Pattern As String, Optional IgnoreCase As Boolean) As String
Dim re As Object, matches As Object, i As Long
Set re = CreateObject("VBScript.RegExp")
With re
.Global = True
.MultiLine = True
.IgnoreCase = IgnoreCase
.Pattern = Pattern
If .test(Text) Then
Set matches = .Execute(Text)
For i = 0 To matches.Count - 1
Text = Replace$(Text, matches(i), UCase$(matches(i)))
Next i
UcaseString = Text
Else
UcaseString = Text
End If
End With
End Function