注册 登录
编程论坛 VB6论坛

大家帮帮忙这个 VB 简单的问题关于分割的操作! 帮帮忙!谢谢了!!!

a251357 发布于 2014-04-24 21:14, 668 次点击
VB编程知识: 已知:ListView1 "编号"帐号"密码" C:\帐号.txt 这个帐号.txt内容如下:
1234567---89101112
2123423---23233232
admin---38434853
dkjfsi---24424334
ijjruinv---432423
我想把C:\帐号.txt的内容显示在ListView1"帐号","密码"的里面帐号和密码!


如果以上太难 那就用 List1 来操作吧!
以C:\帐号.txt作为数据库内容":
1234567---89101112
2123423---23233232
admin---38434853
dkjfsi---24424334
ijjruinv---432423

显示在List1里面

创建text1和text2 点击按钮会一行一行的显示帐号和密码!

各位大侠帮帮忙!我做个简单的数据帐号密码管理库!
谢谢了
9 回复
#2
a2513572014-04-24 21:16
注意下"---"这个是分割号 前面是帐号后面是密码!!!
#3
风吹过b2014-04-25 07:47
打开文件,一行行的读会不会?
假设你会吧。

打开文件
   没有结束
     读一行
     显示一行
   继续循环
关闭文件

显示时:
dim fj() as string
if instr(1,list1.list(list1.listindex),"---")>0 then
fj=split(list1.list(list1.listindex),"---")        '按---分成前后两段
text1.text=fj(0)
text2.text=fj(1)
else
text1.text=""
text2.text=""
endif
#4
vbvcr512014-04-25 09:21
关键是split函数,好用,很强大。
#5
a2513572014-04-25 14:12
回复 3 楼 风吹过 b
版主!这个我是看懂的只是我需要达到这样一个效果 你写的分割代码我看懂了但是让它拼在点击按钮就会继续显示下一组的帐号和密码点击又会继续显示下一组帐号密码。
这个我始终有点纠结...点击就会继续显示下一组的数据帐号和密码:List1.list(1) List1.list(2) List1.list(3) List1.list(4) List1.list(5)
我知道可以变量i 而i可以继续等于i+1 而 List1.list(i) 点击可以继续选择下一个显示数组的帐号和密码..就是这里我不知道怎么配合你的代码..我写了很多次不知道问题老出在哪.
麻烦你给我写哈..在这先谢谢版主了..
#6
风吹过b2014-04-25 14:59
Static CI as long                '定义静态变量
dim fj() as string
if ci>list1.listcount then ci=0       '超出范围返回第一个
if instr(1,list1.list(ci),"---")>0 then         '是有效数据
fj=split(list1.list(ci),"---")        '按---分成前后两段
text1.text=fj(0)
text2.text=fj(1)
else
text1.text=""
text2.text=""
endif
ci=ci+1            '下一次显示下一个。
#7
owenlu19812014-04-25 16:43
Private Sub Form_Load()
Open "C:\帐号.txt" for input as #1
Dim i as Integer,AC as String,PW as String,StrName as string
Do while not EOF(#1)
    Lineinput #1,StrName    '读取一行
    List1.AddItem StrName
Loop
Close #1
i = 0
List1.ListIndex = i
Text1.Text = split(list1.list(i),"---")(0)
Text2.Text = split(list1.list(i),"---")(1)

'增加两个Command按钮 Cmd_Next,Cmd_Pre
Private Sub Cmd_Next_Click    '显示下一组
i = i + 1
List1.ListIndex = i
If i = List.ListCount-1 then
    Cmd_Next.Enabled = False
Endif
Text1.Text = split(list1.list(i),"---")(0)
Text2.Text = split(list1.list(i),"---")(1)
Cmd_Pre.Enabled = True
End Sub

Private Sub Cmd_Pre_Click    ‘显示上一组
i = i - 1
List1.ListIndex = i
If i = 0 then
    Cmd_Pre.Enabled = False
Endif
Text1.Text = split(list1.list(i),"---")(0)
Text2.Text = split(list1.list(i),"---")(1)
Cmd_Next.Enabled = True
End Sub
#8
a2513572014-04-25 23:55
回复 7 楼 owenlu1981
文章错误代码:Do while not EOF(#1)
文章错误改正:Do while not EOF(1)

代码测试:失败!!!!连续点击按钮只显示最多2组数据!!!变量的问题!!!
建议版主实际VB代码操作下!!

希望版主改正下!!嘻嘻
#9
a2513572014-04-26 00:08
'窗体添加一个List1 四个Text1.2.3.4. 一个Timer1属性150

Private Sub Form_Load()
If Dir("C:\Documents and Settings\Administrator\桌面\112.txt") <> "" Then
Dim aa As String
Open ("C:\Documents and Settings\Administrator\桌面\112.txt") For Input As #1
Do While Not EOF(1)
 Line Input #1, aa
List1.AddItem aa
 Loop
 Close #1
End If
'全部数量
Text4 = List1.ListCount
End Sub






Private Sub List1_Click()
Dim fj() As String
If InStr(1, List1.List(List1.ListIndex), "----") > 0 Then
fj = Split(List1.List(List1.ListIndex), "----")     '按---分成前后两段
Text1.Text = fj(0)
Text2.Text = fj(1)
Else
Text1.Text = ""
Text2.Text = ""
End If
Text3.Text = List1.ListIndex + 1
End Sub





Private Sub Timer1_Timer()
Static CI As Long                '定义静态变量
Dim fj() As String
If CI > List1.ListCount Then CI = 0   '超出范围返回第一个
If InStr(1, List1.List(CI), "----") > 0 Then     '是有效数据
fj = Split(List1.List(CI), "----")     '按---分成前后两段
Text1.Text = fj(0)
Text2.Text = fj(1)
List1.ListIndex = CI
Else
Text1.Text = ""
Text2.Text = ""
End If
CI = CI + 1
'Command2.Caption = CI '下一次显示下一个。
If Text3.Text = Text4.Text Then
List1.ListIndex = 0
Timer1.Enabled = False
End If

'感谢版主:风吹过b
'代码完美付出 我相信以后会有人用到的!
#10
owenlu19812014-04-26 11:05
程序代码:

Dim i as Integer,AC as String,PW as String,StrName as string    '变量定义

Private Sub Form_Load()
Open "C:\帐号.txt" for input as #1
Do while not EOF(1)
    Lineinput #1,StrName    '读取一行
    List1.AddItem StrName
Loop
Close #1
i = 0
List1.ListIndex = i
Text1.Text = split(list1.list(i),"---")(0)
Text2.Text = split(list1.list(i),"---")(1)

'增加两个Command按钮 Cmd_Next,Cmd_Pre
Private Sub Cmd_Next_Click    '显示下一组
i = i + 1
List1.ListIndex = i
If i = List.ListCount-1 then
    Cmd_Next.Enabled = False
Endif
Text1.Text = split(list1.list(i),"---")(0)
Text2.Text = split(list1.list(i),"---")(1)
Cmd_Pre.Enabled = True
End Sub

Private Sub Cmd_Pre_Click    ‘显示上一组
i = i - 1
List1.ListIndex = i
If i = 0 then
    Cmd_Pre.Enabled = False
Endif
Text1.Text = split(list1.list(i),"---")(0)
Text2.Text = split(list1.list(i),"---")(1)
Cmd_Next.Enabled = True
End Sub
1