Advertisement
a5768549

Untitled

Jul 10th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.74 KB | None | 0 0
  1. Public Class Form1
  2.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  3.         Dim 須轉換進制 As String
  4.         Dim 十進位數字 As Integer = 0
  5.         Dim 取出數字 As String
  6.         Dim text As String
  7.         Dim tmp As String = ""
  8.         Dim ans As String = ""
  9.         Dim ups As Integer
  10.         Dim angel()
  11.         Dim len1 As Integer
  12.  
  13.         If Mid(TextBox1.Text, 2, 1) = " " Then
  14.             須轉換進制 = Mid(TextBox1.Text, 1, 1)
  15.         Else
  16.             須轉換進制 = Mid(TextBox1.Text, 1, 2)
  17.         End If
  18.         text = TextBox1.Text
  19.         angel = Split(text, " ")
  20.         取出數字 = Val(angel(1))
  21.         len1 = Len(取出數字)
  22.         Select Case 須轉換進制
  23.             Case 2
  24.                 For i = 1 To Len(取出數字)
  25.                     If (Mid(取出數字, i, 1) = "1") Then
  26.                         十進位數字 += 2 ^ (Len(取出數字) - i)
  27.                     End If
  28.                 Next
  29.             Case 3
  30.                 For i = 1 To Len(取出數字)
  31.                     If (Mid(取出數字, i, 1) = "1") Then
  32.                         十進位數字 += 3 ^ (Len(取出數字) - i)
  33.                     ElseIf (Mid(取出數字, i, 1) = "2") Then
  34.                         十進位數字 += (3 ^ (Len(取出數字) - i)) * 2
  35.                     End If
  36.                 Next
  37.             Case 4
  38.                 Dim times As Integer = 3
  39.                 For i = 1 To Len(取出數字)
  40.                     For j = 1 To times
  41.                         If (Mid(取出數字, i, 1) = j) Then
  42.                             十進位數字 += (4 ^ (Len(取出數字) - i)) * j
  43.                         End If
  44.                     Next
  45.                 Next
  46.             Case 5
  47.                 Dim times As Integer = 4
  48.                 For i = 1 To Len(取出數字)
  49.                     For j = 1 To times
  50.                         If (Mid(取出數字, i, 1) = j) Then
  51.                             十進位數字 += (5 ^ (Len(取出數字) - i)) * j
  52.                         End If
  53.                     Next
  54.                 Next
  55.             Case 6
  56.                 Dim times As Integer = 5
  57.                 For i = 1 To Len(取出數字)
  58.                     For j = 1 To times
  59.                         If (Mid(取出數字, i, 1) = j) Then
  60.                             十進位數字 += (6 ^ (Len(取出數字) - i)) * j
  61.                         End If
  62.                     Next
  63.                 Next
  64.             Case 7
  65.                 Dim times As Integer = 6
  66.                 For i = 1 To Len(取出數字)
  67.                     For j = 1 To times
  68.                         If (Mid(取出數字, i, 1) = j) Then
  69.                             十進位數字 += (7 ^ (Len(取出數字) - i)) * j
  70.                         End If
  71.                     Next
  72.                 Next
  73.             Case 8
  74.                 Dim times As Integer = 7
  75.                 For i = 1 To Len(取出數字)
  76.                     For j = 1 To times
  77.                         If (Mid(取出數字, i, 1) = j) Then
  78.                             十進位數字 += (8 ^ (Len(取出數字) - i)) * j
  79.                         End If
  80.                     Next
  81.                 Next
  82.             Case 9
  83.                 Dim times As Integer = 8
  84.                 For i = 1 To Len(取出數字)
  85.                     For j = 1 To times
  86.                         If (Mid(取出數字, i, 1) = j) Then
  87.                             十進位數字 += (9 ^ (Len(取出數字) - i)) * j
  88.                         End If
  89.                     Next
  90.                 Next
  91.             Case 10
  92.                 Dim times As Integer = 9
  93.                 For i = 1 To Len(取出數字)
  94.                     For j = 1 To times
  95.                         If (Mid(取出數字, i, 1) = j) Then
  96.                             十進位數字 += (10 ^ (Len(取出數字) - i)) * j
  97.                         End If
  98.                     Next
  99.                 Next
  100.             Case 11
  101.                 Dim times As Integer = 10
  102.                 For i = 1 To Len(取出數字)
  103.                     For j = 1 To times
  104.                         If (Mid(取出數字, i, 1) = j) Then
  105.                             十進位數字 += (11 ^ (Len(取出數字) - i)) * j
  106.                         End If
  107.                     Next
  108.                 Next
  109.             Case 12
  110.                 Dim times As Integer = 11
  111.                 For i = 1 To Len(取出數字)
  112.                     For j = 1 To times
  113.                         If (Mid(取出數字, i, 1) = j) Then
  114.                             十進位數字 += (12 ^ (Len(取出數字) - i)) * j
  115.                         End If
  116.                     Next
  117.                 Next
  118.             Case 13
  119.                 Dim times As Integer = 12
  120.                 For i = 1 To Len(取出數字)
  121.                     For j = 1 To times
  122.                         If (Mid(取出數字, i, 1) = j) Then
  123.                             十進位數字 += (13 ^ (Len(取出數字) - i)) * j
  124.                         End If
  125.                     Next
  126.                 Next
  127.             Case 14
  128.                 Dim times As Integer = 13
  129.                 For i = 1 To Len(取出數字)
  130.                     For j = 1 To times
  131.                         If (Mid(取出數字, i, 1) = j) Then
  132.                             十進位數字 += (14 ^ (Len(取出數字) - i)) * j
  133.                         End If
  134.                     Next
  135.                 Next
  136.             Case 15
  137.                 Dim times As Integer = 14
  138.                 For i = 1 To Len(取出數字)
  139.                     For j = 1 To times
  140.                         If (Mid(取出數字, i, 1) = j) Then
  141.                             十進位數字 += (15 ^ (Len(取出數字) - i)) * j
  142.                         End If
  143.                     Next
  144.                 Next
  145.             Case 16
  146.                 Dim times As Integer = 10
  147.                 For i = 1 To Val(Len(取出數字))
  148.                     For j = 1 To times
  149.                         If (Mid(取出數字, i, 1) = j) Then
  150.                             十進位數字 += (16 ^ (Len(取出數字) - i)) * j
  151.                         End If
  152.                     Next
  153.                 Next
  154.  
  155.                 For i = len1 To 1
  156.                     ups = Asc(Mid(取出數字, i, 1))
  157.                     MsgBox(len1)
  158.  
  159.                 Next
  160.                 Select Case ups
  161.                     Case 65 : 十進位數字 = 十進位數字 + 10
  162.                     Case 66 : 十進位數字 = 十進位數字 + 11
  163.                     Case 67 : 十進位數字 = 十進位數字 + 12
  164.                     Case 68 : 十進位數字 = 十進位數字 + 13
  165.                     Case 69 : 十進位數字 = 十進位數字 + 14
  166.                     Case 70 : 十進位數字 = 十進位數字 + 15
  167.                 End Select
  168.         End Select
  169.         Select Case angel(2)
  170.             Case 8
  171.                 tmp = 十進位數字
  172.                 For i = Len(十進位數字) To 1
  173.                     ans = ans & (Val(tmp) Mod 8)
  174.                     tmp = Val(十進位數字) \ 8
  175.                     i = i - 1
  176.                 Next
  177.             Case 16
  178.                 tmp = Val(十進位數字)
  179.                 Do
  180.                     Select Case tmp Mod 16
  181.                         Case Is < 10 : ans = (tmp Mod 16) & ans
  182.                         Case 10 : ans = "A" & ans
  183.                         Case 11 : ans = "B" & ans
  184.                         Case 12 : ans = "C" & ans
  185.                         Case 13 : ans = "D" & ans
  186.                         Case 14 : ans = "E" & ans
  187.                         Case 15 : ans = "F" & ans
  188.                     End Select
  189.                     tmp = tmp \ 16
  190.                 Loop Until tmp = 0
  191.  
  192.         End Select
  193.         TextBox2.Text = ans
  194.     End Sub
  195. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement