
正文
vb.net获取名称 vba 获取文件名
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net从文件路径中获取文件名
获取方法,参考实例如下:
'获取路径名各部分:
如:
c:\dir1001\aaa.txt
'获取路径路径
c:\dir1001\
Public
Function
GetFileName(FilePathFileName
As
String)
As
String
'获取文件名
aaa.txt
On
Error
Resume
Next
Dim
i
As
Integer,
J
As
Integer
i
Len(FilePathFileName)
J
InStrRev(FilePathFileName,
"\")
GetFileName
Mid(FilePathFileName,
J
+
1,
i)
End
Function
''获取路径路径
c:\dir1001\
Public
Function
GetFilePath(FilePathFileName
As
String)
As
String
'获取路径路径
c:\dir1001\
On
Error
Resume
Next
Dim
J
As
Integer
J
InStrRev(FilePathFileName,
"\")
GetFilePath
Mid(FilePathFileName,
1,
J)
End
Function
'获取文件名但不包括扩展名
aaa
Public
Function
GetFileNameNoExt(FilePathFileName
As
String)
As
String
'获取文件名但不包括扩展名
aaa
On
Error
Resume
Next
Dim
i
As
Integer,
J
As
Integer,
k
As
Integer
i
Len(FilePathFileName)
J
InStrRev(FilePathFileName,
"\")
k
InStrRev(FilePathFileName,
".")
If
k
Then
GetFileNameNoExt
Mid(FilePathFileName,
J
+
1,
i
-
J)
Else
GetFileNameNoExt
Mid(FilePathFileName,
J
+
1,
k
-
J
-
1)
End
If
End
Function
'=====
'获取扩展名
.txt
Public
Function
GetFileExtName(FilePathFileName
As
String)
As
String
'获取扩展名
.txt
On
Error
Resume
Next
Dim
i
As
Integer,
J
As
Integer
i
Len(FilePathFileName)
J
InStrRev(FilePathFileName,
".")
If
J
Then
GetFileExtName
".txt"
Else
GetFileExtName
Mid(FilePathFileName,
J,
i)
End
If
End
Function
相关问答
Q1: VB.NET获取控件完整的名称
在本窗口中vb.net获取名称的就用me.
后面vb.net获取名称的就选择下。
Q2: vb.net的获取计算机名称问题
My功能可以替代很多API,因为CLR已经封装了大量系统函数,不建议使用API,那样会限制程序的可移植性。(微软声称.NET FRAMEWORK是跨平台的,但是迄今都没看见在Linux上的.NET 程序)
多翻翻MSDN就知道东西怎么用了
Q3: vb.net怎样获取同类控件名称
Private ctrName As String '控件名称
Private isClick As Boolean '鼠标点击状态
'注:如果已知点击目标控件的父控件,ctrParent变量可以不要。
Private WithEvents ctrParent As Control '父控件
Private Sub ControlAMouseDown(sender As Object, e As MouseEventArgs) _
Handles Button1.MouseDown
isClick = (e.Button = MouseButtons.Left _
Or e.Button = MouseButtons.Right) '左键或右键按下
If isClick Then
Dim ctr As Control = CType(sender, Control) '转换Object为控件类型
ctrName = ctr.Name '获取控件名称
ctrParent = ctr.Parent '获取控件的父控件
End If
End Sub
'增加这个父控件事件,是为了正确判别鼠标弹起时是否已进入指定目标
Private Sub ParentMouseMove(sender As Object, e As EventArgs) _
Handles ctrParent.MouseMove '如果已取消ctrParent变量,改为相应的父控件
If isClick Then isClick = False '点击状态关闭
End Sub
Private Sub ControlBMouseUp(sender As Object, e As EventArgs) _
Handles Button2.MouseEnter
If isClick Then '如果点击状态为打开
Dim ctr As Control = CType(sender, Control) '转换Object为控件类型
MsgBox(ctrName " | " ctr.Name) '弹出消息显示结果
End If
End Sub
Q4: VB.NET 如何获取主机在域中的用户名?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim UserID As String = Environment.GetEnvironmentVariable("USERNAME") '获取用户名
MsgBox(UserID)
End Sub
Q5: 如何获得某个类中所有枚举类型的名称 vb.net
'调用类System.Enumvb.net获取名称的
'Public Shared Function GetNames(enumType As Type) As String()
'方法vb.net获取名称,就可以获取指定枚举类型vb.net获取名称的所有常数名称
'下面有一个例子
Option Explicit On
Option Strict On
Imports System
Enum Color
Red
Green
Blue
Black
End Enum
Module Program
Sub Main()
For Each en As String In System.Enum.GetNames(GetType(Color))
Console.WriteLine(en)
Next
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
End Sub
End Module
关于vb.net获取名称和vba 获取文件名的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







