VB.net 的习惯代码

VB.net中相关的使用从VB6转变过来

 

  • 创建固定指定空间长度的字符串

VB6 dim str_tmp as string(1024)

VB.net中我是这样搞的

dim chr_tmp(1024) as char

dim str_tmp as string

str_tmp=chr_tmp

检查str_tmp的长度就是1025(str_tmp.lenth)

 

  • 获取当前APP的路径

VB6   app.path

vb.net中是  Environment.CurrentDirectory

 

  • 创建文件夹和文件(VB.NET)
    Imports System.IO
    Private Sub Create_Dir(Dir_Path As String)
        Directory.CreateDirectory(Dir_Path)
    End Sub
    Private Sub Create_File(Full_Filename As String)
        Dim tempdir() As String
        Dim dirCreated As String
        Dim count1 As Integer
        Dim str_FileName As String
        str_FileName = Trim(Full_Filename)
        If Mid(str_FileName, str_FileName.Length - 1, 1) = "\" Then  'VB6中用Right在VB.NET中已经不好用了
            Call Create_Dir(str_FileName)
            Exit Sub
        End If
        tempdir = Split(str_FileName, "\")
        dirCreated = ""
        For count1 = 0 To UBound(tempdir) - 1
            If tempdir(count1) <> "" Then
                dirCreated = dirCreated & tempdir(count1) & "\"
            End If
        Next
        Call Create_Dir(dirCreated)
        If File.Exists(Full_Filename) = False Then
            Dim fs As FileStream = File.Create(Full_Filename)
            fs.Close()
        End If
    End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值