In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use VB.NET control to operate files, the article is very detailed, has a certain reference value, interested friends must read it!
Show Fil
Because of the differences in the storage formats of different files, different files can be displayed correctly only by using appropriate methods. On the surface, that is, different file suffixes have different names, and different applications can only read and display files in one or more different formats. For example, files with the suffix .DOC can be opened with WORD, but cannot be displayed correctly with notepad. Therefore, VB provides us with different controls to display different files.
Here we take the text control as an example to see how to display files with it.
Private Sub mnuopen_Click () 'execute Dim filepath as Sting Dim strLine As String when opening a file on the menu' when no file is selected, text.text is empty character, does not display anything text1.text = "" CommonDialog1.FileName = "" 'the following statement sets the file filtering mode, and can display the txt file CommonDialog1.Filter = "(* .txt) | * .txt"' to establish a general dialog box for opening mode. You can also use commondialog1.showopen CommonDialog1.Action = 1 filepath=CommonDialog1.FileName'to get the selected file Open filepath For Input As # 1 to open the selected file Do Until EOF (1)'to display the open file Line Input # 1, strLine text1text1.Text = text1.Text + strLine + Chr (13) + Chr (10) Loop Close # 1'to close the open file End Sub
In addition to what comes with the VB.NET control, we can also use fileSystemObject file system objects, file objects, and files collections. Below we give two examples. For more details, please refer to the previous catalog section.
The following code illustrates how to get a file object and how to view one of its properties.
Sub ShowFileInfo (filespec) Dim fs, f, s Set fs = CreateObject ("scripting.FileSystemObject") Set f = fs.GetFile (filespec) s = f.DateCreated MsgBox s
File operation is a necessary function of every software. Using the common controls provided by Visual Basic, you can easily operate the file End Sub.
For how to get a files collection and how to use For Each... Next statement to access each file in this collection, we can refer to the following example:
Sub ShowFolderList (folderspec) 'folderspec is the folder name Dim fs, f, F1 S Set fs = CreateObject ("Scripting.FileSystemObject") Set f = fs.GetFolder (folderspec) 'get the folder object related to the folderspec folder Set ffc = f.Files' get the files collection For Each fi in fc'of the folder contained in the folder object access each folder ss= s & f1.name'in the folder collection format the text to be displayed ss= s & vbCrLf Next MsgBox s' display the information End Sub above is "such as" All the contents of the article "how to use VB.NET controls to manipulate files" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.