vb.net转换数值 vb转换函数代码

VB.NET如何把字符串(不全是数字或为空)转换成数字?明白你的意思了,只要是字母都会转换成数字,帮你写好了("usernane"和 "pasward" 我这里写成"username" 和" password")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim username, password As String
Dim temp As Long
Dim r As String = ""
Dim v As String = TextBox1.Text
For Each c In v.ToString
If IsNumeric(c) Then
r = c
Else
r = ((Asc(c) - 65).ToString("00"))
End If
Next
username = r
temp = username * 3 - 500
password = CStr(temp)
TextBox2.Text = password
End Sub
VB.NET,八/十六进制转十进制的函数,怎么转?'此函数用于十进制到二进制
Private Function Bin(Number As Long) As Long
Dim Div_value As String
Do
Div_value = https://www.04ip.com/post/(Number Mod 2)Div_value
Number = Int(Number / 2)
Loop Until Number2
Bin = NumberDiv_value
End Function
'此函数用于二进制到十进制
Private Function value_Bin(Number As Long) As Long
Dim Temp_value As Long, Cyc As Long
For Cyc = 0 To Len(Str(Number))
If Cyc = Len(Str(Number)) Then
value_Bin = Temp_value + Val(Mid(Str(Number), Cyc, 1))
Exit For
End If
If Cyc0 Then Temp_value = https://www.04ip.com/post/(Temp_value + Val(Mid(Str(Number), Cyc, 1))) * 2
Next Cyc
End Function
'====写入以上函数后转值操作:
'十进制到十六进制:Hex(十进制数值)
'十进制到八进制:Oct(十进制数值)
'十进制到二进制:Bin(十进制数值)
'二进制到十进制:value_Bin(二进制数值)
'八进制到十进制:Val("O"八进制数值)
'十六进制到十进制:Val("H"十六进制数值)
比如
msgbox DEC_to_BIN(10)
就会返回一个10转换为十进制后的结果
或者简单点就用
VB自带函数:
十进制转八进制:Oct(num)
十六进制转八进制:oct("H"num)
十进制转十六进制:hex(num)
八进制转十六进制:hex("O"num)
十六进制转换为十进制
Dim str As String
str = Text2.Text
Text10.Text = CLng("H"str)
vb.net 如何把大写金额转换成阿拉伯数字金额?Private Sub Text2_Change()'大写金额转换成阿拉伯数字金额
Dim i As Integer
Dim j As Integer
Dim myint As Integer
Dim myint1 As Integer
Dim mydoub As Double
Dim mystr As String
Dim mystr1 As String
Dim mystr2 As String
Dim mystr3 As String
Dim mystr4 As String
Dim money As Long
Dim money1 As Integer
Dim money2 As Long
mystr = Text2.Text
myint = InStr(mystr, ".")
If myint = 0 Then
mystr = Text2.Text
Else
mystr3 = Right(Text2.Text, Len(Text2.Text) - myint)
If mystr3"" Then'转换小数位
mystr4 = Left(mystr3, 1)
mystr3 = Right(mystr3, Len(mystr3) - 1)
If mystr4"0" Then
mystr2 = mystr2 + setdata(Val(mystr4)) + "角"
End If
If mystr3"" Then
mystr4 = Left(mystr3, 1)
mystr2 = mystr2 + setdata(Val(mystr4)) + "分"
End If
End If
mystr = Left(Text2.Text, myint - 1)
End If
j = Len(mystr)
For i = 1 To Len(mystr)'转换整数位
money2 = Left(mystr, i)
money1 = Right(money2, 1)
If money1 = 0 Then
If j = 5 Then
If Right(mystr1, 1)"万" Then mystr1 = mystr1"万"
Else
If Right(mystr1, 1)"零" And Right(money, j)0 Then mystr1 = mystr1"零"
End If
Else
mystr1 = mystr1setdata(money1) + chang(j)
End If
j = j - 1
Next i
Text1.Text = mystr1"元"mystr2'显示大写
End Sub
VB.NET的OPC读取西门子PLC数值转换12601, 转换成16进制是3139,16进制 ASC吗31对应字符1,39对应9 。后面的用这个思路去转换就对上了 。

推荐阅读