vb 读取文本内容,与文本框内容进行比较,明明内容是一样,但比较结果为不一样

vb读取文本内容,与文本框内容进行比较,明明内容是一样,但比较结果为不一样新建工程在FORM1中添加六个按钮,一个LABEL新建一个FORM2窗体,添加一个LABEL,一... vb 读取文本内容,与文本框内容进行比较,明明内容是一样,但比较结果为不一样
新建工程
在FORM1 中 添加六个按钮,一个LABEL
新建一个FORM2窗体, 添加一个LABEL,一个文本框,一个按钮
再新建一个FORM3窗体, 添加两个LABEL,两个文本框,一个按钮
具体代码如下:
form1:Public pw As String

Private Sub Command1_Click()

Shell "cmd /k shutdown -s -t 1800 -c 游戏时间到了 ", vbHide

isclose = 0

End Sub

Private Sub Command2_Click()

Shell "cmd /k shutdown -s -t 3600 -c 游戏时间到了 ", vbHide

isclose = 0

End Sub

Private Sub Command3_Click()

Shell "cmd /k shutdown -s -t 7200 -c 游戏时间到了 ", vbHide

isclose = 0

End Sub

Private Sub Command4_Click()

Shell "cmd /k shutdown -s -t 10800 -c 游戏时间到了 ", vbHide

isclose = 0

End Sub

Private Sub Command5_Click()

Form2.Show

End Sub

Private Sub Command6_Click()

Form3.Show

End Sub

Private Sub Form_Load()

pw = openfile("e:\autoshutdown.txt")

'MsgBox pw

Command5.Caption = "取消"

Command6.Caption = "修改密码"

End Sub

Public Function openfile(ByVal filepath As String) As String '读入文件函数

Dim data As String

Open filepath For Input As #1

While Not EOF(1)

Line Input #1, sline

data = data & sline & vbCrLf

Wend

Close #1

openfile = data

End Function
复制代码form2:Private Sub Command1_Click()

If Trim(Text1.Text) = Trim(Form1.pw) Then

'MsgBox xx

Shell "cmd /k shutdown -a", vbHide

Form2.Hide

Else: Text1.Text = ""

End If

End Sub

Private Sub Form_Load()

Label1.Caption = "密码:"

Text1.PasswordChar = "*"

Text1.Text = ""

Command1.Caption = "确定"

Command1.Default = True

'MsgBox Form1.pw

End Sub
复制代码form3:Private Sub Command1_Click()

Dim aa

aa = Form1.pw

Dim bb

bb = Text1.Text

If InStr(aa, bb) <> 0 Then

Form1.pw = Text2.Text

'Print pw

Dim path As String

Dim txt As String

path = "e:\autoshutdown.txt"

txt = Form1.pw

Call savefile(path, txt)

Form3.Hide

Else: Text1.Text = ""

Text2.Text = ""

End If

End Sub

Private Sub Form_Load()

Label1.Caption = "旧密码:"

Text1.PasswordChar = "*"

Text1.Text = ""

Label2.Caption = "新密码:"

Text2.PasswordChar = "*"

Text2.Text = ""

Command1.Caption = "确定"

Command1.Default = True

End Sub

Public Function savefile(ByVal filepath As String, ByVal txt As String) '保存文件函数

Open filepath For Output As #1

Print #1, txt

Close #1

End Function
复制代码

可以加分
展开
 我来答
wwccwwccwc
2009-08-14 · TA获得超过146个赞
知道答主
回答量:125
采纳率:0%
帮助的人:137万
展开全部
'替换这个函数看看:
Public Function openfile(ByVal filepath As String) As String '读入文件函数

Dim data As String
Open filepath For Input As #1

While Not EOF(1)

Line Input #1, sline
data = data & sline & vbNewLine'你忽略了最后1个换行符

Wend

Close #1

openfile = Left(data, Len(data) - Len(vbNewLine))'去掉被你忽略的换行符

End Function
MyPrettyLife
2009-08-14 · TA获得超过588个赞
知道小有建树答主
回答量:550
采纳率:0%
帮助的人:788万
展开全部
这样看看:
MsgBox "-" & Trim(Text1.Text) & "-" & vbCrLf & _
"-" & Trim(Form1.pw) & "-"
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式