• VB.NET中使用List


    VB.NET中的List用法

      1 Imports System.IO
      2 Imports System.Data.OleDb
      3 Public Class Form_mobilecodeFilter
      4     Public list As New List(Of String)
      5     Public mobilecode As New List(Of mobile)
      6     Public loadlist As New List(Of plist) 
      7 
      8     '结构体 
      9 
     10     Public Structure mobile
     11         Public mobilecode As String
     12         Public Province As String
     13         Public City As String
     14         Public Card As String
     15     End Structure 
     16 
     17     Public Structure plist
     18         Public province As String
     19         Public mobileNew As List(Of citylist)
     20     End Structure 
     21 
     22     Public Structure citylist
     23         Public city As String
     24         Public mobilecontext As List(Of mobileLoadwritetxt)
     25     End Structure 
     26 
     27     Public Structure mobileLoadwritetxt
     28         Public context As String
     29         Public mobilecode As String
     30         Public Province As String
     31         Public City As String
     32         Public Card As String
     33     End Structure 
     34 
     35     Private Sub Button_Importmobilecode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Importmobilecode.Click
     36         Dim fileName As String
     37         OpenFileDialog_ImportMobileCode.Filter = "文本文件(*.txt)|*.txt"
     38         OpenFileDialog_ImportMobileCode.ShowDialog()
     39         fileName = OpenFileDialog_ImportMobileCode.FileName
     40         TextBox_Importfilepath.Text = fileName 
     41 
     42         Dim path As String
     43         Dim line As String = String.Empty
     44         path = TextBox_Importfilepath.Text
     45         Try
     46             FileOpen(1, path, OpenMode.Input)
     47         Catch ex As Exception
     48             FileClose(1)
     49             FileOpen(1, path, OpenMode.Input)
     50         End Try
     51         line = "" 
     52 
     53         Do While Not EOF(1)
     54             Input(1, line)
     55             If line.Trim <> "" Then
     56                 list.Add(line)
     57             End If
     58         Loop
     59         FileClose(1)
     60     End Sub 
     61 
     62     Private Sub Button_Checkout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Checkout.Click 
     63 
     64         Dim fileName As String
     65         Dim result As DialogResult = FolderBrowserDialog_download.ShowDialog()
     66         fileName = FolderBrowserDialog_download.SelectedPath
     67         Dim i, j, k As Integer
     68         Dim cl As citylist
     69         Dim mo As mobileLoadwritetxt
     70         For i = 0 To loadlist.Count - 1
     71             Dim txtpath As String = fileName & "\" & loadlist.Item(i).province
     72             System.IO.Directory.CreateDirectory(txtpath)
     73             For j = 0 To loadlist.Item(i).mobileNew.Count - 1
     74                 cl = loadlist.Item(i).mobileNew.Item(j)
     75                 Dim writefile As New StreamWriter(txtpath & "\" & cl.city & ".txt")
     76                 For k = 0 To cl.mobilecontext.Count - 1
     77                     mo = cl.mobilecontext.Item(k)
     78                     Dim context As String = mo.context
     79                     Dim province As String = mo.Province
     80                     Dim City As String = mo.City
     81                     Dim mobilecode As String = mo.mobilecode
     82                     Dim Card As String = mo.Card
     83                     Dim writecontext As String = ""
     84                     If CheckBox_ID.Checked Then
     85                         writecontext = writecontext & k 1 & "   "
     86                     End If
     87                     If CheckBox_mobilecode.Checked Then
     88                         writecontext = writecontext & context & "     "
     89                     End If
     90                     If CheckBox_province.Checked Then
     91                         writecontext = writecontext & province & "    "
     92                     End If
     93                     If CheckBox_city.Checked Then
     94                         writecontext = writecontext & City & "    "
     95                     End If
     96                     If CheckBox_haoduan.Checked Then
     97                         writecontext = writecontext & mobilecode & "    "
     98                     End If
     99                     If CheckBox_execute.Checked Then
    100                         writecontext = writecontext & Card
    101                     End If
    102                     writefile.WriteLine(writecontext)
    103                 Next
    104                 writefile.Flush()
    105                 writefile.Close()
    106             Next
    107         Next
    108         TextBox_Importfilepath.Text = ""
    109         MessageBox.Show("完成"
    110 
    111     End Sub 
    112 
    113     Private Sub Button_closeMe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_closeMe.Click
    114         Me.Close()
    115     End Sub 
    116 
    117     Public Sub loadmobile()
    118         Dim SQLGroupStr = "select * from mobile"
    119         Dim CString As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ctc-nft.mdb;Persist Security Info=True"
    120         Dim con As New OleDbConnection(CString)
    121         Dim com As New OleDbCommand()
    122         com.Connection = con
    123         con.Open()
    124         com.CommandType = CommandType.Text
    125         com.CommandText = SQLGroupStr
    126         Dim rs As OleDbDataReader = com.ExecuteReader()
    127         While (rs.Read)
    128             Dim m As New mobile
    129             m.mobilecode = rs.GetString(0)
    130             m.Province = rs.GetString(1)
    131             m.City = rs.GetString(2)
    132             m.Card = rs.GetString(3)
    133             mobilecode.Add(m)
    134         End While
    135         con.Close()
    136     End Sub 
    137 
    138     Private Sub Button_manage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_manage.Click
    139         loadmobile()
    140         MessageBox.Show("在处理中可能要等几分钟,请稍等""提示")
    141         Dim i, j As Integer
    142         Dim a As Integer = 1
    143         Dim m As mobile
    144         For i = 0 To mobilecode.Count - 1
    145             m = mobilecode.Item(i)
    146             For j = 0 To list.Count - 1
    147                 If m.mobilecode.ToString.Equals(list.Item(j).ToString.Substring(07)) Then
    148                     If a = 1 Then
    149                         a = a 1
    150                         Dim pl As New plist
    151                         pl.province = mobilecode.Item(i).Province
    152                         Dim lm As New citylist
    153                         lm.city = mobilecode.Item(i).City
    154                         Dim mo As New mobileLoadwritetxt
    155                         mo.Card = mobilecode.Item(i).Card
    156                         mo.City = mobilecode.Item(i).City
    157                         mo.context = list.Item(j)
    158                         mo.mobilecode = mobilecode.Item(i).mobilecode
    159                         mo.Province = mobilecode.Item(i).Province
    160                         lm.mobilecontext = New List(Of mobileLoadwritetxt)
    161                         lm.mobilecontext.Add(mo)
    162                         pl.mobileNew = New List(Of citylist)
    163                         pl.mobileNew.Add(lm)
    164                         loadlist.Add(pl)
    165                     Else
    166                         Dim sp As String = isProvince(loadlist, mobilecode.Item(i).Province)
    167                         Dim str() As String = sp.Split(" ")
    168                         Dim flagprovince As String = str(0)
    169                         Dim flag As Boolean
    170                         If flagprovince.ToString.Equals("1"Then
    171                             flag = True
    172                         Else
    173                             flag = False
    174                         End If
    175                         If flag = True Then
    176                             Dim sc As String = iscity(loadlist, mobilecode.Item(i).City)
    177                             Dim str1() As String = sc.Split(" ")
    178                             Dim flagcity As Boolean
    179                             If str1(0).ToString.Equals("1"Then
    180                                 flagcity = True
    181                             Else
    182                                 flagcity = False
    183                             End If
    184                             If flagcity = True Then
    185                                 Dim mob As New mobileLoadwritetxt
    186                                 mob.Card = mobilecode.Item(i).Card
    187                                 mob.City = mobilecode.Item(i).City
    188                                 mob.context = list.Item(j)
    189                                 mob.mobilecode = mobilecode.Item(i).mobilecode
    190                                 mob.Province = mobilecode.Item(i).Province
    191                                 loadlist.Item(str(1)).mobileNew.Item(str1(1)).mobilecontext.Add(mob)
    192                             Else
    193                                 Dim cl As New citylist
    194                                 cl.city = mobilecode.Item(i).City
    195                                 Dim mi As New mobileLoadwritetxt
    196                                 mi.Card = mobilecode.Item(i).Card
    197                                 mi.City = mobilecode.Item(i).City
    198                                 mi.context = list.Item(j)
    199                                 mi.mobilecode = mobilecode.Item(i).mobilecode
    200                                 mi.Province = mobilecode.Item(i).Province
    201                                 cl.mobilecontext = New List(Of mobileLoadwritetxt)
    202                                 cl.mobilecontext.Add(mi)
    203                                 loadlist.Item(str(1)).mobileNew.Add(cl)
    204                             End If
    205                         Else
    206                             Dim pl As New plist
    207                             pl.province = mobilecode.Item(i).Province
    208                             Dim lm As New citylist
    209                             lm.city = mobilecode.Item(i).City
    210                             Dim mo As New mobileLoadwritetxt
    211                             mo.Card = mobilecode.Item(i).Card
    212                             mo.City = mobilecode.Item(i).City
    213                             mo.context = list.Item(j)
    214                             mo.mobilecode = mobilecode.Item(i).mobilecode
    215                             mo.Province = mobilecode.Item(i).Province
    216                             lm.mobilecontext = New List(Of mobileLoadwritetxt)
    217                             lm.mobilecontext.Add(mo)
    218                             pl.mobileNew = New List(Of citylist)
    219                             pl.mobileNew.Add(lm)
    220                             loadlist.Add(pl)
    221                         End If
    222                         End If
    223                 End If
    224             Next
    225         Next
    226         MessageBox.Show("请立即导入,当关闭此窗口数据就会销毁""提示")
    227     End Sub 
    228 
    229     Public Function isProvince(ByVal list As List(Of plist), ByVal str As String)
    230         Dim i As Integer
    231         For i = 0 To list.Count - 1
    232             If str.ToString.Equals(list.Item(i).province.ToString) Then
    233                 Return 1 & " " & i
    234             End If
    235         Next
    236         Return 0 & " " & i - 1
    237     End Function 
    238 
    239     Public Function iscity(ByVal list As List(Of plist), ByVal str As String)
    240         Dim i, j As Integer
    241         Dim pl As plist
    242         pl.mobileNew = New List(Of citylist)
    243         Dim cl As citylist
    244         For i = 0 To list.Count - 1
    245             pl.mobileNew = list.Item(i).mobileNew
    246             For j = 0 To pl.mobileNew.Count - 1
    247                 cl = pl.mobileNew.Item(j)
    248                 If cl.city.ToString.Equals(strThen
    249                     Return 1 & " " & j
    250                 End If
    251             Next
    252         Next
    253         Return 0 & " " & j - 1
    254     End Function 
    255 
    256 End Class 
    257 

     

         '此段代码现给有一定编程基础的朋友

    成功者找方法,失败者找借口!
  • 相关阅读:
    webStorm Ctrl+s 自动格式化 然后 保存 用宏命令
    vuez init webStorm vscode
    Node + Express + MySQL 接口开发完整案例
    sysUpload.vue上传组件 的时候 看进度的时候 不要mock 注释掉 // if (process.env.NODE_ENV !== 'production') require('@/mock')
    目录下 shift 右键菜单 打开cmd 或者在 地址栏输入cmd 回车进入cmd
    xls表格 拼接字段 拼json =CONCAT("{ code:'",A2,"',","codeName: '",B2,"',","flag: '",C2,"'},")
    js 数组过滤 filter
    libs/tools.js stringToDate dateToString 日期字符串转换函数
    vue 组件内 directives指令的调用方式 <base-table v-auto-height:tableHeight="{vm:this, diffHeight:ahTable.diffHeight}"
    油猴 tamperMonkey 在百度首页 添加自己的自定义链接
  • 原文地址:https://www.cnblogs.com/lizunicon/p/1247319.html
Copyright © 2020-2023  润新知