Public Class Form1
創(chuàng)新互聯(lián)2013年開創(chuàng)至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站制作、網(wǎng)站建設(shè)網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元志丹做網(wǎng)站,已為上家服務(wù),為志丹各地企業(yè)和個人服務(wù),聯(lián)系電話:18980820575
Inherits System.Windows.Forms.Form
Public filename As String = "英漢詞典.txt"
Public myword(6500, 1) As String
Public words As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As String
Dim b As Integer
Dim i As Integer = 0
Dim n As String
Dim m As String
Dim stringb As Integer
TextBox1.Text = ""
TextBox2.Text = ""
FileOpen(1, "英漢詞典.txt", OpenMode.Input)
Do While Not EOF(1)
a = LineInput(1)
b = InStr(a, " ")
n = Microsoft.VisualBasic.Left(a, b - 1)
myword(i, 0) = n
ListBox1.Items.Add(n)
stringb = Len(a) - b
m = Trim(Microsoft.VisualBasic.Right(a, stringb))
myword(i, 1) = m
i += 1
Loop
words = i
FileClose(1)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = -1
If TextBox1.Text = "" Then
MessageBox.Show("不能輸入空格,請重新輸入")
TextBox2.Text = ""
TextBox1.Focus()
Exit Sub
Else
For i = i + 1 To words
If LCase(TextBox1.Text) = LCase(myword(i, 0)) Then
TextBox2.Text = Trim(myword(i, 1))
Exit Sub
End If
Next
MessageBox.Show(" 您需要的單詞不存在,請重新輸入")
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Try
TextBox1.Text = myword(ListBox1.SelectedIndex, 0)
TextBox2.Text = Trim(myword(ListBox1.SelectedIndex, 1))
Catch ex As Exception
End Try
Exit Sub
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim ch, enterwords As String
Dim j, m As Integer
If -1 = ListBox1.SelectedIndex Then
MsgBox("請選擇單詞", , "")
ListBox1.Focus()
Exit Sub
End If
enterwords = InputBox("請修改單詞", "修改單詞", Trim(myword(ListBox1.SelectedIndex, 0)))
Do While enterwords = ""
m = MsgBox("單詞不能為空", MsgBoxStyle.RetryCancel, "修改單詞")
If m = 4 Then
enterwords = InputBox("請修改單詞", "修改單詞", Trim(myword(ListBox1.SelectedIndex, 0)))
Else
Exit Sub
End If
Loop
ch = InputBox("請修改中文意思", "修改單詞", Trim(myword(ListBox1.SelectedIndex, 1)))
Do While ch = ""
m = MsgBox("中文意思不能為空", MsgBoxStyle.RetryCancel, "修改單詞")
If m = 4 Then
ch = InputBox("請修改中文意思", "修改單詞", Trim(myword(ListBox1.SelectedIndex, 1)))
Else
Exit Sub
End If
Loop
myword(ListBox1.SelectedIndex, 1) = ch
myword(ListBox1.SelectedIndex, 0) = enterwords
FileOpen(1, filename, OpenMode.Output)
For j = 0 To words - 1
PrintLine(1, myword(j, 0) " " myword(j, 1))
Next
FileClose(1)
MsgBox("修改成功")
ListBox1.Items.Clear()
Form1_Load(sender, e)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer = 0
Dim k, m As Integer
Dim enterwords, ch As String
enterwords = InputBox("請輸入要添加的單詞", "添加單詞")
Do While enterwords = ""
m = MsgBox("單詞不能為空,請輸入單詞!", MessageBoxButtons.RetryCancel, "添加單詞")
If m = 4 Then
enterwords = InputBox("請輸入要添加的單詞", "添加單詞")
Else
Exit Sub
End If
Loop
ch = InputBox("請輸入中文意思", "添加中文")
Do While ch = ""
m = MsgBox("中文不能為空,請輸入中文意思!", MessageBoxButtons.RetryCancel, "添加中文")
If m = 4 Then
ch = InputBox("請輸入中文意思", "添加中文")
Else
Exit Sub
End If
Loop
Do While LCase(myword(i, 0)) LCase(enterwords)
i = i + 1
If words = i Then
myword(i, 0) = enterwords
myword(i, 1) = ch
words = words + 1
FileOpen(1, filename, OpenMode.Output)
For i = 0 To words - 1
PrintLine(1, myword(i, 0) " " myword(i, 1))
Next
ListBox1.Items.Clear()
FileClose(1)
ListBox1.Items.Clear()
Form1_Load(sender, e)
MessageBox.Show("添加成功")
Exit Sub
End If
Loop
If LCase(myword(i, 0)) = LCase(enterwords) Then
MessageBox.Show("該單詞已存在!")
ListBox1.SelectedIndex = i
Exit Sub
ElseIf LCase(myword(0, 0)) LCase(enterwords) Then
For k = words To 0 Step -1
myword(k + 1, 0) = myword(k, 0)
myword(k + 1, 1) = myword(k, 1)
Next
myword(0, 0) = enterwords
myword(0, 1) = ch
words = words + 1
FileOpen(1, filename, OpenMode.Output)
For i = 0 To words - 1
PrintLine(1, myword(i, 0) " " myword(i, 1))
Next
ListBox1.Items.Clear()
FileClose(1)
Form1_Load(sender, e)
MessageBox.Show("添加成功")
Exit Sub
End If
For k = words To i + 1 Step -1
myword(k + 1, 0) = myword(k, 0)
myword(k + 1, 1) = myword(k, 1)
Next k
myword(i, 0) = enterwords
myword(i, 1) = ch
words = words + 1
FileOpen(1, filename, OpenMode.Output)
For i = 0 To words - 1
PrintLine(1, myword(i, 0) " " myword(i, 1))
Next
FileClose(1)
ListBox1.Items.Clear()
Form1_Load(sender, e)
MessageBox.Show("添加成功")
Exit Sub
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim i, j, k As Integer
If -1 = ListBox1.SelectedIndex Then
MsgBox("請選擇單詞", , "")
ListBox1.Focus()
Exit Sub
End If
k = MsgBox("確定是否刪除", MsgBoxStyle.YesNo, "提示")
If k = 6 Then
For i = ListBox1.SelectedIndex To words
myword(i, 0) = myword(i + 1, 0)
myword(i, 1) = myword(i + 1, 1)
Next
words = words - 1
FileOpen(1, filename, OpenMode.Output)
For j = 0 To words - 1
PrintLine(1, myword(j, 0) " " myword(j, 1))
Next
FileClose(1)
MsgBox("單詞已刪除")
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox1.Refresh()
TextBox1.Text = ""
TextBox2.Text = ""
Exit Sub
Else
Exit Sub
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
End Class
這是代碼,文字性的內(nèi)容自己去做。
隱式聲明就是指在使用某個變量之前,沒有專門對其進行聲明,
比如有個變量 J ,現(xiàn)在用DIM J AS ...對它進行專門的聲明.就用它: J = 5 這就是隱式聲明.
隱式聲明會有一些風(fēng)險.比如會寫錯變量明,使得前后本來要使用的是同一個變量的,卻變成了兩個.
顯式聲明和隱式聲明相反,就是在用變量之前,對它進行了專門的聲明.如:
dim a as string
a = "abc"
----------------------
在編程之前可以對程序進行設(shè)置,在編輯器的選項設(shè)置里 - VB默認(rèn)值中 ,有個
Option Explicit 屬性,如果選擇ON,則會在寫程序時,要求強制顯式聲明變量.如果沒有進行顯示聲明的變量,在使用的時候會報錯.
也可以在程序前使用 Option Explicit On 語句,來開啟強制顯式聲明...
-------------------------
這么解釋能理解吧?
在VBA中使用字典分為前期綁定和后期綁定兩種方式,
一、前期綁定:打開VBE編輯器,按下圖操作,勾選相應(yīng)選項就可以直接使用字典了。
二、后期綁定:如下代碼即創(chuàng)建了一個名稱為d的字典。
Set d = CreateObject("scripting.dictionary")
新聞名稱:vb.net如何聲明字典 vb聲明語句
分享鏈接:http://vcdvsql.cn/article42/doichhc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、、品牌網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計公司、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)