Text2.Text = Mid(Text1.Text, 1, 1) * (16 * 16 * 16 * 16) + Mid(Text1.Text, 2, 1) * (16 * 16 * 16) + Mid(Text1.Text, 3, 1) * (16 * 16) + Mid(Text1.Text, 4, 1) * 16 + Mid(Text1.Text, 5, 1)
这个溢出  怎么解决??谢谢

解决方案 »

  1.   

    Text2.Text = 
    Mid(Text1.Text, 1, 1) * (16 * 16 * 16 * 16) 
    + Mid(Text1.Text, 2, 1) * (16 * 16 * 16) 
    + Mid(Text1.Text, 3, 1) * (16 * 16) 
    + Mid(Text1.Text, 4, 1) * 16 
    + Mid(Text1.Text, 5, 1)这好像是一个十进制转16进制吧。可以用循环的。
      

  2.   

    Option ExplicitPrivate Sub Command1_Click()
        Dim t As Currency
        
        Dim s As String
        Randomize Timer
        s = CStr(CLng(Rnd * 10000000))
        
        Debug.Print s
        
        Dim i As Long
        Dim l As Long
        l = Len(s)
        For i = 1 To l
            t = t * 16
            t = t + Val("&h" & Mid(s, i, 1))
        Next i
        
        Debug.Print t & "       " & Hex$(t)
        
    End Sub
      

  3.   

    Text2.Text = Mid(Text1.Text, 1, 1) * (clng(16) * 16 * 16 * 16) + Mid(Text1.Text, 2, 1) * (16 * 16 * 16) + Mid(Text1.Text, 3, 1) * (16 * 16) + Mid(Text1.Text, 4, 1) * 16 + Mid(Text1.Text, 5, 1)原因是VB把16当成一个Integer,16 * 16 * 16 * 16是4个Integer相乘,返回结果仍为Integer型,而16 * 16 * 16 * 16计算的结果为65536超过了Integer的范围,所以溢出。(尿兜溢出,请使用屎兜!  ^_^)
      

  4.   


    Text2.Text = Mid(Text1.Text, 1, 1) * 16^4 + Mid(Text1.Text, 2, 1) * 16^3 + Mid(Text1.Text, 3, 1) * 16^2 + Mid(Text1.Text, 4, 1) * 16^1 + Mid(Text1.Text, 5, 1) 
      

  5.   

    Text2.Text = Mid(Text1.Text, 1, 1) * (16&* 16 * 16 * 16) + Mid(Text1.Text, 2, 1) * (16& * 16 * 16) + Mid(Text1.Text, 3, 1) * (16& * 16) + Mid(Text1.Text, 4, 1) * 16 + Mid(Text1.Text, 5, 1)