Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of dealing with data in VB.NET File

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "the method of dealing with data in VB.NET file". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

VB.NET file processing code:

'Open csv file PrivateSubbtnFile_Click (ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs) HandlesbtnFile.Click DimOpenFileAsOpenFileDialog=NewOpenFileDialog OpenFile.Filter= "csvFiles (* .csv) | * .xls | AllFiles (*. *) | *. *" IfOpenFile.ShowDialog () = DialogResult.OKThen txtFile.Text=OpenFile.FileName Else ExitSub EndIf EndSub 'write file PrivateSuboutfile () DimSaveFileAsSaveFileDialog=NewSaveFileDialog SaveFile.Filter= "text file (* .txt) | * .txt | AllFiles (*. *) | *." IfSaveFile.ShowDialog () = DialogResult.OKThen' txtdt.Text=SaveFile.FileName DimobjWriterAsNewIO.StreamWriter (SaveFile.FileName,True) System.Text.Encoding.Default) objWriter.WriteLine ("ANSI") objWriter.WriteLine ("Chinese") objWriter.Close () Else ExitSub EndIf EndSub 'ANSI text processing PrivateSubsplit1 ()' DimobjFileAsSystem.IO.File DimobjReaderAsNewIO.StreamReader ("D:\ MySystem\ Desktop\ Book1.csv" System.Text.Encoding.Default) DimsLineAsString= "DimarrTextAsNewArrayList Do sLine=objReader.ReadLine () IfNotsLineIsNothingThen arrText.Add (sLine) EndIf LoopUntilsLineIsNothing objReader.Close () DimDSAsNewDataSet DS.Tables.Add (" tab1 ") DS.Tables (" tab1 "). Columns.Add (" ID ") DS.Tables (" tab1 "). Columns.Add (" par ") DS.Tables (" tab1 "). Columns.Add (" no ") DS.Tables (" tab1 "). Columns.Add (" name ") DimfenAsString=" "Dimfen1AsChar () = fen.ToCharArray () DimsplitAsString () = Nothing DimiAsInteger 'ForEachsLineInarrText Fori=0ToarrText.Count-1 sLine=arrText (I) &", "split=sLine.Split (fen1) DimdrAsDataRow=DS.Tables (" tab1 "). NewRow dr (" ID ") = split (0). ToString dr (" par ") = split (1). ToString dr (" no ") = split (2). ToString dr (" name ") = IIf (split (3) ="," 0 ") Split (3) .ToString) DS.Tables ("tab1") .Rows.Add (dr) Next DataGrid1.DataSource=DS.Tables ("tab1") EndSub 'process data PrivateSubbtnDeal_Click (ByValsenderAsSystem.Object ByValeAsSystem.EventArgs) HandlesbtnDeal.Click IfDS.Tables.Contains ("tab2") = FalseThen DS.Tables.Add ("tab2") DS.Tables ("tab2"). Columns.Add ("part") DS.Tables ("tab2"). Columns.Add ("pp0") DS.Tables ("tab2"). Columns.Add ("pp1") DS.Tables ("tab2"). Columns.Add ("yanglao") DS.Tables ("tab2"). Columns.Add ("yibao") DS .Tables ("tab2"). Columns.Add ("gongji") DS.Tables ("tab2"). Columns.Add ("shiye") DS.Tables ("tab2"). Columns.Add ("sum0") EndIf DimdvAsDataView=DS.Tables ("tab1"). DefaultView dv.Sort= "part" ProgressBar1.Show () ProgressBar1.Value=0 ProgressBar1.Maximum=dv.Count-1 DimiAsInteger Dimdr Dr0AsDataRow Fori=0Todv.Count-1 ProgressBar1.Value=i Ifi=0Then dr=DS.Tables ("tab2"). NewRow dr ("part") = dv (I) .Row ("part") dr ("pp0") = dv (I) .Row ("pp1") dr ("yanglao") = dv (I) .Row ("yanglao") dr ("yibao") = dv (I) .Row ("yibao") dr ("gongji") = dv (I) .Row ("gongji") dr ("shiye") = dv (I) .Row ("shiye") dr ("sum0") = dv (I) .Row ("sum0") dr0=DS.Tables ("tab2"). NewRow dr0 ("part") = "Total" dr0 ("pp0") = 0 dr0 ("yanglao") = 0 dr0 ("yibao") = 0 dr0 ("gongji") = 0 dr0 ("shiye") = 0 dr0 ("sum0") = 0 Else Ifdr ("part") dv (I). Row ("part") Then dr0 ("pp0") + = dr ("pp0") ) dr0 ("yanglao") + = dr ("yanglao") dr0 ("yibao") + = dr ("yibao") dr0 ("gongji") + = dr ("gongji") dr0 ("shiye") + = dr ("shiye") dr0 ("sum0") + = dr ("sum0") DS.Tables ("tab2") .Rows.Add (dr) dr=DS.Tables ("tab2"). NewRow dr ("part") = dv (I) .Row ("part") dr ("pp0") = dv (I) ). Row ("pp1") dr ("yanglao") = dv (I) .Row ("yanglao") dr ("yibao") = dv (I) .Row ("yibao") dr ("gongji") = dv (I) .Row ("gongji") dr ("shiye") = dv (I) .Row ("shiye") dr ("sum0") = dv (I) .Row ("sum0") Else dr ("pp0") + = dv (I) .Row ("pp1") dr ( "yanglao") + = dv (I) .Row ("yanglao") dr ("yibao") + = dv (I) .Row ("yibao") dr ("gongji") + = dv (I) .Row ("gongji") dr ("shiye") + = dv (I) .Row ("shiye") dr ("sum0") + = dv (I) .Row ("sum0") EndIf EndIf Application.DoEvents () Next dr0 ("pp0") + = dr ("pp0") dr0 ("yanglao") + = dr ("yanglao") Dr0 ("yibao") + = dr ("yibao") dr0 ("gongji") + = dr ("gongji") dr0 ("shiye") + = dr ("shiye") dr0 ("sum0") + = dr ("sum0") DS.Tables ("tab2") .Rows.Add (dr) DS.Tables ("tab2") .Rows.Add (dr0) ProgressBar1.Hide () grdMain.CaptionText= "result data" grdMain.DataSource=DS.Tables ("tab2") grdStyles ("tab2") This is the end of the introduction of MsgBox ("data has been processed") EndSub "methods for processing data in VB.NET files". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report