Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. Dim a, b, c As Long
  2. Dim text, bin, Prevar As String
  3. Dim n, i, dec As Integer
  4.  
  5. Private Sub Command1_Click()
  6. 'Prefix calculater
  7.  
  8. For X = 1 To Text3.text
  9. Prevar = Prevar & "1"
  10. Next X
  11.  
  12. For X = 1 To 32 - Text3.text
  13. Prevar = Prevar & "0"
  14. Next X
  15.  
  16. n = 1
  17. For v = 0 To 3
  18. Text2(v).text = Mid(Prevar, n, 8)
  19. n = n + 8
  20. Next v
  21.  
  22. Prevar = ""
  23.  
  24. Call Command3_Click
  25.  
  26.  
  27. End Sub
  28. Private Sub Command2_Click()
  29. 'Dec to bin subnet mask
  30. For X = 0 To 3
  31.  
  32. a = Val(Text1(X).text)
  33. Text2(X).text = ""
  34.  
  35. If a = 1 Or a = 0 Then
  36. Text2(X).text = a
  37. Else
  38.  
  39. Do Until c = 1
  40. b = a Mod 2
  41. c = Int(a / 2)
  42. a = c
  43.  
  44. If b = 1 Then
  45. Text2(X).text = "1" & Text2(X).text
  46. ElseIf b = 0 Then
  47. Text2(X).text = "0" & Text2(X).text
  48. End If
  49. Loop
  50. c = 0
  51. Text2(X).text = "1" & Text2(X).text
  52.  
  53. End If
  54. Text2(X) = Format(Text2(X), "00000000")
  55.  
  56. Next
  57.  
  58. End Sub
  59.  
  60. Private Sub Command3_Click()
  61. 'Bin to Dec subnet mask
  62. For z = 0 To 3
  63. dec = 0
  64. bin = Text2(z).text
  65. i = Len(Text2(z).text) - 1
  66.  
  67. For n = 1 To Len(Text2(z).text)
  68. dec = dec + Mid(bin, n, 1) * (2 ^ i)
  69. i = i - 1
  70.  
  71. Next
  72.  
  73. Text1(z).text = dec
  74.  
  75. Next
  76.  
  77. End Sub
  78.  
  79. Private Sub Command4_Click()
  80. 'Dec to bin host
  81. For X = 0 To 3
  82.  
  83. a = Val(Text4(X).text)
  84. Text5(X).text = ""
  85.  
  86. If a = 1 Or a = 0 Then
  87. Text5(X).text = a
  88. Else
  89.  
  90. Do Until c = 1
  91. b = a Mod 2
  92. c = Int(a / 2)
  93. a = c
  94.  
  95. If b = 1 Then
  96. Text5(X).text = "1" & Text5(X).text
  97. ElseIf b = 0 Then
  98. Text5(X).text = "0" & Text5(X).text
  99. End If
  100. Loop
  101. c = 0
  102. Text5(X).text = "1" & Text5(X).text
  103.  
  104. End If
  105. Text5(X) = Format(Text5(X), "00000000")
  106.  
  107. Next
  108.  
  109. Call NetworkID
  110.  
  111. End Sub
  112.  
  113. Private Sub Command5_Click()
  114. 'bin to dec host
  115. For z = 0 To 3
  116. dec = 0
  117. bin = Text5(z).text
  118. i = Len(Text5(z).text) - 1
  119.  
  120. For n = 1 To Len(Text5(z).text)
  121. dec = dec + Mid(bin, n, 1) * (2 ^ i)
  122. i = i - 1
  123.  
  124. Next
  125.  
  126. Text4(z).text = dec
  127.  
  128. Next
  129.  
  130. End Sub
  131.  
  132. Private Sub Command6_Click()
  133. 'clear textboxes i prefix
  134. For k = 0 To 3
  135. Text1(k).text = blank
  136. Text2(k).text = blank
  137. Text3.text = blank
  138.  
  139. Next
  140. End Sub
  141.  
  142. Private Sub Command7_Click()
  143. 'clear textboxes i host
  144. For k = 0 To 3
  145. Text4(k).text = blank
  146. Text5(k).text = blank
  147. Next
  148. End Sub
  149.  
  150. Private Sub NetworkID()
  151. 'Kopire host oct 0 to 2 bin og dec
  152. For f = 0 To 2
  153.  
  154. Text7(f).text = Text5(f).text
  155. Text6(f).text = Text4(f).text
  156. Text13(f).text = Text7(f).text
  157. 'Text12(f).text = Text6(f).text
  158.  
  159. Next f
  160.  
  161. 'Beregner bin network ID text7(3)
  162. For n = 1 To 8
  163.  
  164. If Mid(Text2(3).text, n, 1) And Mid(Text5(3).text, n, 1) = 1 Then
  165. Text7(3).text = Text7(3).text & "1"
  166.  
  167. Else
  168. Text7(3).text = Text7(3).text & "0"
  169.  
  170. End If
  171.  
  172. Next n
  173. 'Binært til Dec i networkID
  174. For z = 0 To 3
  175. dec = 0
  176. bin = Text7(z).text
  177. i = Len(Text7(z).text) - 1
  178.  
  179. For n = 1 To Len(Text7(z).text)
  180. dec = dec + Mid(bin, n, 1) * (2 ^ i)
  181. i = i - 1
  182.  
  183. Next
  184.  
  185. Text6(z).text = dec
  186.  
  187. Next
  188.  
  189.  
  190. 'first host
  191. For Y = 0 To 3
  192. Text8(Y).text = Text6(Y).text 'first host
  193. Text9(Y).text = Text7(Y).text 'First host
  194.  
  195. Next
  196. Text8(3).text = Val(Text8(3).text) + 1 ' first host
  197. Text9(3).text = Val(Text9(3).text) + 1 ' first host
  198.  
  199. 'Broadcast
  200. For n = 1 To 8
  201.  
  202. If Mid(Text2(3), n, 1) = 1 Then
  203. Text13(3).text = Text13(3).text & Mid(Text7(3), n, 1)
  204. Else
  205. Text13(3).text = Text13(3).text & "1"
  206. End If
  207.  
  208. Next n
  209.  
  210. 'binært til dec i broadcast
  211. For z = 0 To 3
  212. dec = 0
  213. bin = Text13(z).text
  214. i = Len(Text13(z).text) - 1
  215.  
  216. For n = 1 To Len(Text13(z).text)
  217. dec = dec + Mid(bin, n, 1) * (2 ^ i)
  218. i = i - 1
  219.  
  220. Next
  221.  
  222. Text12(z).text = dec
  223.  
  224. Next
  225.  
  226. 'last host
  227. For Y = 0 To 3
  228. Text10(Y).text = Text6(Y).text 'last host
  229. Text11(Y).text = Text7(Y).text 'last host
  230.  
  231. Next
  232. Text10(3).text = Val(Text12(3).text) - 1 ' last host
  233. Text11(3).text = Val(Text13(3).text) - 1 ' last host
  234.  
  235. 'antal host
  236. Text14.text = 2 ^ (32 - Text3.text) - 2
  237.  
  238. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement